class RolesConditionCreator in Block Visibility Groups 8
A condition creator to be used in creating user role condition.
Plugin annotation
@ConditionCreator(
id = "roles",
label = "Roles",
condition_plugin = "user_role"
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\block_visibility_groups_admin\Plugin\ConditionCreatorBase implements ConditionCreatorInterface uses StringTranslationTrait
- class \Drupal\block_visibility_groups_admin\Plugin\ConditionCreator\RolesConditionCreator
- class \Drupal\block_visibility_groups_admin\Plugin\ConditionCreatorBase implements ConditionCreatorInterface uses StringTranslationTrait
Expanded class hierarchy of RolesConditionCreator
File
- block_visibility_groups_admin/
src/ Plugin/ ConditionCreator/ RolesConditionCreator.php, line 16
Namespace
Drupal\block_visibility_groups_admin\Plugin\ConditionCreatorView source
class RolesConditionCreator extends ConditionCreatorBase {
/**
* {@inheritdoc}
*/
public function getNewConditionLabel() {
return $this
->t('Roles');
}
/**
* {@inheritdoc}
*/
public function createConditionElements() {
$elements['condition_config'] = [
'#tree' => TRUE,
];
// @todo Dynamically create condition for by call ConditionPluginBase::buildConfigurationForm?
$elements['condition_config']['roles'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('When the user has the following roles'),
'#options' => array_map('\\Drupal\\Component\\Utility\\Html::escape', user_role_names()),
];
return $elements;
}
/**
* {@inheritdoc}
*/
public function itemSelected($condition_info) {
$roles = $condition_info['condition_config']['roles'];
return !empty(array_filter($roles));
}
/**
* {@inheritdoc}
*/
public function createConditionConfig($plugin_info) {
$config = parent::createConditionConfig($plugin_info);
$config['roles'] = array_filter($config['roles']);
// @todo Dynamically figure out context by loading connect plugin?
$config['context_mapping'] = [
'user' => '@user.current_user_context:current_user',
];
return $config;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConditionCreatorBase:: |
protected | property | ||
ConditionCreatorBase:: |
protected | property | ||
ConditionCreatorBase:: |
public | function |
RouteConditionCreator constructor. Overrides PluginBase:: |
1 |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
RolesConditionCreator:: |
public | function |
Create condition configuration from form submission. Overrides ConditionCreatorBase:: |
|
RolesConditionCreator:: |
public | function |
Create condition elements for form. Overrides ConditionCreatorBase:: |
|
RolesConditionCreator:: |
public | function |
Get the label when creating a new condition. Overrides ConditionCreatorInterface:: |
|
RolesConditionCreator:: |
public | function |
Determine if a condition was selected in the form. Overrides ConditionCreatorBase:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |