class Regions in Context 8
Same name and namespace in other branches
- 8.4 src/Plugin/ContextReaction/Regions.php \Drupal\context\Plugin\ContextReaction\Regions
Provides a content reaction that will let you disable regions.
Plugin annotation
@ContextReaction(
id = "regions",
label = @Translation("Regions")
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\context\ContextReactionPluginBase implements ContextReactionInterface
- class \Drupal\context\Plugin\ContextReaction\Regions implements ContainerFactoryPluginInterface
- class \Drupal\context\ContextReactionPluginBase implements ContextReactionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of Regions
File
- src/
Plugin/ ContextReaction/ Regions.php, line 20
Namespace
Drupal\context\Plugin\ContextReactionView source
class Regions extends ContextReactionPluginBase implements ContainerFactoryPluginInterface {
/**
* An array of regions to be disabled with this reaction.
*
* @var array
*/
protected $regions = [];
/**
* @var \Drupal\Core\Theme\ThemeManagerInterface
*/
protected $themeManager;
/**
* @var \Drupal\Core\Extension\ThemeHandlerInterface
*/
protected $themeHandler;
/**
* {@inheritdoc}
*/
function __construct(array $configuration, $pluginId, $pluginDefinition, ThemeManagerInterface $themeManager, ThemeHandlerInterface $themeHandler) {
parent::__construct($configuration, $pluginId, $pluginDefinition);
$this->themeManager = $themeManager;
$this->themeHandler = $themeHandler;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $pluginId, $pluginDefinition) {
return new static($configuration, $pluginId, $pluginDefinition, $container
->get('theme.manager'), $container
->get('theme_handler'));
}
/**
* {@inheritdoc}
*/
public function summary() {
return $this
->t('Lets you remove regions from selected theme.');
}
/**
* Executes the plugin.
*/
public function execute() {
// TODO: Implement execute() method.
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$themes = $this->themeHandler
->listInfo();
$default_theme = $this->themeHandler
->getDefault();
// Build configuration form for each installed theme.
foreach ($themes as $theme_id => $theme) {
if ($theme_id == $default_theme) {
$title = $this
->t('Disable Regions in %theme (Default)', [
'%theme' => $theme->info['name'],
]);
}
else {
$title = $this
->t('Disable Regions in %theme', [
'%theme' => $theme->info['name'],
]);
}
$form[$theme_id] = [
'#type' => 'details',
'#title' => $title,
'#weight' => 5,
'#open' => FALSE,
];
// Get regions of the theme.
$regions = $this
->getSystemRegionList($theme_id);
// Get disabled regions.
$disabled_regions = $this
->getDisabledRegions();
$form[$theme_id]['regions'] = [
'#type' => 'checkboxes',
'#options' => $regions,
'#title' => $this
->t('Disable the following'),
'#default_value' => isset($disabled_regions[$theme_id]) ? $disabled_regions[$theme_id] : [],
];
}
return $form;
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$themes = $form_state
->getValues();
if (is_array($themes)) {
foreach ($themes as $theme_name => $region) {
$disabled_regions = array_keys(array_filter($region['regions']));
if (!empty($disabled_regions)) {
$configuration['regions'][$theme_name] = $disabled_regions;
$configuration += $this
->getConfiguration();
}
else {
$configuration['regions'][$theme_name] = [];
$configuration += $this
->getConfiguration();
}
$this
->setConfiguration($configuration);
}
}
}
/**
* Wraps system_region_list().
*
* @param string $theme
* The theme to get a list of regions for.
*
* @param string $show
* What type of regions that should be returned, defaults to all regions.
*
* @return array
*
* @todo This could be moved to a service since we use it in a couple of places.
*/
protected function getSystemRegionList($theme, $show = REGIONS_ALL) {
return system_region_list($theme, $show);
}
/**
* Get disabled regions.
*/
protected function getDisabledRegions() {
$configurations = $this
->getConfiguration();
return isset($configurations['regions']) ? $configurations['regions'] : [];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ContextReactionPluginBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
|
ContextReactionPluginBase:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurablePluginInterface:: |
2 |
ContextReactionPluginBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurablePluginInterface:: |
1 |
ContextReactionPluginBase:: |
public | function |
Get the unique ID of this context reaction. Overrides ContextReactionInterface:: |
|
ContextReactionPluginBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurablePluginInterface:: |
1 |
ContextReactionPluginBase:: |
public | function |
Form validation handler is optional. Overrides PluginFormInterface:: |
|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
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. | |
Regions:: |
protected | property | An array of regions to be disabled with this reaction. | |
Regions:: |
protected | property | ||
Regions:: |
protected | property | ||
Regions:: |
public | function |
Form constructor. Overrides PluginFormInterface:: |
|
Regions:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
Regions:: |
public | function |
Executes the plugin. Overrides ExecutableInterface:: |
|
Regions:: |
protected | function | Get disabled regions. | |
Regions:: |
protected | function | Wraps system_region_list(). | |
Regions:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
|
Regions:: |
public | function |
Provides a human readable summary of the condition's configuration. Overrides ContextReactionInterface:: |
|
Regions:: |
function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides ContextReactionPluginBase:: |
||
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. |