Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
namespace Drupal\menu_graft;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\menu_link_content\MenuLinkContentInterface;
/**
* Class MenuGraftHelper.
*
* @package Drupal\menu_graft
*/
class MenuGraftHelper {
/**
* Menu storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $menuStorage;
/**
* Constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* Entity type menuLinkManager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->menuStorage = $entity_type_manager->getStorage('menu');
}
/**
* Update menu entries from the scion menu.
*
* @param \Drupal\menu_link_content\MenuLinkContentInterface $menu_link_content
* The menu link being created or updated.
*/
public function updateMenuGraftEntries(MenuLinkContentInterface $menu_link_content) {
$menu = $this->menuStorage->load($menu_link_content->getMenuName());
$has_graft = $menu->getThirdPartySetting('menu_graft', 'menu_graft_link');
// Do we always do this, or only on grafted menus?
if (!$has_graft) {
// return;
}
\Drupal::cache('menu')->invalidateAll();
\Drupal::service('plugin.manager.menu.link')->rebuild();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment