You are here

class RoleSplitDeriver in Config Role Split 8

Deriver for Config Role Split filters.

Hierarchy

Expanded class hierarchy of RoleSplitDeriver

File

src/Plugin/ConfigFilter/RoleSplitDeriver.php, line 14

Namespace

Drupal\config_role_split\Plugin\ConfigFilter
View source
class RoleSplitDeriver extends DeriverBase implements ContainerDeriverInterface {

  /**
   * The menu storage.
   *
   * @var \Drupal\Core\Entity\EntityStorageInterface
   */
  protected $entityStorage;

  /**
   * The config Factory to load the overridden configuration.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * SplitFilter constructor.
   *
   * @param \Drupal\Core\Entity\EntityStorageInterface $entity_storage
   *   The entity storage to load the split entities from.
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The config factory to load the configuration including overrides from.
   */
  public function __construct(EntityStorageInterface $entity_storage, ConfigFactoryInterface $config_factory) {
    $this->entityStorage = $entity_storage;
    $this->configFactory = $config_factory;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, $base_plugin_id) {
    return new static($container
      ->get('entity_type.manager')
      ->getStorage('role_split'), $container
      ->get('config.factory'));
  }

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    foreach ($this->entityStorage
      ->loadMultiple() as $name => $entity) {
      $config_name = $entity
        ->getConfigDependencyName();
      $config = $this->configFactory
        ->get($config_name);
      $this->derivatives[$name] = $base_plugin_definition;
      $this->derivatives[$name]['label'] = $entity
        ->label();
      $this->derivatives[$name]['config_name'] = $config_name;

      // The roles and mode are read from the storage if it exists.
      $this->derivatives[$name]['roles'] = $config
        ->get('roles');
      $this->derivatives[$name]['mode'] = $config
        ->get('mode');

      // The weight and status can be overwritten in settings.php, however,
      // the cache has to ble cleared for changes in overrides to take effect.
      $this->derivatives[$name]['weight'] = $config
        ->get('weight');
      $this->derivatives[$name]['status'] = $config
        ->get('status');
      $this->derivatives[$name]['config_dependencies']['config'] = [
        $config_name,
      ];
    }
    return $this->derivatives;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
RoleSplitDeriver::$configFactory protected property The config Factory to load the overridden configuration.
RoleSplitDeriver::$entityStorage protected property The menu storage.
RoleSplitDeriver::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
RoleSplitDeriver::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
RoleSplitDeriver::__construct public function SplitFilter constructor.