You are here

class FeatureListMenuLink in Configuration selector 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Derivative/FeatureListMenuLink.php \Drupal\config_selector\Plugin\Derivative\FeatureListMenuLink

Test derivative with an unsafe string.

Hierarchy

Expanded class hierarchy of FeatureListMenuLink

1 string reference to 'FeatureListMenuLink'
config_selector.links.menu.yml in ./config_selector.links.menu.yml
config_selector.links.menu.yml

File

src/Plugin/Derivative/FeatureListMenuLink.php, line 15

Namespace

Drupal\config_selector\Plugin\Derivative
View source
class FeatureListMenuLink extends DeriverBase implements ContainerDeriverInterface, ContainerInjectionInterface {

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * FeatureListAccessCheck constructor.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    $this->entityTypeManager = $entity_type_manager;
  }

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

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    if ($this
      ->count()) {
      $this->derivatives['config_selector.admin_display'] = $base_plugin_definition;
    }
    return $this->derivatives;
  }

  /**
   * Allows access to Config Selector UI if there are entities.
   *
   * @return \Drupal\Core\Access\AccessResultInterface
   *   The access result.
   */
  public function access() {
    $entity_type = $this->entityTypeManager
      ->getDefinition('config_selector_feature');
    return AccessResult::allowedIf($this
      ->count() > 0)
      ->addCacheTags($entity_type
      ->getListCacheTags())
      ->addCacheContexts($entity_type
      ->getListCacheContexts());
  }

  /**
   * Gets the count of feature entities.
   *
   * @return int
   *   The count of feature entities.
   */
  protected function count() {
    return $this->entityTypeManager
      ->getStorage('config_selector_feature')
      ->getQuery()
      ->accessCheck(TRUE)
      ->count()
      ->execute();
  }

}

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
FeatureListMenuLink::$entityTypeManager protected property The entity type manager.
FeatureListMenuLink::access public function Allows access to Config Selector UI if there are entities.
FeatureListMenuLink::count protected function Gets the count of feature entities.
FeatureListMenuLink::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
FeatureListMenuLink::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
FeatureListMenuLink::__construct public function FeatureListAccessCheck constructor.