Hi,
I may be jumping the gun a bit, but I'm having some issues with the module on the Drupal 9 alpha. I'm getting the following error:
ArgumentCountError: Too few arguments to function Drupal\system\Plugin\Block\SystemMenuBlock::__construct(), 4 passed in /srv/bindings/5054caa179a84771a26251400e792dbb/code/modules/contrib/menu_block/src/Plugin/Block/MenuBlock.php on line 73 and exactly 5 expected in Drupal\system\Plugin\Block\SystemMenuBlock->__construct() (line 57 of /srv/bindings/5054caa179a84771a26251400e792dbb/code/core/modules/system/src/Plugin/Block/SystemMenuBlock.php)
I've also applied the patch in #99 here:
https://www.drupal.org/project/menu_block/issues/2809699
All in all, the module is causing two errors:
1. I can't seem to place a menu block in the Block Layout screen. I just get the pinwheel for a split second before it does nothing. I checked the log and the error at the top is what I've got.
2. The advanced options in the patch in #99 aren't appearing. Those options are great and I'm hoping to use them on a D9 site. Why they're not appearing and if they're related to the error I'm getting, I can't say.
The only Drupal 9 deprecation I'm getting in my D8 site is the core requirement, which I added in the info.yml file before trying the module out on D9.
Hopefully someone who knows more than I do can shine some light on this issue.
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | 3115436-11.patch | 2.37 KB | dww |
| #5 | 3115436-5.patch | 2.27 KB | jungle |
Comments
Comment #2
mattbloomfield commentedI've done some digging, and I think it might be this difference in the core System Menu Block:
D8.8:
public function __construct(array $configuration, $plugin_id, $plugin_definition, MenuLinkTreeInterface $menu_tree, MenuActiveTrailInterface $menu_active_trail = NULL) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->menuTree = $menu_tree;
if ($menu_active_trail === NULL) {
@trigger_error('The menu.active_trail service must be passed to SystemMenuBlock::__construct(), it is required before Drupal 9.0.0. See https://www.drupal.org/node/2669550.', E_USER_DEPRECATED);
$menu_active_trail = \Drupal::service('menu.active_trail');
}
$this->menuActiveTrail = $menu_active_trail;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('menu.link_tree'),
$container->get('menu.active_trail')
);
}
D9:
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;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('menu.link_tree'),
$container->get('menu.active_trail')
);
}
And here's what I've got in the menu block module in MenuBlock.php:
public function __construct(array $configuration, $plugin_id, array $plugin_definition, MenuLinkTreeInterface $menu_tree, MenuActiveTrailInterface $active_trail, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $menu_tree);
$this->menuActiveTrail = $active_trail;
$this->entityTypeManager = $entity_type_manager;
}
I'm not sure what that should be updated to, though.
Comment #3
dww#2809699-111: Add configuration options for dynamic block titles should fix all of this (although I haven't tested on D9 myself, yet).
I could split out the parts that fix the handling of menuActiveTrail to a separate patch for this issue if the maintainers prefer for scope management/focus.
Comment #4
dwwLeaving this here as a more appropriate place for the reference:
https://www.previousnext.com.au/blog/safely-extending-drupal-8-plugin-cl...
Fixing the title to be more accurate.
Also, if we're going to fix the deprecated stuff here, and potentially refactor to not have to worry about constructor changes in the future, we should also fully remove our protected copy of that service pointer. SystemMenuBlock already has it, so we're managing our own duplicate copy for nothing. See #2809699-110: Add configuration options for dynamic block titles for more.
Comment #5
jungleOnly refactored src/Plugin/Block/MenuBlock according to the blog post shared in #4
Comment #6
jungleJust realised, maybe we should return $this to support method chaining.
Comment #7
jungleBack to NW, haven't done this.
Comment #8
jungleIt takes longer than expected, unassign myself to allow others working on this as it's critical.
Comment #9
dwwRe: #4 -- Sorry, I was getting confused since I was looking at my copy of this code with #2809699: Add configuration options for dynamic block titles already applied. The copy of menu_block in Git doesn't have
activeMenuTrailat all. ;)Giving this issue a more accurate title/scope, fixing the priority/category, and marking RTBC. #5 is sufficient for this issue.
Let's get this in, then we can focus on #2809699.
Thanks!
-Derek
Comment #10
dwwThis addresses #6 and adds
return $this.Comment #11
dwwOh right, code standards wants a blank line before @return
Comment #12
kristen polComment #13
kristen polThanks for the update.
1) Confirmed that the changes in #11 are for returning
$thisas noted in #6. Note that some core code adds a description for* @return $thisand some do not.2) Diffed the patches from #5 and #11 to double check the changes were only what was in the interdiff.
3) Double checked the other code in the patch and seems ok. I noticed that the naming in the patch is different than what's used in core, e.g.
whereas the patch is using:
though I'd argue that the patch is following a more standard naming pattern than the core code in this case. Likewise for:
menu_parent_selectorvs.menu_parent_form_selector4) Patch applied cleanly:
5) Searched the code for other references to
menu_parent_form_selectorand there were none other than what's handled in the patch.6) Tests pass.
7) Not sure what's the best way to manually test this.
Comment #14
kristen polComment #15
jungleRe#13.1, Checked API documentation and comment standards, it's an undocumented convention IMO.
BTW, an issue just created #3129184: Remove description from @return $this
Thanks!
Comment #16
dwwSadly, we all missed #2968049: Dependency Injection issue when working on this, so we've now got 2 issues for the same thing. :(
Probably this should be marked duplicate and we should move back over there. Or we can commit/fix this, and simply mark that one fixed, too. ;)
Comment #18
joelpittetThank you for the great review @Kristen Pol and the patch @dww. Also nice follow-up @jungle! I've committed this to the dev release and I did a quick manual test... just in case.
I'll see if I can credit the other issue too
Comment #19
kristen pol@joelpittet Thanks! I see commit credit for:
dww, jungle, mattbloomfield, Kristen Pol
but only issue credit for:
dww, jungle, joelpittet
Would add issue credit for me and mattbloomfield, please :)
Comment #20
jungleTried to check and save the checkboxes, but did not get saved, let's wait for maintainers :p