web/modules/contrib/search_api_page/search_api_page.module 122 Call to deprecated method url() of class Drupal\file\Entity\File. Deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Please use toUrl() instead.

web/modules/contrib/search_api_page/src/Controller/SearchApiPageController.php 303 Call to deprecated function pager_default_initialize(). Deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Pager\PagerManagerInterface->defaultInitialize() instead.

web/modules/contrib/search_api_page/src/Form/SearchApiPageBlockForm.php 149 Call to deprecated method getUrlGenerator() of class Drupal\Core\Form\FormBase. Deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Use the url_generator service instead.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mo_farhaz created an issue. See original summary.

mo_farhaz’s picture

Assigned: mo_farhaz » Unassigned
karishmaamin’s picture

Status: Active » Needs review
FileSize
2.95 KB

please review.

Status: Needs review » Needs work

The last submitted patch, 3: 3123705-2.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Berdir’s picture

  1. +++ b/search_api_page.module
    @@ -119,7 +119,7 @@ function template_preprocess_search_api_page_result(&$variables) {
       $variables['title'] = $entity->label();
       if ($entity instanceof \Drupal\file\Entity\File) {
    -    $variables['url'] = $entity->url();
    +    $variables['url'] = $entity->toUrl()->toString();
       }
       else {
         $variables['url'] = $entity->toUrl()->toString();
    

    There is a reason this is in a file entity specific check. So the replacement here is then createFileUrl().

  2. +++ b/src/Controller/SearchApiPageController.php
    @@ -26,14 +27,24 @@ class SearchApiPageController extends ControllerBase {
        *   The parse mode plugin manager.
    +   * @param Drupal\Core\Pager\PagerManagerInterface $pagerManager
    +   *   The parse mode pager manager.
        */
    -  public function __construct(ParseModePluginManager $parseModePluginManager) {
    +  public function __construct(ParseModePluginManager $parseModePluginManager, PagerManagerInterface $pagerManager) {
         $this->parseModePluginManager = $parseModePluginManager;
    +    $this->pagerManager = $pagerManager;
       }
    

    this means requiring 8.8, so we need to update .info.yml files.

    There's also #3073604: Missing `config_export` in `search_api_page` entity definition. which doesn't show up with drupal-check.

  3. +++ b/src/Form/SearchApiPageBlockForm.php
    @@ -146,7 +146,7 @@ class SearchApiPageBlockForm extends FormBase implements BaseFormIdInterface {
           $route = 'search_api_page.' . $langcode . '.' . $search_api_page->id();
    -      $form['#action'] = $this->getUrlGenerator()->generateFromRoute($route);
    +      $form['#action'] = $this->urlGenerator->generateFromRoute($route);
           $form['#method'] = 'get';
    

    this isn't the correct fix, should use Url::fromRoute()->toString()

    And the url generator trait should be removed from the class.

abhijeet.kumar2107’s picture

Assigned: Unassigned » abhijeet.kumar2107
abhijeet.kumar2107’s picture

abhijeet.kumar2107’s picture

abhijeet.kumar2107’s picture

FileSize
3.01 KB

Attached patche please review

abhijeet.kumar2107’s picture

Patch Attached

abhijeet.kumar2107’s picture

FileSize
2.12 KB

../../../vendor/bin/drupal-check -d .
23/23 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

[OK] No errors

Patch attached please review

abhijeet.kumar2107’s picture

../../../vendor/bin/drupal-check -d .
23/23 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

[OK] No errors

Patch attached please review

abhijeet.kumar2107’s picture

Assigned: abhijeet.kumar2107 » Unassigned
Status: Needs work » Needs review
abhijeet.kumar2107’s picture

Assigned: Unassigned » abhijeet.kumar2107
Status: Needs review » Needs work
abhijeet.kumar2107’s picture

abhijeet.kumar2107’s picture

Created patch and passed at #15 which remove all deprecated code, Please check below screenshot attached

https://www.drupal.org/files/issues/2020-05-14/search_api_pages.png

./../../vendor/bin/drupal-check -d .
23/23 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

[OK] No errors

abhijeet.kumar2107’s picture

Assigned: abhijeet.kumar2107 » Unassigned
Status: Needs work » Needs review
richgerdes’s picture

Priority: Normal » Major
Status: Needs review » Reviewed & tested by the community

Tested the patch, it looks good against drupal check.

s_leu’s picture

Priority: Major » Normal
Status: Reviewed & tested by the community » Needs work

Regarding the patch in #15:

  1. +++ b/search_api_page.module
    @@ -119,7 +119,7 @@ function template_preprocess_search_api_page_result(&$variables) {
    +    $variables['url'] = $entity->toUrl()->toString();
    

    This should use the method on FileInterface as already pointed out in #5

  2. +++ b/src/Controller/SearchApiPageController.php
    @@ -300,7 +300,7 @@ class SearchApiPageController extends ControllerBase {
    +    \Drupal::service('pager.manager')->createPager($result->getResultCount(), $search_api_page->getLimit());
    

    The pager.manager service should be injected for this, as it was already the case in the patch posted in #3.

    Also as already mentioned in #5 too, a requirement for ^8.8 has to be added to the .info.yml file as the service was only introduced on Drupal 8.8.

  3. +++ b/src/Form/SearchApiPageBlockForm.php
    @@ -146,7 +146,7 @@ class SearchApiPageBlockForm extends FormBase implements BaseFormIdInterface {
    +      $form['#action'] = $form['#action'] = \Drupal::urlGenerator()->generateFromRoute($route);
    

    Also mentioned in #5, the Url::fromRoute() should be used here instead.

s_leu’s picture

Status: Needs work » Needs review
FileSize
2.18 KB
3.62 KB

Here's a patch that takes all things mentioned in the last post and #5 into account, as well as an interdiff to the patch posted in #3.

richgerdes’s picture

@s_leu, thanks for the feedback and verifying that the comments from #5 was incorporated. I glanced over some of those and was working off the latest patch.

I've tested your updated patch and everything looks good here. Moving back to RTBC.

richgerdes’s picture

Status: Needs review » Reviewed & tested by the community
oknate’s picture

Note: I also needed this patch for Drupal 9: #3073604: Missing `config_export` in `search_api_page` entity definition.

Without it, I couldn't save the config without an error.

  • borisson_ committed 53166e5 on 8.x-1.x authored by s_leu
    Issue #3123705 by abhijeet.kumar2107, s_leu, karishmaamin, Berdir,...
borisson_’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.