class RulesUiConfigHandler
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 \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait extends \Drupal\Component\Plugin\PluginBase
- class \Drupal\rules\Ui\RulesUiConfigHandler implements \Drupal\rules\Ui\RulesUiHandlerInterface, \Drupal\Core\Plugin\ContainerFactoryPluginInterface uses \Drupal\rules\Ui\TempStoreTrait extends \Drupal\Core\Plugin\PluginBase
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait extends \Drupal\Component\Plugin\PluginBase
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
| Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
|---|---|---|---|---|---|
| DependencySerializationTrait::$_entityStorages | protected | property | An array of entity type IDs keyed by the property name of their storages. | ||
| DependencySerializationTrait::$_serviceIds | protected | property | An array of service IDs keyed by property name used for serialization. | ||
| DependencySerializationTrait::__sleep | public | function | 2 | ||
| DependencySerializationTrait::__wakeup | public | function | #[\ReturnTypeWillChange] | 2 | |
| MessengerTrait::$messenger | protected | property | The messenger. | 27 | |
| MessengerTrait::messenger | public | function | Gets the messenger. | 27 | |
| MessengerTrait::setMessenger | public | function | Sets the messenger. | ||
| PluginBase::$configuration | protected | property | Configuration information passed into the plugin. | 1 | |
| PluginBase::$pluginId | protected | property | The plugin_id. | ||
| PluginBase::DERIVATIVE_SEPARATOR | constant | A string which is used to separate base plugin IDs from the derivative ID. | |||
| PluginBase::getBaseId | public | function | Gets the base_plugin_id of the plugin instance. | Overrides DerivativeInspectionInterface::getBaseId | |
| PluginBase::getDerivativeId | public | function | Gets the derivative_id of the plugin instance. | Overrides DerivativeInspectionInterface::getDerivativeId | |
| PluginBase::getPluginDefinition | public | function | Gets the definition of the plugin implementation. | Overrides PluginInspectionInterface::getPluginDefinition | 2 |
| PluginBase::getPluginId | public | function | Gets the plugin_id of the plugin instance. | Overrides PluginInspectionInterface::getPluginId | |
| PluginBase::isConfigurable | public | function | Determines if the plugin is configurable. | ||
| RulesUiConfigHandler::$configFactory | protected | property | The config factory. | ||
| RulesUiConfigHandler::$currentRouteMatch | protected | property | The current route match. | ||
| RulesUiConfigHandler::$pluginDefinition | protected | property | The rules UI (plugin) definition. | Overrides PluginBase::$pluginDefinition | |
| RulesUiConfigHandler::create | public static | function | Creates an instance of the plugin. | Overrides ContainerFactoryPluginInterface::create | |
| RulesUiConfigHandler::getBaseRouteUrl | public | function | Returns the URL of the base route, based on the current URL. | Overrides RulesUiHandlerInterface::getBaseRouteUrl | |
| RulesUiConfigHandler::getComponent | public | function | Gets the currently edited component. | Overrides RulesUiHandlerInterface::getComponent | |
| RulesUiConfigHandler::getComponentLabel | public | function | Gets the human-readable label of the component. | Overrides RulesUiHandlerInterface::getComponentLabel | |
| RulesUiConfigHandler::getConfig | public | function | Gets the edited config object. | ||
| RulesUiConfigHandler::getForm | public | function | Gets the component form, ready to be embedded in some other form. | Overrides RulesUiHandlerInterface::getForm | |
| RulesUiConfigHandler::getUrlFromRoute | public | function | Gets an URL for a Rules UI route. | Overrides RulesUiHandlerInterface::getUrlFromRoute | |
| RulesUiConfigHandler::updateComponent | public | function | Updates the edited component. | Overrides RulesUiHandlerInterface::updateComponent | |
| RulesUiConfigHandler::__construct | public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | Overrides PluginBase::__construct | |
| StringTranslationTrait::$stringTranslation | protected | property | The string translation service. | 3 | |
| StringTranslationTrait::formatPlural | protected | function | Formats a string containing a count of items. | ||
| StringTranslationTrait::getNumberOfPlurals | protected | function | Returns the number of plurals supported by a given language. | ||
| StringTranslationTrait::getStringTranslation | protected | function | Gets the string translation service. | ||
| StringTranslationTrait::setStringTranslation | public | function | Sets the string translation service to use. | 2 | |
| StringTranslationTrait::t | protected | function | Translates a string to the current language or to a given language. | ||
| TempStoreTrait::$dateFormatter | protected | property | The date formatter service. | ||
| TempStoreTrait::$entityTypeManager | protected | property | The entity type manager service. | ||
| TempStoreTrait::$renderer | protected | property | The renderer service. | ||
| TempStoreTrait::$rulesUiHandler | protected | property | The currently active rules UI handler. | ||
| TempStoreTrait::$tempStore | protected | property | The temporary store for the rules component. | ||
| TempStoreTrait::$tempStoreFactory | protected | property | The tempstore factory. | ||
| TempStoreTrait::addLockInformation | public | function | |||
| TempStoreTrait::clearTemporaryStorage | public | function | |||
| TempStoreTrait::fetchFromTempStore | protected | function | Fetches the stored data from the temporary storage. | ||
| TempStoreTrait::getDateFormatter | protected | function | Retrieves the date formatter service if not already present. | ||
| TempStoreTrait::getEntityTypeManager | protected | function | Retrieves the entity type manager service if not already present. | ||
| TempStoreTrait::getLockMetaData | public | function | |||
| TempStoreTrait::getRenderer | public | function | Retrieves the renderer service if not already present. | ||
| TempStoreTrait::getRulesUiHandler | protected | function | Gets the currently active RulesUI's handler. | ||
| TempStoreTrait::getTempStore | private | function | Gets the temporary storage repository from the factory. | ||
| TempStoreTrait::getTempStoreFactory | protected | function | Retrieves the temporary storage service if not already present. | ||
| TempStoreTrait::getTempStoreItemId | private | function | Generates the temp store item's ID to use for the edited component. | ||
| TempStoreTrait::isEdited | public | function | |||
| TempStoreTrait::isLocked | public | function | |||
| TempStoreTrait::lockInformationMessage | private | function | Provides a lock info message. | ||
| TempStoreTrait::setDateFormatter | public | function | Setter injection for the date formatter service. | ||
| TempStoreTrait::setTempStoreFactory | public | function | Setter injection for the temporary storage factory. | ||
| TempStoreTrait::storeToTempStore | protected | function | Stores some data in the temporary storage. | ||
| TempStoreTrait::validateLock | public | function |