Commit 8b1a846c authored by Fabian de Rijk's avatar Fabian de Rijk
Browse files

Issue #3191579: Added alter hook for output

parent 5675c668
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -17,8 +17,23 @@
 * @param string $menu_name
 *   The menu name.
 */
function hook_rest_menu_items_resource_manipulators_alter(array $manipulators, $menu_name) {
function hook_rest_menu_items_resource_manipulators_alter(array &$manipulators, &$menu_name) {
  if ($menu_name === 'main') {
    $manipulators[] = ['callable' => 'custom.manipulator:method'];
  }
}

/**
 * Alter the output of the menu_items array.
 *
 * @param array $menu_items
 *   The menu items array.
 */
function hook_rest_menu_items_output_alter(array &$menu_items) {
  foreach ($menu_items as &$menu_item) {
    if (array_key_exists('below', $menu_item)) {
      $menu_item['child'] = $menu_item['below'];
      unset($menu_item['below']);
    }
  }
}
+4 −1
Original line number Diff line number Diff line
@@ -164,6 +164,9 @@ class RestMenuItemsResource extends ResourceBase {

      $this->getMenuItems($menu['#items'], $this->menuItems);

      // Other modules can alter the output before rendering.
      $this->moduleHandler->alter('rest_menu_items_output', $this->menuItems);

      // Return response.
      $response = new ResourceResponse(array_values($this->menuItems));