public function ContextEditForm::processReactions in Context 8
Same name and namespace in other branches
- 8.4 modules/context_ui/src/Form/ContextEditForm.php \Drupal\context_ui\Form\ContextEditForm::processReactions()
- 8.0 modules/context_ui/src/Form/ContextEditForm.php \Drupal\context_ui\Form\ContextEditForm::processReactions()
Process function for the reactions.
Parameters
$element: The element to process.
FormStateInterface $form_state: The current form state.
Return value
array
File
- modules/
context_ui/ src/ Form/ ContextEditForm.php, line 158
Class
Namespace
Drupal\context_ui\FormCode
public function processReactions(&$element, FormStateInterface $form_state) {
$reactions = $this->entity
->getReactions();
$element['add_reaction'] = [
'#type' => 'link',
'#title' => $this
->t('Add reaction'),
'#url' => Url::fromRoute('context.reactions_library', [
'context' => $this->entity
->id(),
]),
'#attributes' => [
'class' => [
'use-ajax',
'button',
'button--small',
],
'data-dialog-type' => 'modal',
'data-dialog-options' => Json::encode([
'width' => 700,
]),
],
];
if (!count($reactions)) {
$element['empty'] = [
'#type' => 'container',
'#markup' => $this
->t('No reactions has been added.'),
];
}
$element['reaction_tabs'] = [
'#type' => 'vertical_tabs',
'#parents' => [
'reaction_tabs',
],
];
foreach ($reactions as $reaction_id => $reaction) {
$element['reaction-' . $reaction_id] = [
'#type' => 'details',
'#title' => $reaction
->getPluginDefinition()['label'],
'#group' => 'reaction_tabs',
];
$reaction_values = $form_state
->getValue([
'reactions',
$reaction_id,
], []);
$reaction_state = (new FormState())
->setValues($reaction_values);
$element['reaction-' . $reaction_id]['options'] = $reaction
->buildConfigurationForm([], $reaction_state, $this->entity);
$element['reaction-' . $reaction_id]['options']['#parents'] = [
'reactions',
$reaction_id,
];
$element['reaction-' . $reaction_id]['remove'] = [
'#type' => 'link',
'#title' => $this
->t('Remove reaction'),
'#url' => Url::fromRoute('context.reaction_delete', [
'context' => $this->entity
->id(),
'reaction_id' => $reaction_id,
]),
'#attributes' => [
'class' => [
'use-ajax',
'button',
'button--small',
],
'data-dialog-type' => 'modal',
'data-dialog-options' => Json::encode([
'width' => 700,
]),
],
];
}
return $element;
}