You are here

function panels_everywhere_post_update_route_override in Panels Everywhere 8.4

Upgrade path for existing sites, adds route override to every variant.

File

./panels_everywhere.post_update.php, line 11
Post update functions for Panels Everywhere.

Code

function panels_everywhere_post_update_route_override() {
  $entity_type_manager = \Drupal::entityTypeManager();
  $entities = $entity_type_manager
    ->getStorage('page')
    ->loadMultiple();

  /* @var $entity \Drupal\page_manager\Entity\Page */
  foreach ($entities as $entity) {
    $route_override = $entity
      ->getThirdPartySetting('panels_everywhere', 'disable_route_override');
    $variants = $entity
      ->getVariants();

    /* @var $variant \Drupal\page_manager\Entity\PageVariant */
    foreach ($variants as $variant) {
      $settings = $variant
        ->get('variant_settings');
      $settings['route_override_enabled'] = $route_override;
      $variant
        ->set('variant_settings', $settings);
      $variant
        ->save();
    }
    $entity
      ->unsetThirdPartySetting('panels_everywhere', 'disable_route_override');
    $entity
      ->save();
  }
  \Drupal::service('router.builder')
    ->rebuild();
}