From ce53b04360b5d0b0ebe67ea3c7bbbd81755cce72 Mon Sep 17 00:00:00 2001 From: Anton MArtyniuk Date: Wed, 18 May 2016 15:35:11 +0300 Subject: [PATCH 1/4] email body as text area --- src/Context/ContextDefinition.php | 1 + src/Form/Expression/ContextFormTrait.php | 2 +- src/Plugin/RulesAction/SystemSendEmail.php | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Context/ContextDefinition.php b/src/Context/ContextDefinition.php index 1ff4d44a..c364326a 100644 --- a/src/Context/ContextDefinition.php +++ b/src/Context/ContextDefinition.php @@ -21,6 +21,7 @@ class ContextDefinition extends ContextDefinitionCore implements ContextDefiniti 'multiple' => 'isMultiple', 'required' => 'isRequired', 'default_value' => 'defaultValue', + 'form_element' => 'formElement', 'constraints' => 'constraints', 'allow_null' => 'allowNull', 'assignment_restriction' => 'assignmentRestriction', diff --git a/src/Form/Expression/ContextFormTrait.php b/src/Form/Expression/ContextFormTrait.php index e535ba99..46d4e336 100644 --- a/src/Form/Expression/ContextFormTrait.php +++ b/src/Form/Expression/ContextFormTrait.php @@ -49,7 +49,7 @@ public function buildContextForm(array $form, FormStateInterface $form_state, $c $default_value = $context_definition->getDefaultValue(); } $form['context'][$context_name]['setting'] = [ - '#type' => 'textfield', + '#type' => isset($context_definition->formElement) ? $context_definition->formElement : 'textfield', '#title' => $title, '#required' => $context_definition->isRequired(), '#default_value' => $default_value, diff --git a/src/Plugin/RulesAction/SystemSendEmail.php b/src/Plugin/RulesAction/SystemSendEmail.php index e8cc4b8c..d0c215af 100644 --- a/src/Plugin/RulesAction/SystemSendEmail.php +++ b/src/Plugin/RulesAction/SystemSendEmail.php @@ -29,6 +29,7 @@ * "message" = @ContextDefinition("string", * label = @Translation("Message"), * description = @Translation("The email's message body."), + * form_element = "textarea", * ), * "reply" = @ContextDefinition("email", * label = @Translation("Reply to"), From 114b3e1428a438c5c0e89ca84ee3a9f159177f7f Mon Sep 17 00:00:00 2001 From: yanniboi Date: Tue, 24 May 2016 20:46:47 +0100 Subject: [PATCH 2/4] Issue #2724129 by yanniboi: Added to ContextDefinition for rules contexts. --- src/Context/ContextDefinition.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Context/ContextDefinition.php b/src/Context/ContextDefinition.php index c364326a..e623ebf3 100644 --- a/src/Context/ContextDefinition.php +++ b/src/Context/ContextDefinition.php @@ -27,6 +27,13 @@ class ContextDefinition extends ContextDefinitionCore implements ContextDefiniti 'assignment_restriction' => 'assignmentRestriction', ]; + /** + * Type of form element to be used. + * + * @var string + */ + protected $formElement = 'textfield'; + /** * Whether the context value is allowed to be NULL or not. * From 8e3f1a7db2d08dd90f18d50033f675e288cdfa14 Mon Sep 17 00:00:00 2001 From: yanniboi Date: Tue, 31 May 2016 15:10:49 +0100 Subject: [PATCH 3/4] Issue #2724129 by yanniboi: Added getters and setters for formElement Context Definition property. --- src/Context/ContextDefinition.php | 15 +++++++++++++++ src/Context/ContextDefinitionInterface.php | 18 ++++++++++++++++++ src/Form/Expression/ContextFormTrait.php | 6 ++++-- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/Context/ContextDefinition.php b/src/Context/ContextDefinition.php index e623ebf3..2b835649 100644 --- a/src/Context/ContextDefinition.php +++ b/src/Context/ContextDefinition.php @@ -121,4 +121,19 @@ public function setAssignmentRestriction($restriction) { return $this; } + /** + * {@inheritdoc} + */ + public function getFormElement() { + return $this->formElement; + } + + /** + * {@inheritdoc} + */ + public function setFormElement($form_element) { + $this->formElement = $form_element; + return $this; + } + } diff --git a/src/Context/ContextDefinitionInterface.php b/src/Context/ContextDefinitionInterface.php index d5156ce2..277c52b9 100644 --- a/src/Context/ContextDefinitionInterface.php +++ b/src/Context/ContextDefinitionInterface.php @@ -60,6 +60,24 @@ public function getAssignmentRestriction(); */ public function setAssignmentRestriction($restriction); + /** + * Determines form element for the context type. + * + * @return bool + * Type of form element to be used. + */ + public function getFormElement(); + + /** + * Sets the form element for context. + * + * @param string $form_element + * Type of form element to be used. + * + * @return $this + */ + public function setFormElement($form_element); + /** * Exports the definition as an array. * diff --git a/src/Form/Expression/ContextFormTrait.php b/src/Form/Expression/ContextFormTrait.php index 46d4e336..9f193ad2 100644 --- a/src/Form/Expression/ContextFormTrait.php +++ b/src/Form/Expression/ContextFormTrait.php @@ -4,7 +4,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\rules\Context\ContextConfig; -use Drupal\Core\Plugin\Context\ContextDefinitionInterface; +use Drupal\rules\Context\ContextDefinitionInterface; /** * Provides form logic for handling contexts when configuring an expression. @@ -49,7 +49,7 @@ public function buildContextForm(array $form, FormStateInterface $form_state, $c $default_value = $context_definition->getDefaultValue(); } $form['context'][$context_name]['setting'] = [ - '#type' => isset($context_definition->formElement) ? $context_definition->formElement : 'textfield', + '#type' => $context_definition->getFormElement(), '#title' => $title, '#required' => $context_definition->isRequired(), '#default_value' => $default_value, @@ -58,6 +58,8 @@ public function buildContextForm(array $form, FormStateInterface $form_state, $c $element = &$form['context'][$context_name]['setting']; if ($mode == 'selector') { + // Always use a textfield for selector mode. + $element['#type'] = 'textfield'; $element['#description'] = $this->t("The data selector helps you drill down into the data available to Rules. To make entity fields appear in the data selector, you may have to use the condition 'entity has field' (or 'content is of type'). More useful tips about data selection is available in the online documentation.", [ ':url' => 'https://www.drupal.org/node/1300042', ]); From 3ea66cfb5ac5efe4e4cdb05ed1b2a16094212a5f Mon Sep 17 00:00:00 2001 From: Anton MArtyniuk Date: Thu, 21 Jul 2016 18:18:15 +0300 Subject: [PATCH 4/4] added small changes accorging klausi comments --- src/Context/ContextDefinitionInterface.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Context/ContextDefinitionInterface.php b/src/Context/ContextDefinitionInterface.php index 277c52b9..2dac81cc 100644 --- a/src/Context/ContextDefinitionInterface.php +++ b/src/Context/ContextDefinitionInterface.php @@ -61,9 +61,10 @@ public function getAssignmentRestriction(); public function setAssignmentRestriction($restriction); /** - * Determines form element for the context type. + * Determines form element for the context type + * e.g textarea. * - * @return bool + * @return string * Type of form element to be used. */ public function getFormElement();