Skip to content

Commit

Permalink
feat(SHS-5907): Add update hook to grant site managers view access to…
Browse files Browse the repository at this point in the history
… private pages
  • Loading branch information
codechefmarc committed Dec 3, 2024
1 parent 03e6f6c commit 2b56b5f
Showing 1 changed file with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1036,3 +1036,44 @@ function su_humsci_profile_update_9715() {
'grant content access simple',
]);
}

/**
* Changes all private pages to allow site managers view access.
*/
function su_humsci_profile_update_9716(&$sandbox) {
$node_type = 'hs_private_page';

// Update content type (and defaults for new nodes).
$settings = content_access_get_settings('all', $node_type);

array_push($settings['view'], 'site_manager');
array_push($settings['view_own'], 'site_manager');

content_access_set_settings($settings, $node_type);

// Update existing nodes, if they have different settings than default.
$node_storage = \Drupal::entityTypeManager()->getStorage('node');
if (empty($sandbox['ids'])) {
$sandbox['ids'] = $node_storage->getQuery()
->accessCheck(FALSE)
->condition('type', $node_type)
->execute();
$sandbox['total'] = count($sandbox['ids']);
}
$node_ids = array_splice($sandbox['ids'], 0, 50);

/** @var \Drupal\node\NodeInterface $node */
foreach ($node_storage->loadMultiple($node_ids) as $node) {
/** @var \Drupal\Core\Field\FieldItemInterface $field_item */
$settings = content_access_get_per_node_settings($node);

if ($settings) {
array_push($settings['view'], 'site_manager');
array_push($settings['view_own'], 'site_manager');
content_access_save_per_node_settings($node, $settings);
}
}

$sandbox['#finished'] = count($sandbox['ids']) ? 1 - count($sandbox['ids']) / $sandbox['total'] : 1;

}

0 comments on commit 2b56b5f

Please sign in to comment.