class MenuLinkContentMigrateSubscriber in Multiversion 8
MenuContentLinkMigrateSubscriber class.
A menu_tree database table should be rediscovered after enabling/disabling a menu_link_content entity.
Hierarchy
- class \Drupal\multiversion\EventSubscriber\MenuLinkContentMigrateSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of MenuLinkContentMigrateSubscriber
1 string reference to 'MenuLinkContentMigrateSubscriber'
1 service uses MenuLinkContentMigrateSubscriber
File
- src/
EventSubscriber/ MenuLinkContentMigrateSubscriber.php, line 18
Namespace
Drupal\multiversion\EventSubscriberView source
class MenuLinkContentMigrateSubscriber implements EventSubscriberInterface {
/**
* @var \Drupal\Core\Database\Connection
*/
protected $connection;
/**
* @var \Drupal\Core\Menu\MenuLinkManagerInterface
*/
protected $menuLinkManager;
/**
* Class constructor.
*
* @param \Drupal\Core\Database\Connection $connection
* @param \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager
*/
public function __construct(Connection $connection, MenuLinkManagerInterface $menu_link_manager) {
$this->connection = $connection;
$this->menuLinkManager = $menu_link_manager;
}
/**
* Set rediscover property and rebuild menu trees.
*
* @param \Drupal\multiversion\Event\MultiversionManagerEvent $event
*/
public function onPostMigrateLinks(MultiversionManagerEvent $event) {
if ($event
->getOp() === MultiversionManager::OP_DISABLE && ($entity_type = $event
->getEntityType('menu_link_content'))) {
$data_table = $entity_type
->getDataTable();
// Truncate 'menu_tree' table before rebuild.
$this->connection
->truncate('menu_tree')
->execute();
// Set a rediscover and rebuild menu_tree table.
// @see \Drupal\menu_link_content\Plugin\Deriver\MenuLinkContentDeriver
$this->connection
->update($data_table)
->fields([
'rediscover' => 1,
])
->execute();
$this->menuLinkManager
->rebuild();
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
return [
MultiversionManagerEvents::POST_MIGRATE => [
'onPostMigrateLinks',
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MenuLinkContentMigrateSubscriber:: |
protected | property | ||
MenuLinkContentMigrateSubscriber:: |
protected | property | ||
MenuLinkContentMigrateSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
MenuLinkContentMigrateSubscriber:: |
public | function | Set rediscover property and rebuild menu trees. | |
MenuLinkContentMigrateSubscriber:: |
public | function | Class constructor. |