Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DDST-382: Subscriber to handle deletion of related Embargoes when a n… #13

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions islandora_entity_status.module
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Hook implementations.
*/

use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\islandora\IslandoraUtils;
Expand Down Expand Up @@ -165,3 +166,17 @@ function islandora_entity_status_batch_finished($success, $results, $operations)
$messenger->addError(t('Batch processing failed.'));
}
}

/**
* Implements hook_entity_delete().
*/
function islandora_entity_status_entity_delete(EntityInterface $entity) {
if (!$entity instanceof ContentEntityInterface) {
return;
}

// Check if the entity is a node with the bundle "islandora_object".
if ($entity->hasField(IslandoraUtils::MEMBER_OF_FIELD)) {
\Drupal::service('islandora_entity_status.islandora_node_delete_subscriber')->deleteAssociatedCustomEntity($entity);
}
}
3 changes: 3 additions & 0 deletions islandora_entity_status.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ services:
- '@entity_type.manager'
tags:
- { name: drush.command }
islandora_entity_status.islandora_node_delete_subscriber:
class: Drupal\islandora_entity_status\IslandoraNodeDeleteSubscriber
arguments: [ '@entity_type.manager' ]
45 changes: 45 additions & 0 deletions src/IslandoraNodeDeleteSubscriber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Drupal\islandora_entity_status;

use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\node\NodeInterface;

/**
* Subscriber to handle deletion of related Embargoes when a node is deleted.
*/
class IslandoraNodeDeleteSubscriber {

/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;

/**
* Constructs a new CustomEntityDeleter object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}

/**
* Deletes the associated embargos.
*
* @param \Drupal\node\NodeInterface $node
* The Islandora object node being deleted.
*/
public function deleteAssociatedCustomEntity(NodeInterface $node): void {
$custom_entity_storage = $this->entityTypeManager->getStorage('embargo');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would effectively be creating a dependency on the embargo module, yeah? Probably not desired.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adam-vessey please suggest in which module I can implement this. https://github.com/discoverygarden/embargo module?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be more of the target, yes. Still not convinced that such functionality is desired.

Like, something like a scan to find occurrences of ::getEmbargoedNode() that don't account for it being able to be NULL might be more in order?

The ticket is more about error suppression than data maintenance that this PR is getting into, or so I read it. As in, much like discoverygarden/embargo#41 , might also need to hit: https://github.com/discoverygarden/embargo/blob/a075aa4a994472666adf9cdd1af48891fb675323/src/Plugin/search_api/processor/EmbargoJoinProcessor.php#L230

$custom_entities = $custom_entity_storage->loadByProperties(['embargoed_node' => $node->id()]);

foreach ($custom_entities as $custom_entity) {
$custom_entity->delete();
}
}

}
Loading