You are here

function panelizer_form_entity_view_display_edit_submit in Panelizer 8.3

Same name and namespace in other branches
  1. 8.5 panelizer.module \panelizer_form_entity_view_display_edit_submit()
  2. 8.4 panelizer.module \panelizer_form_entity_view_display_edit_submit()
1 string reference to 'panelizer_form_entity_view_display_edit_submit'
panelizer_form_entity_view_display_edit_form_alter in ./panelizer.module
Implements hook_form_FORM_ID_alter().

File

./panelizer.module, line 296
Hook implementations for the Panelizer module.

Code

function panelizer_form_entity_view_display_edit_submit(&$form, FormStateInterface $form_state) {
  $rebuild = FALSE;

  /** @var \Drupal\Core\Entity\EntityFormInterface $form_object */
  $form_object = $form_state
    ->getFormObject();

  /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display */
  $display = $form_object
    ->getEntity();

  /** @var \Drupal\panelizer\Plugin\PanelizerEntityManager $panelizer_manager */
  $panelizer_manager = \Drupal::service('plugin.manager.panelizer_entity');

  /** @var \Drupal\panelizer\Panelizer $panelizer */
  $panelizer = \Drupal::service('panelizer');
  if ($panelizer_manager
    ->hasDefinition($display
    ->getTargetEntityTypeId())) {
    $settings = $panelizer
      ->getPanelizerSettings($display
      ->getTargetEntityTypeId(), $display
      ->getTargetBundle(), $display
      ->getMode(), $display);
    if ($settings['enable'] != $form_state
      ->getValue([
      'panelizer',
      'enable',
    ])) {
      $rebuild = TRUE;
    }
    $settings['enable'] = $form_state
      ->getValue([
      'panelizer',
      'enable',
    ]);
    $settings['custom'] = $form_state
      ->getValue([
      'panelizer',
      'custom',
    ]);
    $settings['allow'] = $form_state
      ->getValue([
      'panelizer',
      'allow',
    ]);
    $panelizer
      ->setPanelizerSettings($display
      ->getTargetEntityTypeId(), $display
      ->getTargetBundle(), $display
      ->getMode(), $settings, $display);
    if ($rebuild) {
      \Drupal::service('router.builder')
        ->rebuild();

      /** @var \Drupal\Core\Menu\LocalActionManager $local_action_manager */
      $local_action_manager = \Drupal::service('plugin.manager.menu.local_action');
      $local_action_manager
        ->clearCachedDefinitions();

      // Manually reinitialize these.
      $local_action_manager
        ->getDefinitions();
      \Drupal::service('cache.render')
        ->invalidateAll();
    }
  }
}