Skip to content

Commit 61776c0

Browse files
Merge pull request #25 from discoverygarden/fix/status
DGI9-628: Attempt to avoid making assertions on unpublished content.
2 parents 4d321c9 + 51bcb20 commit 61776c0

File tree

6 files changed

+10
-6
lines changed

6 files changed

+10
-6
lines changed

islandora_hierarchical_access.module

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function islandora_hierarchical_access_entity_delete(EntityInterface $entity) :
7777
function islandora_hierarchical_access_entity_access(
7878
EntityInterface $entity,
7979
$operation,
80-
AccountInterface $account
80+
AccountInterface $account,
8181
) : AccessResultInterface {
8282
/** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */
8383
$entity_type_manager = \Drupal::service('entity_type.manager');

src/Commands/IslandoraHierarchicalAccessCommands.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class IslandoraHierarchicalAccessCommands extends DrushCommands {
3535
*/
3636
public function __construct(
3737
LUTGeneratorInterface $lut_generator,
38-
EntityTypeManagerInterface $entityTypeManager
38+
EntityTypeManagerInterface $entityTypeManager,
3939
) {
4040
parent::__construct();
4141
$this->lutGenerator = $lut_generator;

src/EntityAccessHandler.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Drupal\Core\Access\AccessResultReasonInterface;
88
use Drupal\Core\Database\Connection;
99
use Drupal\Core\Entity\EntityInterface;
10+
use Drupal\Core\Entity\EntityPublishedInterface;
1011
use Drupal\Core\Entity\EntityStorageInterface;
1112
use Drupal\Core\Entity\EntityTypeInterface;
1213
use Drupal\Core\Session\AccountInterface;
@@ -106,7 +107,7 @@ public function __construct(
106107
EntityStorageInterface $storage,
107108
$column,
108109
$target_column,
109-
array $op_map
110+
array $op_map,
110111
) {
111112
$this->database = $database;
112113
$this->ops = $ops;
@@ -140,6 +141,9 @@ public function check(EntityInterface $entity, string $operation, AccountInterfa
140141
if (!in_array($operation, $this->ops, TRUE)) {
141142
return AccessResult::neutral("Irrelevant operation.");
142143
}
144+
if ($entity instanceof EntityPublishedInterface && !$entity->isPublished()) {
145+
return AccessResult::neutral("Hierarchical access is only concerned with published content.");
146+
}
143147

144148
return $this->doCheck($entity, $operation, $account);
145149
}

src/EntityCUDHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function __construct(
8282
Connection $database,
8383
LUTGeneratorInterface $generator,
8484
$column,
85-
$operations
85+
$operations,
8686
) {
8787
$this->database = $database;
8888
$this->generator = $generator;

src/LUTGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function regenerate(): void {
5050
/**
5151
* {@inheritDoc}
5252
*/
53-
public function generate(EntityInterface $entity = NULL): void {
53+
public function generate(?EntityInterface $entity = NULL): void {
5454
if (count($this->uniqueFileFields()) === 0) {
5555
// Did not find any fields over which to generate the LUT so abort the
5656
// attempt.

src/LUTGeneratorInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ public function regenerate(): void;
2424
* LUT will be completely regenerated. If provided, only those rows
2525
* resulting from the given entity will be added to the table.
2626
*/
27-
public function generate(EntityInterface $entity = NULL): void;
27+
public function generate(?EntityInterface $entity = NULL): void;
2828

2929
}

0 commit comments

Comments
 (0)