class EventTypeDefaultMessagesListForm in RNG - Events and Registrations 8.2
Same name and namespace in other branches
- 3.x src/Form/EventTypeDefaultMessagesListForm.php \Drupal\rng\Form\EventTypeDefaultMessagesListForm
Form for event type default message.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Entity\EntityForm implements EntityFormInterface
- class \Drupal\rng\Form\EventTypeDefaultMessagesListForm
- class \Drupal\Core\Entity\EntityForm implements EntityFormInterface
Expanded class hierarchy of EventTypeDefaultMessagesListForm
File
- src/
Form/ EventTypeDefaultMessagesListForm.php, line 18
Namespace
Drupal\rng\FormView source
class EventTypeDefaultMessagesListForm extends EntityForm {
/**
* The redirect destination service.
*
* @var \Drupal\Core\Routing\RedirectDestinationInterface
*/
protected $redirectDestination;
/**
* The action manager service.
*
* @var \Drupal\Core\Action\ActionManager
*/
protected $actionManager;
/**
* The condition manager service.
*
* @var \Drupal\Core\Condition\ConditionManager
*/
protected $conditionManager;
/**
* Event type rule storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $eventTypeRuleStorage;
/**
* The RNG event manager.
*
* @var \Drupal\rng\EventManagerInterface
*/
protected $eventManager;
/**
* Rules for the event type.
*
* @var \Drupal\rng\Entity\EventTypeRuleInterface[]
*/
protected $rules;
/**
* Constructs a EventTypeAccessDefaultsForm object.
*
* @param \Drupal\Core\Routing\RedirectDestinationInterface $redirect_destination
* The redirect destination service.
* @param \Drupal\Core\Action\ActionManager $actionManager
* The action manager.
* @param \Drupal\Core\Condition\ConditionManager $conditionManager
* The condition manager.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\rng\EventManagerInterface $event_manager
* The RNG event manager.
*/
public function __construct(RedirectDestinationInterface $redirect_destination, ActionManager $actionManager, ConditionManager $conditionManager, EntityTypeManagerInterface $entity_type_manager, EventManagerInterface $event_manager) {
$this->redirectDestination = $redirect_destination;
$this->actionManager = $actionManager;
$this->conditionManager = $conditionManager;
$this->eventTypeRuleStorage = $entity_type_manager
->getStorage('rng_event_type_rule');
$this->eventManager = $event_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('redirect.destination'), $container
->get('plugin.manager.action'), $container
->get('plugin.manager.condition'), $container
->get('entity_type.manager'), $container
->get('rng.event_manager'));
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
/** @var \Drupal\rng\Entity\EventTypeInterface $event_type */
$event_type = $this->entity;
/** @var array $default_messages */
$default_messages = $form_state
->get('default_messages');
if (empty($default_messages)) {
$default_messages = $event_type
->getDefaultMessages();
$form_state
->set('default_messages', $default_messages);
}
// @TODO : Move this and other occurences into a common place?.
// @see EventTypeDefaultMessagesAddForm::buildForm.
$trigger_options = [
'rng:custom:date' => $this
->t('To all registrations, on a date.'),
(string) $this
->t('Registrations') => [
'entity:registration:new' => $this
->t('To a single registration, when it is created.'),
'entity:registration:update' => $this
->t('To a single registration, when it is updated.'),
],
];
$trigger_labels = [
'entity:registration:new' => $this
->t('Registration creation'),
'entity:registration:update' => $this
->t('Registration updated'),
'rng:custom:date' => $this
->t('Send on a date'),
];
$form['messages'] = [
'#type' => 'container',
'#attributes' => [
'id' => 'rng-default-messages-wrapper',
],
'#tree' => TRUE,
];
foreach ($default_messages as $key => $message) {
$form['messages'][$key] = [
'#type' => 'details',
'#tree' => TRUE,
'#title' => $this
->t('@label (@status)', [
'@label' => isset($trigger_labels[$message['trigger']]) ? $trigger_labels[$message['trigger']] : $message['trigger'],
'@status' => $message['status'] ? $this
->t('active') : $this
->t('disabled'),
]),
];
$form['messages'][$key]['trigger'] = [
'#type' => 'select',
'#options' => $trigger_options,
'#title' => $this
->t('Trigger'),
'#default_value' => $message['trigger'],
];
$form['messages'][$key]['status'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enabled'),
'#default_value' => $message['status'],
];
$form['messages'][$key]['subject'] = [
'#type' => 'textfield',
'#title' => $this
->t('Subject'),
'#default_value' => $message['subject'],
'#required' => TRUE,
];
$form['messages'][$key]['body'] = [
'#type' => 'textarea',
'#title' => $this
->t('Body'),
'#default_value' => $message['body'],
'#required' => TRUE,
];
$form['messages'][$key]['remove'] = [
'#type' => 'submit',
'#value' => $this
->t('Remove this message'),
'#message_key' => $key,
'#name' => 'button-message-remove-' . $key,
'#submit' => [
'::removeMessageCallback',
],
'#ajax' => [
'callback' => '::processMessageCallback',
'wrapper' => 'rng-default-messages-wrapper',
],
];
}
return $form;
}
/**
* {@inheritdoc}
*/
public function processMessageCallback(array &$form, FormStateInterface $form_state) {
// This function may be used for other ajax callbacks, too.
$triggering_element = $form_state
->getTriggeringElement();
if (strpos($triggering_element['#name'], 'button-message-remove') !== FALSE) {
unset($form['messages'][$triggering_element['#message_key']]);
return $form['messages'];
}
}
/**
* {@inheritdoc}
*/
public function removeMessageCallback(array &$form, FormStateInterface $form_state) {
$key = $form_state
->getTriggeringElement()['#message_key'];
$default_messages = $form_state
->get('default_messages');
unset($default_messages[$key]);
$form_state
->set('default_messages', $default_messages);
$form_state
->setRebuild();
}
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state) {
/** @var \Drupal\rng\Entity\EventTypeInterface $event_type */
$event_type = $this->entity;
/** @var array $default_messages */
$default_messages = $form_state
->getValue('messages');
$event_type
->setDefaultMessages($default_messages)
->save();
// Site cache needs to be cleared after enabling this setting as there are
// issue regarding caching.
Cache::invalidateTags([
'rendered',
]);
$this
->messenger()
->addMessage($this
->t('Event type default messages saved.'));
$this->eventManager
->invalidateEventType($event_type);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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 | |
EntityForm:: |
protected | property | The entity being used by this form. | 7 |
EntityForm:: |
protected | property | The entity type manager. | 3 |
EntityForm:: |
protected | property | The module handler service. | |
EntityForm:: |
protected | property | The name of the current operation. | |
EntityForm:: |
private | property | The entity manager. | |
EntityForm:: |
protected | function | Returns an array of supported actions for the current entity form. | 29 |
EntityForm:: |
protected | function | Returns the action form element for the current entity form. | |
EntityForm:: |
public | function | Form element #after_build callback: Updates the entity with submitted data. | |
EntityForm:: |
public | function |
Builds an updated entity object based upon the submitted form values. Overrides EntityFormInterface:: |
2 |
EntityForm:: |
protected | function | Copies top-level form values to entity properties | 7 |
EntityForm:: |
public | function | Gets the actual form array to be built. | 30 |
EntityForm:: |
public | function |
Returns a string identifying the base form. Overrides BaseFormIdInterface:: |
5 |
EntityForm:: |
public | function |
Gets the form entity. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
Determines which entity will be used by this form from a RouteMatch object. Overrides EntityFormInterface:: |
1 |
EntityForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
10 |
EntityForm:: |
public | function |
Gets the operation identifying the form. Overrides EntityFormInterface:: |
|
EntityForm:: |
protected | function | Initialize the form state and the entity before the first form build. | 3 |
EntityForm:: |
protected | function | Prepares the entity object before the form is built first. | 3 |
EntityForm:: |
protected | function | Invokes the specified prepare hook variant. | |
EntityForm:: |
public | function | Process callback: assigns weights and hides extra fields. | |
EntityForm:: |
public | function |
Sets the form entity. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
Sets the entity manager for this form. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
Sets the entity type manager for this form. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
Sets the module handler for this form. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
Sets the operation for this form. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
This is the default entity object builder function. It is called before any
other submit handler to build the new entity object to be used by the
following submit handlers. At this point of the form workflow the entity is
validated and the form state… Overrides FormInterface:: |
17 |
EntityForm:: |
public | function | ||
EntityForm:: |
public | function | ||
EventTypeDefaultMessagesListForm:: |
protected | property | The action manager service. | |
EventTypeDefaultMessagesListForm:: |
protected | property | The condition manager service. | |
EventTypeDefaultMessagesListForm:: |
protected | property | The RNG event manager. | |
EventTypeDefaultMessagesListForm:: |
protected | property | Event type rule storage. | |
EventTypeDefaultMessagesListForm:: |
protected | property |
The redirect destination service. Overrides RedirectDestinationTrait:: |
|
EventTypeDefaultMessagesListForm:: |
protected | property | Rules for the event type. | |
EventTypeDefaultMessagesListForm:: |
public | function |
Form constructor. Overrides EntityForm:: |
|
EventTypeDefaultMessagesListForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
EventTypeDefaultMessagesListForm:: |
public | function | ||
EventTypeDefaultMessagesListForm:: |
public | function | ||
EventTypeDefaultMessagesListForm:: |
public | function |
Form submission handler for the 'save' action. Overrides EntityForm:: |
|
EventTypeDefaultMessagesListForm:: |
public | function | Constructs a EventTypeAccessDefaultsForm object. | |
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. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
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 | 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. |