diff --git a/src/Context/ContextDefinition.php b/src/Context/ContextDefinition.php
index 1ff4d44a..2b835649 100644
--- a/src/Context/ContextDefinition.php
+++ b/src/Context/ContextDefinition.php
@@ -21,11 +21,19 @@ class ContextDefinition extends ContextDefinitionCore implements ContextDefiniti
'multiple' => 'isMultiple',
'required' => 'isRequired',
'default_value' => 'defaultValue',
+ 'form_element' => 'formElement',
'constraints' => 'constraints',
'allow_null' => 'allowNull',
'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.
*
@@ -113,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..2dac81cc 100644
--- a/src/Context/ContextDefinitionInterface.php
+++ b/src/Context/ContextDefinitionInterface.php
@@ -60,6 +60,25 @@ public function getAssignmentRestriction();
*/
public function setAssignmentRestriction($restriction);
+ /**
+ * Determines form element for the context type
+ * e.g textarea.
+ *
+ * @return string
+ * 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 e535ba99..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' => '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',
]);
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"),