roleStorage = $role_storage; } /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { return new static( $configuration, $plugin_id, $plugin_definition, $container->get('entity.manager')->getStorage('user_role') ); } public function getValueOptions() { $this->valueOptions = user_role_names(TRUE); unset($this->valueOptions[RoleInterface::AUTHENTICATED_ID]); return $this->valueOptions; } /** * Override empty and not empty operator labels to be clearer for user roles. */ public function operators() { $operators = parent::operators(); $operators['empty']['title'] = $this->t("Only has the 'authenticated user' role"); $operators['not empty']['title'] = $this->t("Has roles in addition to 'authenticated user'"); return $operators; } /** * {@inheritdoc} */ public function calculateDependencies() { $dependencies = []; if (in_array($this->operator, ['empty', 'not empty'])) { return $dependencies; } foreach ($this->value as $role_id) { $role = $this->roleStorage->load($role_id); $dependencies[$role->getConfigDependencyKey()][] = $role->getConfigDependencyName(); } return $dependencies; } }