function context_form_alter in Context 8.4
Same name and namespace in other branches
- 6.3 context.core.inc \context_form_alter()
- 6 context.core.inc \context_form_alter()
- 6.2 context.core.inc \context_form_alter()
- 7.3 context.core.inc \context_form_alter()
Implements hook_form_alter().
File
- ./
context.module, line 97 - Defines Drupal hooks for context module.
Code
function context_form_alter(&$form, FormStateInterface $form_state, $form_id) {
// If this is Context form.
if ($form_id === 'context_edit_form') {
$reactions = $form["reactions"]["#process"];
foreach ($reactions as $reaction) {
foreach ($reaction as $react) {
if (is_object($react) && property_exists($react, 'entity') && $react
->getEntity()
->getEntityTypeId() === 'context') {
// If menu reaction is selected.
$entity = $react
->getEntity();
if (!empty($entity
->get('reactions')) && array_key_exists('menu', $entity
->get('reactions'))) {
// Verify is the correct context class service is correct.
$definition = \Drupal::service('menu.active_trail');
if (!$definition instanceof ContextMenuActiveTrail) {
// Warn users about this skip.
$messenger = \Drupal::messenger();
$messenger
->addMessage(t('@module will not work because @service has a different menu service provider.', [
'@module' => 'Context module: "Menu Reactions"',
'@service' => 'menu.active_trail',
]), $messenger::TYPE_WARNING);
$form_state
->disableRedirect();
}
}
}
}
}
}
}