Skip to content

Commit

Permalink
Add HOOK_wienimal_editor_toolbar_manipulators_alter
Browse files Browse the repository at this point in the history
Allow other modules to manipulate the toolbar menu
  • Loading branch information
RobinHoutevelts committed Jul 10, 2023
1 parent f7e79ed commit 92d82a8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [4.1.6] - 2023-07-10
### Added
- Add `HOOK_wienimal_editor_toolbar_manipulators_alter` hook ([#23](https://github.com/wieni/wienimal_editor_toolbar/pull/23))

## [4.1.5] - 2023-07-10
### Fixed
- **BC** Use AND conjunction in Route Alter ([#22](https://github.com/wieni/wienimal_editor_toolbar/pull/22))
Expand Down
2 changes: 2 additions & 0 deletions src/Service/EditorToolbarMenuBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public function buildMenu(): array
$manipulators[] = ['callable' => 'toolbar_tools_menu_navigation_links'];
}

$this->moduleHandler->alter('wienimal_editor_toolbar_manipulators', $manipulators, $menuName);

$tree = $this->menuTree->transform($tree, $manipulators);

// Finally, build a renderable array from the transformed tree.
Expand Down
15 changes: 15 additions & 0 deletions wienimal_editor_toolbar.api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

/**
* Alter the menu tree manipulators used by the editor toolbar.
*
* @see \Drupal\wienimal_editor_toolbar\Service\EditorToolbarMenuBuilder::buildMenu()
* @param array $manipulators
* @param string $menuName
*/
function hook_wienimal_editor_toolbar_manipulators_alter(array &$manipulators, string $menuName): void
{
$manipulators[] = [
'callable' => 'my_module.my_service:hideMenuItems',
];
}

0 comments on commit 92d82a8

Please sign in to comment.