You are here

function opigno_learning_path_update_8019 in Opigno Learning path 8

Delete deprecated cache context for group-memberships.

File

./opigno_learning_path.install, line 567
Install, update and uninstall functions for the module.

Code

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

  // Update "group_members" view.
  $config = $config_factory
    ->getEditable('views.view.group_members');
  $displays = $config
    ->get('display');
  foreach ($displays as &$display) {
    $contexts =& $display['cache_metadata']['contexts'];
    if (is_array($contexts)) {
      $index = array_search('group_membership.roles.permissions', $contexts);
      if ($index !== FALSE) {

        // Delete deprecated cache context.
        array_splice($contexts, $index, 1);
      }
    }
  }
  $config
    ->set('display', $displays);
  $config
    ->save(TRUE);

  // Update "subgroups" view.
  $config = $config_factory
    ->getEditable('views.view.subgroups');
  $displays = $config
    ->get('display');
  foreach ($displays as &$display) {
    $contexts =& $display['cache_metadata']['contexts'];
    if (is_array($contexts)) {
      $index = array_search('group_membership.roles.permissions', $contexts);
      if ($index !== FALSE) {

        // Delete deprecated cache context.
        array_splice($contexts, $index, 1);
      }
    }
  }
  $config
    ->set('display', $displays);
  $config
    ->save(TRUE);
}