Reproduction:

  1. Create a search api page
  2. Add a block to any region

=>

Call to a member function getConfigDependencyName() on null in Drupal\search_api_page\Plugin\Block\SearchApiPageBlock->calculateDependencies() (line 56 of modules/contrib/search_api_page/src/Plugin/Block/SearchApiPageBlock.php).

Code

/**
   * {@inheritdoc}
   */
  public function calculateDependencies() {
    /* @var $search_api_page \Drupal\search_api_page\SearchApiPageInterface */
    $search_api_page = SearchApiPage::load($this->configuration['search_api_page']);
    $config_name = $search_api_page->getConfigDependencyName();
    return ['config' => [$config_name]];
  }

Problem

$this->configuration doesn't contain a "search_api_page" value at this point.

Proposed solution

Unclear. Check if calculateDependencies() is right here and if the timing / execution order is designed for that.

Comments

Anybody created an issue. See original summary.

anybody’s picture

Priority: Normal » Major

Changing to major, because this breaks an important part of the functionality and makes the search blocks unusable.

anybody’s picture

The problem just occured on a further page... reconfirming.

Snehal Brahmbhatt’s picture

Status: Active » Needs review
StatusFileSize
new702 bytes

@Anybody,Please find my patch that works for the error that mentioned above. getConfigDependencyName function returns null because $search_api_page was empty. I have set the condition to check whether $search_api_page is empty or not. If $search_api_page is not empty then only it check for getConfigDependencyName function.
Please your view after using the attached patch.

Thanks!.

anybody’s picture

@snehal.addweb: Thank you. That patch work, but I'd like the maintainer to have an eye on it, if $search_api_page will ever have a value... otherwise the whole function doesn't add value...

marcoweijenborg’s picture

I can't reproduce the issue when I install the latest stable version of Search API combined with the dev version of Search API Pages. However, the patch is ok, an extra check is always good.

marcoweijenborg’s picture

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

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new777 bytes

The calculateDependencies() method should return an empty array if no dependencies could be determined. The attached patch fixes this.

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

Yes, looks good.

  • borisson_ committed f14ab12 on 8.x-1.x authored by legolasbo
    Issue #3001894 by legolasbo, snehal.addweb, borisson_: Call to a member...
borisson_’s picture

Status: Reviewed & tested by the community » Fixed

Thanks!

Status: Fixed » Closed (fixed)

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