You are here

function business_rules_entity_form_display_alter in Business Rules 2.x

Same name and namespace in other branches
  1. 8 business_rules.module \business_rules_entity_form_display_alter()

Implements hook_entity_form_display_alter().

The trick here is to pass the $form_display as a reference.

File

./business_rules.module, line 520
Business Rules module.

Code

function business_rules_entity_form_display_alter(EntityFormDisplayInterface &$form_display, array $context) {
  $reacts_on_definition = \Drupal::getContainer()
    ->get('plugin.manager.business_rules.reacts_on')
    ->getDefinition('form_display_mode_alter');
  $loop_control = $form_display
    ->id();
  $event = new BusinessRulesEvent($form_display, [
    'entity_type_id' => $context['entity_type'],
    'bundle' => $context['bundle'],
    'reacts_on' => $reacts_on_definition,
    'loop_control' => $loop_control,
    'form_display' => NULL,
  ]);

  /** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher */
  $event_dispatcher = \Drupal::service('event_dispatcher');
  $event_dispatcher
    ->dispatch($reacts_on_definition['eventName'], $event);
  $new_form_display = $event
    ->getArgument('form_display');
  if ($new_form_display instanceof EntityFormDisplayInterface) {
    $form_display = $new_form_display;
  }
}