Skip to content

Commit

Permalink
Handled case when media is deleted.
Browse files Browse the repository at this point in the history
  • Loading branch information
kepol committed Mar 5, 2024
1 parent 197f315 commit d93ee42
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions quant.module
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@ function _quant_entity_delete_op(EntityInterface $entity) {
case 'file':
Seed::unpublishFile($entity);
break;

case 'media':
Seed::unpublishMedia($entity);
break;
}

}
Expand Down
27 changes: 27 additions & 0 deletions src/Seed.php
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,33 @@ public static function unpublishFile(EntityInterface $entity) {
\Drupal::service('event_dispatcher')->dispatch(new QuantEvent('', $url, [], NULL), QuantEvent::UNPUBLISH);
}

/**
* Unpublish the media from Quant.
*
* @param Drupal\Core\Entity\EntityInterface $entity
* The media entity.
*/
public static function unpublishMedia(EntityInterface $entity) {

// @todo Handle custom media types or ones from other modules. Could grab
// all fields through introspection and check if it's a file field.
$fields = [
'field_media_audio_file',
'field_media_document',
'field_media_image',
'field_media_video_file',
];

foreach ($fields as $field) {
if ($entity->hasField($field)) {
$file = $entity->get($field)->entity;
if ($file) {
self::unpublishFile($file);
}
}
}
}

/**
* Unpublish path alias via API request.
*/
Expand Down

0 comments on commit d93ee42

Please sign in to comment.