Compare commits

..

No commits in common. 'main' and 'unpublished_conditions' have entirely different histories.

  1. 16
      README.md
  2. 4
      islandlives.info.yml
  3. 52
      islandlives.module

16
README.md

@ -1,13 +1,9 @@
# "IslandLives" Roblib customization module Features:
## Features: 1. red highlight of Views rows that have class 'Unpublished'.
2. pathauto fallback for pattern 'repository_items' that defaults to NID if field_pid is empty
1. Pathauto fallback: if the pattern is named `repository_items` and the item does not have a value in `[node:field_pid]` then `[node:nid]` will be used. Configuration:
2. CSS library to highlight "Unpublished" things: When you render a View, if it's in the (hardcoded) list, this module will apply a red highlight of rows that have class 'Unpublished'.
3. Adds Conditions (e.g. for use in Contexts) for "Media is published" and "Taxonomy term is published"
4. Fixes a bug in DGI's Islandora Hierarchical Access (possibly now addressed by [this commit](https://github.com/discoverygarden/islandora_hierarchical_access/commit/aaff6f4481cdfcb4335572c7db943223076ca28b) where the module was granting public access to unpublished media and their files, when the node was published. This fix locks down unpublished Media and their files.
## Configuration: 1. Set up the views listed in `islandlives_views_pre_render()` so that under Table > Settings > "Row class" they have '{{ status }}'. Then the css selector should pick up 'Unpublished'. You may need to add the Published (status) field to the views.
2. Create a pathauto pattern called 'repository_items'.
1. (Pathauto fallback): Create a pathauto pattern called `repository_items`, and put `[node:field_pid]` in the pattern. With this module enabled it will fallback to node id if there is no pid.
2. Set up any the views listed in `islandlives_views_pre_render()` so that under Table > Settings > "Row class" they have '{{ status }}' (and the status field is set to display "Unpublished" if the item is unpublished). Then the css selector should pick up 'Unpublished'. You may need to add the Published (status) field to the views.

4
islandlives.info.yml

@ -1,5 +1,5 @@
name: IslandLives (Roblib Islandora) customization module name: IslandLives customization module
description: Lets aliases use PID but fallback to NID; also highlights unpublished items in red. description: Hooks and custom elements for IslandLives.
package: Custom package: Custom
type: module type: module

52
islandlives.module

@ -12,7 +12,7 @@ use Drupal\views\ViewExecutable;
* Implements hook_pathauto_pattern_alter(). * Implements hook_pathauto_pattern_alter().
*/ */
function islandlives_pathauto_pattern_alter(PathautoPatternInterface $pattern, array $context) { function islandlives_pathauto_pattern_alter(PathautoPatternInterface $pattern, array $context) {
// Nodes: Only act if the pattern has machine name `repository_items`. // Only act on the repository_items pattern.
if ($pattern->id() == 'repository_items') { if ($pattern->id() == 'repository_items') {
// If node has no PID... // If node has no PID...
$node = $context['data']['node']; $node = $context['data']['node'];
@ -23,17 +23,6 @@ function islandlives_pathauto_pattern_alter(PathautoPatternInterface $pattern, a
$pattern->setPattern($new_pattern); $pattern->setPattern($new_pattern);
} }
} }
// Taxonomy Terms: Only act if the pattern has machine name `person_vocabulary`.
if ($pattern->id() == 'person_vocabulary') {
// If term has no PID...
$term = $context['data']['term'];
$pid = $term->get('field_pid')->value;
if ($pid == NULL) {
// Replace the PID with the TID in the alias.
$new_pattern = preg_replace('/\[term:field_pid\]/', '[term:tid]', $pattern->getPattern());
$pattern->setPattern($new_pattern);
}
}
} }
/** /**
@ -45,47 +34,8 @@ function islandlives_views_pre_render(ViewExecutable $view) {
'media', 'media',
'manage_members', 'manage_members',
'media_of', 'media_of',
'all_scholars',
]; ];
if (isset($view) && (in_array($view->storage->id(), $applicable_views))) { if (isset($view) && (in_array($view->storage->id(), $applicable_views))) {
$view->element['#attached']['library'][] = 'islandlives/unpublished'; $view->element['#attached']['library'][] = 'islandlives/unpublished';
} }
} }
/**
* Implements hook_entity_access().
*/
function islandlives_entity_access(\Drupal\Core\Entity\EntityInterface $entity, $operation, \Drupal\Core\Session\AccountInterface $account) {
// Only modify access for 'view' and 'download' operations, and only for anonymous users.
if (!($operation === 'view' || $operation === 'download') || !$account->isAnonymous()) {
return \Drupal\Core\Access\AccessResult::neutral();
}
if ($entity instanceof \Drupal\media\MediaInterface) {
if (!$entity->isPublished()) {
return \Drupal\Core\Access\AccessResult::forbidden('Media is not published.');
}
}
$moduleHandler = \Drupal::service('module_handler');
if (!$moduleHandler->moduleExists('islandora_hierarchical_access')) {
return \Drupal\Core\Access\AccessResult::neutral();
}
elseif ($entity instanceof \Drupal\file\FileInterface) {
// Get all media attached to the files.
$media = \Drupal::database()->select(\Drupal\islandora_hierarchical_access\LUTGeneratorInterface::TABLE_NAME, 'lut')
->fields('lut', ['mid'])
->condition("lut.fid", $entity->id())
->execute()
->fetchCol();
foreach ($media as $mid) {
$media_entity = \Drupal::entityTypeManager()->getStorage('media')->load($mid);
if ($media_entity && !$media_entity->isPublished()) {
return \Drupal\Core\Access\AccessResult::forbidden('Media is not published.');
}
}
}
}

Loading…
Cancel
Save