Skip to main content
deleted 6 characters in body
Source Link
Artreaktor
  • 396
  • 3
  • 15

I was unable to find a way to alter tree manipulators of an existing menu. But it is possible if you render a new menu, let's say in a custom block.

Create your own tree manipulator service.

Copied from core.services.yml:

  menu.default_tree_manipulators:
    class: Drupal\Core\Menu\DefaultMenuLinkTreeManipulators
    arguments: ['@access_manager', '@current_user', '@entity_type.manager']

you can define your service in a similar way:

  mymodule.my_custom_tree_manipulators:
    class: Drupal\mymodule\MyCustomMenuLinkTreeManipulators
    arguments: ['@access_manager', '@current_user', '@entity_type.manager']

Then create MyCustomMenuLinkTreeManipulators class that extends DefaultMenuLinkTreeManipulators, define custom method, let's say checkAccessIgnoreStatus() and implement logic you need.

There are many ways to use it, I'd create a new block plugin for that. Refer to my answer for details on how to render menu with manipulators.

Use your manipulators:

$manipulators = array(
        array('callable' => 'mymodule.my_custom_tree_manipulators:checkAccessIgnoreStatus'),
        // ...
      );

I was unable to find a way to alter tree manipulators of an existing menu. But it is possible if you render a new menu, let's say in a custom block.

Create your own tree manipulator service.

Copied from core.services.yml:

  menu.default_tree_manipulators:
    class: Drupal\Core\Menu\DefaultMenuLinkTreeManipulators
    arguments: ['@access_manager', '@current_user', '@entity_type.manager']

you can define your service in a similar way:

  mymodule.my_custom_tree_manipulators:
    class: Drupal\mymodule\MyCustomMenuLinkTreeManipulators
    arguments: ['@access_manager', '@current_user', '@entity_type.manager']

Then create MyCustomMenuLinkTreeManipulators class that extends DefaultMenuLinkTreeManipulators, define custom method, let's say checkAccessIgnoreStatus() and implement logic you need.

There are many ways to use it, I'd create a new block plugin for that. Refer to my answer for details on how to render menu with manipulators.

Use your manipulators:

$manipulators = array(
        array('callable' => 'mymodule.my_custom_tree_manipulators:checkAccessIgnoreStatus'),
        // ...
      );

I was unable to find a way to alter tree manipulators of an existing menu. But it is possible if you render menu, let's say in a custom block.

Create your own tree manipulator service.

Copied from core.services.yml:

  menu.default_tree_manipulators:
    class: Drupal\Core\Menu\DefaultMenuLinkTreeManipulators
    arguments: ['@access_manager', '@current_user', '@entity_type.manager']

you can define your service in a similar way:

  mymodule.my_custom_tree_manipulators:
    class: Drupal\mymodule\MyCustomMenuLinkTreeManipulators
    arguments: ['@access_manager', '@current_user', '@entity_type.manager']

Then create MyCustomMenuLinkTreeManipulators class that extends DefaultMenuLinkTreeManipulators, define custom method, let's say checkAccessIgnoreStatus() and implement logic you need.

There are many ways to use it, I'd create a new block plugin for that. Refer to my answer for details on how to render menu with manipulators.

Use your manipulators:

$manipulators = array(
        array('callable' => 'mymodule.my_custom_tree_manipulators:checkAccessIgnoreStatus'),
        // ...
      );
Source Link
Artreaktor
  • 396
  • 3
  • 15

I was unable to find a way to alter tree manipulators of an existing menu. But it is possible if you render a new menu, let's say in a custom block.

Create your own tree manipulator service.

Copied from core.services.yml:

  menu.default_tree_manipulators:
    class: Drupal\Core\Menu\DefaultMenuLinkTreeManipulators
    arguments: ['@access_manager', '@current_user', '@entity_type.manager']

you can define your service in a similar way:

  mymodule.my_custom_tree_manipulators:
    class: Drupal\mymodule\MyCustomMenuLinkTreeManipulators
    arguments: ['@access_manager', '@current_user', '@entity_type.manager']

Then create MyCustomMenuLinkTreeManipulators class that extends DefaultMenuLinkTreeManipulators, define custom method, let's say checkAccessIgnoreStatus() and implement logic you need.

There are many ways to use it, I'd create a new block plugin for that. Refer to my answer for details on how to render menu with manipulators.

Use your manipulators:

$manipulators = array(
        array('callable' => 'mymodule.my_custom_tree_manipulators:checkAccessIgnoreStatus'),
        // ...
      );