SystemMenuBlock.php in Drupal 10
File
core/modules/system/src/Plugin/Derivative/SystemMenuBlock.php
View source
<?php
namespace Drupal\system\Plugin\Derivative;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class SystemMenuBlock extends DeriverBase implements ContainerDeriverInterface {
protected $menuStorage;
public function __construct(EntityStorageInterface $menu_storage) {
$this->menuStorage = $menu_storage;
}
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($container
->get('entity_type.manager')
->getStorage('menu'));
}
public function getDerivativeDefinitions($base_plugin_definition) {
foreach ($this->menuStorage
->loadMultiple() as $menu => $entity) {
$this->derivatives[$menu] = $base_plugin_definition;
$this->derivatives[$menu]['admin_label'] = $entity
->label();
$this->derivatives[$menu]['config_dependencies']['config'] = [
$entity
->getConfigDependencyName(),
];
}
return $this->derivatives;
}
}