class RulesUiConfigHandler in Rules 8.3
The default handler for RulesUi plugins that store to config.
It follows a list of supported settings. Note that settings that are not marked as optional are required.
- config_parameter: The name of the routing parameter holding a config object providing the edited component. The parameter object must implement \Drupal\rules\Ui\RulesUiComponentProviderInterface. Required, unless config_name and config_key are provided.
- config_name: The name of a (simple) configuration object containing the configuration data of the edited component. For example, 'your_module.your_config'. Required if 'config_parameter' is omitted.
- config_key: The key used to get/set the configuration of the edited component. For example, 'conditions' or 'foo.conditions'. Required if 'config_parameter' is omitted.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\rules\Ui\RulesUiConfigHandler implements ContainerFactoryPluginInterface, RulesUiHandlerInterface uses TempStoreTrait
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of RulesUiConfigHandler
See also
\Drupal\rules\Ui\RulesUiDefinition::settings()
4 files declare their use of RulesUiConfigHandler
- ReactionRuleEditForm.php in src/
Form/ ReactionRuleEditForm.php - RulesComponentEditForm.php in src/
Form/ RulesComponentEditForm.php - RulesUiEmbedTest.php in tests/
src/ Kernel/ RulesUiEmbedTest.php - SettingsForm.php in tests/
modules/ rules_test_ui_embed/ src/ Form/ SettingsForm.php
File
- src/
Ui/ RulesUiConfigHandler.php, line 33
Namespace
Drupal\rules\UiView source
class RulesUiConfigHandler extends PluginBase implements RulesUiHandlerInterface, ContainerFactoryPluginInterface {
use TempStoreTrait;
/**
* The rules UI (plugin) definition.
*
* @var \Drupal\rules\Ui\RulesUiDefinition
*/
protected $pluginDefinition;
/**
* The current route match.
*
* @var \Drupal\Core\Routing\RouteMatchInterface
*/
protected $currentRouteMatch;
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('current_route_match'), $container
->get('config.factory'));
}
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteMatchInterface $route_match, ConfigFactoryInterface $config_factory) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->currentRouteMatch = $route_match;
$this->configFactory = $config_factory;
}
/**
* Gets the edited config object.
*
* @return \Drupal\rules\Ui\RulesUiComponentProviderInterface|\Drupal\Core\Config\Config
* The component provider object (usually a config entity) or the editable
* config object.
*/
public function getConfig() {
$config = $this
->fetchFromTempStore();
if (!$config) {
if (isset($this->pluginDefinition->settings['config_parameter'])) {
$config = $this->currentRouteMatch
->getParameter($this->pluginDefinition->settings['config_parameter']);
}
else {
$config = $this->configFactory
->getEditable($this->pluginDefinition->settings['config_name']);
}
}
return $config;
}
/**
* {@inheritdoc}
*/
public function getComponentLabel() {
if (isset($this->pluginDefinition->component_label)) {
return $this->pluginDefinition->component_label;
}
elseif ($this
->getConfig() instanceof EntityInterface) {
return $this
->getConfig()
->label();
}
else {
return $this->pluginDefinition->component_type_label;
}
}
/**
* {@inheritdoc}
*/
public function getComponent() {
$config = $this
->getConfig();
if ($config instanceof RulesUiComponentProviderInterface) {
return $config
->getComponent();
}
else {
$configuration = $config
->get($this->pluginDefinition->settings['config_key']);
return RulesComponent::createFromConfiguration($configuration);
}
}
/**
* {@inheritdoc}
*/
public function updateComponent(RulesComponent $component) {
$config = $this
->getConfig();
if ($config instanceof RulesUiComponentProviderInterface) {
$config
->updateFromComponent($component);
}
else {
$config
->set($this->pluginDefinition->settings['config_key'], $component
->getConfiguration());
}
$this
->storeToTempStore($config);
}
/**
* {@inheritdoc}
*/
public function getBaseRouteUrl(array $options = []) {
// @see \Drupal\Core\Url::fromRouteMatch()
return Url::fromRoute($this->pluginDefinition->base_route, $this->currentRouteMatch
->getRawParameters()
->all(), $options);
}
/**
* {@inheritdoc}
*/
public function getUrlFromRoute($route_suffix, array $route_parameters, array $options = []) {
// @see \Drupal\Core\Url::fromRouteMatch()
return Url::fromRoute($this->pluginDefinition->base_route . '.' . $route_suffix, $route_parameters + $this->currentRouteMatch
->getRawParameters()
->all(), $options);
}
/**
* {@inheritdoc}
*/
public function getForm() {
return new EmbeddedComponentForm($this);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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_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. | |
RulesUiConfigHandler:: |
protected | property | The config factory. | |
RulesUiConfigHandler:: |
protected | property | The current route match. | |
RulesUiConfigHandler:: |
protected | property |
The rules UI (plugin) definition. Overrides PluginBase:: |
|
RulesUiConfigHandler:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
RulesUiConfigHandler:: |
public | function |
Returns the URL of the base route, based on the current URL. Overrides RulesUiHandlerInterface:: |
|
RulesUiConfigHandler:: |
public | function |
Gets the currently edited component. Overrides RulesUiHandlerInterface:: |
|
RulesUiConfigHandler:: |
public | function |
Gets the human-readable label of the component. Overrides RulesUiHandlerInterface:: |
|
RulesUiConfigHandler:: |
public | function | Gets the edited config object. | |
RulesUiConfigHandler:: |
public | function |
Gets the component form, ready to be embedded in some other form. Overrides RulesUiHandlerInterface:: |
|
RulesUiConfigHandler:: |
public | function |
Gets an URL for a Rules UI route. Overrides RulesUiHandlerInterface:: |
|
RulesUiConfigHandler:: |
public | function |
Updates the edited component. Overrides RulesUiHandlerInterface:: |
|
RulesUiConfigHandler:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
|
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. | |
TempStoreTrait:: |
protected | property | The date formatter service. | |
TempStoreTrait:: |
protected | property | The entity type manager service. | |
TempStoreTrait:: |
protected | property | The renderer service. | |
TempStoreTrait:: |
protected | property | The currently active rules UI handler. | |
TempStoreTrait:: |
protected | property | The temporary store for the rules component. | |
TempStoreTrait:: |
protected | property | The tempstore factory. | |
TempStoreTrait:: |
public | function | ||
TempStoreTrait:: |
public | function | ||
TempStoreTrait:: |
protected | function | Fetches the stored data from the temporary storage. | |
TempStoreTrait:: |
protected | function | Retrieves the date formatter service if not already present. | |
TempStoreTrait:: |
protected | function | Retrieves the entity type manager service if not already present. | |
TempStoreTrait:: |
public | function | ||
TempStoreTrait:: |
public | function | Retrieves the renderer service if not already present. | |
TempStoreTrait:: |
protected | function | Gets the currently active RulesUI's handler. | |
TempStoreTrait:: |
private | function | Gets the temporary storage repository from the factory. | |
TempStoreTrait:: |
protected | function | Retrieves the temporary storage service if not already present. | |
TempStoreTrait:: |
private | function | Generates the temp store item's ID to use for the edited component. | |
TempStoreTrait:: |
public | function | ||
TempStoreTrait:: |
public | function | ||
TempStoreTrait:: |
private | function | Provides a lock info message. | |
TempStoreTrait:: |
public | function | Setter injection for the date formatter service. | |
TempStoreTrait:: |
public | function | Setter injection for the temporary storage factory. | |
TempStoreTrait:: |
protected | function | Stores some data in the temporary storage. | |
TempStoreTrait:: |
public | function |