You are here

function opigno_module_update_8021 in Opigno module 8

Update views: 'Activity list', 'Module list', 'Groups list' and 'Opigno Score Modules'.

File

./opigno_module.install, line 1247
Opigno module app install/update functionality.

Code

function opigno_module_update_8021() {
  $config_factory = \Drupal::configFactory();

  // Update activity_list view.
  $config = $config_factory
    ->getEditable('views.view.activity_list');
  $module_dependencies = $config
    ->get('dependencies');
  $module_dependencies['module'][] = 'user';
  $config
    ->set('dependencies', $module_dependencies);
  $access = [
    'type' => 'perm',
    'options' => [
      'perm' => 'edit activity entities',
    ],
  ];
  $config
    ->set('display.default.display_options.access', $access);
  $displays = $config
    ->get('display');
  foreach ($displays as &$display) {
    $display['cache_metadata']['contexts'][] = 'user.permissions';
  }
  $config
    ->set('display', $displays);
  $config
    ->save(TRUE);

  // Update module_list view.
  $config = $config_factory
    ->getEditable('views.view.module_list');
  $module_dependencies = $config
    ->get('dependencies');
  $module_dependencies['module'][] = 'user';
  $config
    ->set('dependencies', $module_dependencies);
  $modules_list_access = [
    'type' => 'perm',
    'options' => [
      'perm' => 'edit module entities',
    ],
  ];
  $config
    ->set('display.default.display_options.access', $modules_list_access);
  $displays = $config
    ->get('display');
  foreach ($displays as &$display) {
    $display['cache_metadata']['contexts'][] = 'user.permissions';
  }
  $config
    ->set('display', $displays);
  $config
    ->save(TRUE);

  // Update groups_list view.
  $config = $config_factory
    ->getEditable('views.view.groups_list');
  $config
    ->set('display.default.display_options.access', $modules_list_access);
  $displays = $config
    ->get('display');
  foreach ($displays as &$display) {
    $display['cache_metadata']['contexts'][] = 'user.permissions';
  }
  $config
    ->set('display', $displays);
  $config
    ->save(TRUE);

  // Update permissions for opigno_score_module view.
  $config = $config_factory
    ->getEditable('views.view.opigno_score_modules');
  $config
    ->set('display.default.display_options.access.options.perm', 'access content');
  $config
    ->set('display.default.display_options.cache.type', 'none');
  $config
    ->save(TRUE);
}