Skip to content

email body as text area #453

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: 8.x-3.x
Choose a base branch
from
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 @@ -21,11 +21,19 @@ class ContextDefinition extends ContextDefinitionCore implements ContextDefiniti
'multiple' => 'isMultiple',
'required' => 'isRequired',
'default_value' => 'defaultValue',
'form_element' => 'formElement',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You haven't added 'formElement'.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'formElement' is at src/Plugin/RulesAction/SystemSendEmail.php

Copy link
Contributor

@yanniboi yanniboi May 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that I can see. You need something like:

  /**
   * Type of form element to be used.
   *
   * @var string
   */
  protected $formElement = 'textfield';

ContextDefinition::toArray() is trying to set ContextDefinition::$formElement and it doesn't exist yet.

'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 @@ -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;
}

}
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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return type is wrong, this should be "string", right?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add an example, '... , for example "textarea".'

*/
public function getFormElement();

/**
* Sets the form element for context.
*
* @param string $form_element
* Type of form element to be used.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add an example, '... , for example "textarea"."'

*
* @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;

/**
* Provides form logic for handling contexts when configuring an expression.
Expand Down Expand Up @@ -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,
Expand All @@ -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. <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