Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/Context/ContextDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,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.
*
Expand Down Expand Up @@ -117,4 +125,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;
}

}
19 changes: 19 additions & 0 deletions src/Context/ContextDefinitionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
6 changes: 4 additions & 2 deletions src/Form/Expression/ContextFormTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
use Drupal\rules\Context\DataProcessorManagerTrait;

/**
Expand Down Expand Up @@ -52,7 +52,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,
Expand All @@ -61,6 +61,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. <em>To make entity fields appear in the data selector, you may have to use the condition 'entity has field' (or 'content is of type').</em> More useful tips about data selection is available in <a href=':url'>the online documentation</a>.", [
':url' => 'https://www.drupal.org/node/1300042',
]);
Expand Down
1 change: 1 addition & 0 deletions src/Plugin/RulesAction/SystemSendEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down