You are here

function entity_pager_update_8101 in Entity Pager 8

Same name and namespace in other branches
  1. 2.0.x entity_pager.install \entity_pager_update_8101()

Update entity_pager configuration in existing views.

File

./entity_pager.install, line 11
Install, update and uninstall functions for the Entity Pager module.

Code

function entity_pager_update_8101() {
  $config_factory = \Drupal::configFactory();
  $views = $config_factory
    ->listAll('views.view.');
  foreach ($views as $view) {
    $config = $config_factory
      ->getEditable($view);
    $displays = $config
      ->get('display');
    $save = FALSE;
    foreach ($displays as $display_id => $display) {
      $style = $display['display_options']['style'];
      if ($style['type'] == 'entity_pager' && isset($style['options']['next_prev'])) {
        $style_options = array_merge($style['options'], $style['options']['next_prev']);
        unset($style_options['next_prev']);
        $displays[$display_id]['display_options']['style']['options'] = $style_options;
        $save = TRUE;
      }
    }
    if ($save) {
      $config
        ->set('display', $displays);
      $config
        ->save(TRUE);
    }
  }
}