( ! ) Fatal error: Call to a member function getActiveTrailIds() on null in \modules\contrib\superfish\src\Plugin\Block\SuperfishBlock.php on line 1462

Windows 10
Drupal ver. 8.4.0-rc1

name: 'Superfish'
type: module
description: 'Adds jQuery Superfish plugin to menu blocks.'
package: User interface
# core: 8.x

# Information added by Drupal.org packaging script on 2017-06-01
version: '8.x-1.1'

Comments

darkdim created an issue. See original summary.

darkdim’s picture

$parameters = (new MenuTreeParameters())
      ->setMinDepth($level)
      ->setMaxDepth($maxdepth)
      ->setActiveTrail($this->menuActiveTrail->getActiveTrailIds($menu_name))
      ->onlyEnabledLinks();

Field 'menuActiveTrail' not found in SuperfishBlock
Referenced field is not found in subject class.

caspervoogt’s picture

Same here. API change to MenuTreeParameters(), maybe. I looked into a bit but was unsure. I did not see references to menuActiveTrail in the MenuTreeParameters() class though. Maybe it got renamed.

darkdim’s picture

Maybe it got renamed.

Hey.
Thank you, but you're right, here removed the interface, see what can be done

v Drupal 8.4.0-rc1

  /**
   * Constructs a new SystemMenuBlock.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param array $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\Core\Menu\MenuLinkTreeInterface $menu_tree
   *   The menu tree service.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, MenuLinkTreeInterface $menu_tree) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->menuTree = $menu_tree;
  }

v 8.3.7

  /**
   * The active menu trail service.
   *
   * @var \Drupal\Core\Menu\MenuActiveTrailInterface
   */
  protected $menuActiveTrail;

  /**
   * Constructs a new SystemMenuBlock.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param array $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\Core\Menu\MenuLinkTreeInterface $menu_tree
   *   The menu tree service.
   * @param \Drupal\Core\Menu\MenuActiveTrailInterface $menu_active_trail
   *   The active menu trail service.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, MenuLinkTreeInterface $menu_tree, MenuActiveTrailInterface $menu_active_trail) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->menuTree = $menu_tree;
    $this->menuActiveTrail = $menu_active_trail;
  }
darkdim’s picture

patch for the kernel, returns the parameter containing the interface object to the constructor. It is unclear why he did not make it, and there is some other way to get the parameters?!

JvE’s picture

aleksip’s picture

I think #2856625: Remove unused menu active trail service from SystemMenuBlock is a BC breaking change in a minor core release, and should be reverted. Added a comment about this in that issue.

Edit: apparently it isn't considered a BC breaking change: https://www.drupal.org/core/d8-bc-policy

yas’s picture

The patch #5 works as expected in Drupal 8.5.x-dev.

darkdim’s picture

Status: Active » Needs review
darkdim’s picture

Project: Superfish Dropdown Menu » Core development
Version: 8.x-1.x-dev »
aleksip’s picture

Project: Core development » Superfish Dropdown Menu
Version: » 8.x-1.x-dev
Status: Needs review » Needs work

I don't think this issue should be moved to core. There is already the core issue #2856625: Remove unused menu active trail service from SystemMenuBlock and that core commit could just be reverted, fixing the problem for Superfish and others. It would be basically the same than what the patch in this issue is doing.

However, it doesn't look like #2856625: Remove unused menu active trail service from SystemMenuBlock will be reverted. So the stuff that was taken out of core should be added to Superfish itself. It should be almost as simple as adding the lines removed from the core class to the Superfish class that extends it. I could have a go at it this weekend unless someone beats me to it!

aleksip’s picture

I managed to get some discussion going on about the core change, and currently it looks like the core commit might be reverted after all, and added in 8.5, giving Superfish and other modules more time for a fix.

Also in the discussion a great way to avoid future breakage came up: #2856625-25: Remove unused menu active trail service from SystemMenuBlock. So this would be a good way to do the fix in Superfish too.

jhuhta’s picture

My first attempt to fix this, in a way that was suggested in the core issue by @aleksip and others.

Greetings from Vienna 2017 First-Time Sprinter Workshop.

jhuhta’s picture

Second attempt; fixes and cleanup.

jhuhta’s picture

Assigned: darkdim » Unassigned
Status: Needs work » Needs review
mehrpadin’s picture

Hey everybody,

Thanks for the patch, there appears to be a similar issue and a patch which I've just applied, #2896583: Menu active trail service removed from SystemMenuBlock, please close this as a duplicate, thanks again, much appreciated.

aleksip’s picture

@mehrpadin I'm not sure if the patch in that issue works in 8.5? I left a comment in that issue.

jhuhta’s picture

Status: Needs review » Closed (duplicate)
bensti’s picture

@ aleksip i try patch #14 with drupal 8.5.3 and it's work! no more error !

aleksip’s picture

@bensti I believe Superfish 8.x-1.2 contains an alternative fix to this issue, so do try that out.

stephen ollman’s picture

Getting the fatal error after upgrading from Core 8.4.4 to 8.5.4.

Applying the Superfish module update 8.x-1.1 to 8.x-1.2 fixed the issue.