class AddExpressionForm in Rules 8.3
UI form to add an expression like a condition or action to a rule.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\rules\Form\EditExpressionForm
- class \Drupal\rules\Form\AddExpressionForm
- class \Drupal\rules\Form\EditExpressionForm
Expanded class hierarchy of AddExpressionForm
File
- src/
Form/ AddExpressionForm.php, line 16
Namespace
Drupal\rules\FormView source
class AddExpressionForm extends EditExpressionForm {
/**
* The Rules expression manager to get expression plugins.
*
* @var \Drupal\rules\Engine\ExpressionManagerInterface
*/
protected $expressionManager;
/**
* The expression ID that is added, example: 'rules_action'.
*
* @var string
*/
protected $expressionId;
/**
* Creates a new object of this class.
*/
public function __construct(ExpressionManagerInterface $expression_manager) {
$this->expressionManager = $expression_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('plugin.manager.rules_expression'));
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, RulesUiHandlerInterface $rules_ui_handler = NULL, $uuid = NULL, $expression_id = NULL) {
$this->expressionId = $expression_id;
$this->uuid = $uuid;
// When initially adding the expression, we have to initialize the object
// and add the expression.
if (!$this->uuid) {
// Before we add our edited expression to the component's expression,
// we clone it such that we do not change the source component until
// the form has been successfully submitted.
$component = clone $rules_ui_handler
->getComponent();
$this->uuid = $this
->getEditedExpression($component)
->getUuid();
$form_state
->set('component', $component);
$form_state
->set('uuid', $this->uuid);
}
return parent::buildForm($form, $form_state, $rules_ui_handler, $this->uuid);
}
/**
* {@inheritdoc}
*/
protected function getEditedExpression(RulesComponent $component) {
$component_expression = $component
->getExpression();
if (!$component_expression instanceof ExpressionContainerInterface) {
throw new LogicException('Cannot add expression to expression of type ' . $component_expression
->getPluginId());
}
if ($this->uuid && ($expression = $component_expression
->getExpression($this->uuid))) {
return $expression;
}
else {
$expression = $this->expressionManager
->createInstance($this->expressionId);
$rule_expression = $component
->getExpression();
$rule_expression
->addExpressionObject($expression);
return $expression;
}
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$form_state
->setRedirectUrl($this->rulesUiHandler
->getBaseRouteUrl());
}
/**
* Provides the page title on the form.
*/
public function getTitle(RulesUiHandlerInterface $rules_ui_handler, $expression_id) {
$this->expressionId = $expression_id;
$expression = $this->expressionManager
->createInstance($this->expressionId);
return $this
->t('Add @expression', [
'@expression' => $expression
->getLabel(),
]);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AddExpressionForm:: |
protected | property | The expression ID that is added, example: 'rules_action'. | |
AddExpressionForm:: |
protected | property | The Rules expression manager to get expression plugins. | |
AddExpressionForm:: |
public | function |
Form constructor. Overrides EditExpressionForm:: |
|
AddExpressionForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
AddExpressionForm:: |
protected | function |
Gets the currently edited expression from the given component. Overrides EditExpressionForm:: |
|
AddExpressionForm:: |
public | function |
Provides the page title on the form. Overrides EditExpressionForm:: |
|
AddExpressionForm:: |
public | function |
Form submission handler. Overrides EditExpressionForm:: |
|
AddExpressionForm:: |
public | function | Creates a new object of this class. | |
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 | |
EditExpressionForm:: |
protected | property | The edited component. | |
EditExpressionForm:: |
protected | property | The RulesUI handler of the currently active UI. | |
EditExpressionForm:: |
protected | property | The UUID of the edited expression in the rule. | |
EditExpressionForm:: |
protected | function | Builds an updated component object based upon the submitted form values. | |
EditExpressionForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
EditExpressionForm:: |
public | function |
Form validation handler. Overrides FormBase:: |
|
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
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. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |