Problem/Motivation

If we use facet summary, with the Reset Link option enabled, then we've got a fatal error when used with views embeded (embed or block views display mode).

InvalidArgumentException: The user-entered string '' must begin with a '/', '?', or '#'. in Drupal\Core\Url::fromUserInput() (line 214 of core/lib/Drupal/Core/Url.php).

Drupal\facets_summary\Plugin\facets_summary\processor\ResetFacetsProcessor->build(Object, Array, Array) (Line: 137)
Drupal\facets_summary\FacetsSummaryManager\DefaultFacetsSummaryManager->build(Object) (Line: 91)
Drupal\facets_summary\Plugin\Block\FacetsSummaryBlock->build() (Line: 171)
Drupal\block\BlockViewBuilder::preRender(Array)
call_user_func_array(Array, Array) (Line: 101)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 772)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 363)

this is because this piece of code in the ResetFacetsProcessor plugin

$url = Url::fromUserInput($facets_summary->getFacetSource()->getPath());

The path of a view embedded is NULL.

Proposed resolution

Check if the path is NULL or NOT, and if NULL fallback to the current route.

CommentFileSizeAuthor
#7 3258622-7.patch728 bytesflocondetoile
#2 3258622-2.patch946 bytesflocondetoile

Comments

flocondetoile created an issue. See original summary.

flocondetoile’s picture

Status: Active » Needs review
StatusFileSize
new946 bytes
flocondetoile’s picture

Looks like the root cause of that is in the changes between facets 1.8 and 2.0.

In 1.8, we have in the facet_source Plugin SearchApiDisplay

/**
   * {@inheritdoc}
   */
  public function getPath() {
    // The implementation in search api tells us that this is a base path only
    // if a path is defined, and false if that isn't done. This means that we
    // have to check for this + create our own uri if that's needed.
    if ($this->getDisplay()->getPath()) {
      return $this->getDisplay()->getPath();
    }

    return \Drupal::service('path.current')->getPath();
  }

in 2.0 version

we have

/**
   * {@inheritdoc}
   */
  public function getPath() {
    if ($this->isRenderedInCurrentRequest()) {
      return \Drupal::service('path.current')->getPath();
    }
    return $this->getDisplay()->getPath();
  }

And view embedded are not "rendered in the current request".

mkalkbrenner’s picture

Status: Needs review » Needs work

What about moving the logic into getPath() to have it centralized?

flocondetoile’s picture

Yes. It could be better, but would like to have some feedback from maintainers about this change introduced in the getPath() method

mkalkbrenner’s picture

Take a look at that issue committed 2 months ago.

flocondetoile’s picture

StatusFileSize
new728 bytes

Thanks (and sorry, I didn't see you were one of the maintainers :-)).
Attached a patch which move the fix into the SearchApiDisplay->getPath() method.

flocondetoile’s picture

Status: Needs work » Needs review
marcoka’s picture

I have a Layoutbuilder page with a search api views block and some facet blocks.
When added a summary it would always crash the page. With that patch an actual path is returned and not null.
I applied it and here is a debug shot of the variables:

http://www.root.artwaves.de/sharex/09-02-22--17-03-03.jpg