Compatibility with taxonomy_menu_ui

Created on 14 February 2020, over 4 years ago
Updated 25 May 2023, about 1 year ago

Hi,

For my website, I needed menu_item_extras and taxonomy_menu_ui . After installation I made the following observation:
- Menu item extras works well with menu item created by node form
- Menu item extra doesn't work with menu item created by term form, because we don't create an entity menu_link_content on submit.

So I implemented a patch that allows me to use the two modules, It consists of creating, in the same way as for nodes, an entity when submitting a taxonomy term with an item menu.

I attached the patch file.

✨ Feature request
Status

Needs work

Version

3.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡¦Ukraine podarok Ukraine
    git apply compatibility-taxonomy_menu_ui_reroll.patch 
    error: patch failed: src/Service/MenuLinkContentService.php:14
    error: src/Service/MenuLinkContentService.php: patch does not apply

    needs reroll

    also, please, use MR instead of patches, way easier in 21 century

  • Thanks for this, I need this as well. I wrote my own patch which I was about to create an issue for, then I found this one.
    Before this merge request should be accepted please note that I think there are several issues with this patch:

    Get rid of the _addSubmitHandler function

    The function _addSubmitHandler in menu_item_extras.module shouldn't be used. This can easily conflict with another module containing the same function.

    I would suggest adding a method addSubmitHandler to the menu_item_extras.menu_link_content_helper service and call that method instead.

    Refactor the entity type check

    There are several issues with this code:

    use Drupal\node\Entity\Node;
    use Drupal\taxonomy\Entity\Term;
    
    ...
    
    if ($parentEntity instanceof Node) {
      $uri =  'entity:node/' . $parentEntity->id();
    }
    elseif ($parentEntity instanceof Term) {
      $uri =  'entity:taxonomy_term/' . $parentEntity->id();
    }
    

    - The interfaces should be used instead
    - A fallback / exception should be there for other entity types

    I think it should be refactored like this:

    use Drupal\node\Entity\NodeInterface;
    use Drupal\taxonomy\Entity\TermInterface;
    
    ...
    
    $uri = '';
    if ($parentEntity instanceof NodeInterface) {
      $uri =  'entity:node/' . $parentEntity->id();
    }
    elseif ($parentEntity instanceof TermInterface) {
      $uri =  'entity:taxonomy_term/' . $parentEntity->id();
    }
    else {
      throw new \Exception('Entity type is currently not supported by the Menu Item Extras module');
    }
    

    Also I think it may be problemetic to simply refer the NodeInterface and the TermInterface like this, because these namespaces do not exist if either the Node module or the Taxonomy module is not enabled.

    The Menu Item Extras module could depend on both modules, but I don't think that would be correct, because the module should be usable without the Taxonomy module. The best solution might be to move parts of this code to a menu_item_extras_taxonomy module, but that will be some extra work.

Production build 0.69.0 2024