protected function RestMenuItemsResource::getMenuItems in Rest menu items 8.2
Same name and namespace in other branches
- 8 src/Plugin/rest/resource/RestMenuItemsResource.php \Drupal\rest_menu_items\Plugin\rest\resource\RestMenuItemsResource::getMenuItems()
- 3.0.x src/Plugin/rest/resource/RestMenuItemsResource.php \Drupal\rest_menu_items\Plugin\rest\resource\RestMenuItemsResource::getMenuItems()
Generate the menu tree we can use in JSON.
Parameters
array $tree: The menu tree.
array $items: The already created items.
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
1 call to RestMenuItemsResource::getMenuItems()
- RestMenuItemsResource::get in src/
Plugin/ rest/ resource/ RestMenuItemsResource.php - Responds to GET requests.
File
- src/
Plugin/ rest/ resource/ RestMenuItemsResource.php, line 182
Class
- RestMenuItemsResource
- Provides a resource to get bundles by entity.
Namespace
Drupal\rest_menu_items\Plugin\rest\resourceCode
protected function getMenuItems(array $tree, array &$items = []) {
$config = $this->configFactory
->get('rest_menu_items.config');
$outputValues = $config
->get('output_values');
// Loop through the menu items.
foreach ($tree as $item_value) {
/* @var $org_link \Drupal\Core\Menu\MenuLinkInterface */
$org_link = $item_value['original_link'];
/* @var $url \Drupal\Core\Url */
$url = $item_value['url'];
$newValue = [];
foreach ($outputValues as $valueKey) {
if (!empty($valueKey)) {
$this
->getElementValue($newValue, $valueKey, $org_link, $url);
}
}
if (!empty($item_value['below'])) {
$newValue['below'] = [];
$this
->getMenuItems($item_value['below'], $newValue['below']);
}
$items[] = $newValue;
}
}