|
|
|
|
@ -2,17 +2,12 @@
|
|
|
|
|
|
|
|
|
|
namespace Drupal\islandora\Plugin\Action; |
|
|
|
|
|
|
|
|
|
use Drupal\Core\Database\Connection; |
|
|
|
|
use Drupal\Core\Session\AccountInterface; |
|
|
|
|
use Drupal\file\Entity\File; |
|
|
|
|
use Drupal\islandora\MediaSource\MediaSourceService; |
|
|
|
|
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; |
|
|
|
|
use Psr\Log\LoggerInterface; |
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
|
|
|
use Drupal\islandora\Plugin\Action\DeleteMediaAndFile; |
|
|
|
|
use Drupal\Core\Entity\EntityFieldManagerInterface; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Deletes a media and all associated files. |
|
|
|
|
* |
|
|
|
|
@ -23,34 +18,39 @@ use Drupal\Core\Entity\EntityFieldManagerInterface;
|
|
|
|
|
* ) |
|
|
|
|
*/ |
|
|
|
|
class DeleteMediaAndMultifiles extends DeleteMediaAndFile implements ContainerFactoryPluginInterface { |
|
|
|
|
/** |
|
|
|
|
* Entity field manager. |
|
|
|
|
* |
|
|
|
|
* @var \Drupal\Core\Entity\EntityFieldManagerInterface |
|
|
|
|
*/ |
|
|
|
|
private $entityFieldManager; |
|
|
|
|
|
|
|
|
|
private $entity_field_manager; |
|
|
|
|
|
|
|
|
|
public function __construct(array $configuration, $plugin_id, $plugin_definition, MediaSourceService $media_source_service, Connection $connection, LoggerInterface $logger) { |
|
|
|
|
parent::__construct($configuration, $plugin_id, $plugin_definition, $media_source_service, $connection, $logger); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* {@inheritdoc} |
|
|
|
|
*/ |
|
|
|
|
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { |
|
|
|
|
$instance = parent::create($container, $configuration, $plugin_id, $plugin_definition); |
|
|
|
|
$instance->setEntityFieldManager($container->get('entity_field.manager')); |
|
|
|
|
return $instance; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Sets entity field manager. |
|
|
|
|
*/ |
|
|
|
|
public function setEntityFieldManager(EntityFieldManagerInterface $entity_field_manager) { |
|
|
|
|
$this->entity_field_manager = $entity_field_manager; |
|
|
|
|
public function setEntityFieldManager(EntityFieldManagerInterface $entityFieldManager) { |
|
|
|
|
$this->entityFieldManager = $entityFieldManager; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* {@inheritdoc} |
|
|
|
|
*/ |
|
|
|
|
public function execute($entity = NULL) { |
|
|
|
|
if (!$entity) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$delete = FALSE; |
|
|
|
|
$fields = $this->entity_field_manager->getFieldDefinitions('media', $entity->bundle()); |
|
|
|
|
$fields = $this->entityFieldManager->getFieldDefinitions('media', $entity->bundle()); |
|
|
|
|
$files = []; |
|
|
|
|
foreach ($fields as $field) { |
|
|
|
|
$type = $field->getType(); |
|
|
|
|
@ -66,7 +66,7 @@ class DeleteMediaAndMultifiles extends DeleteMediaAndFile implements ContainerFa
|
|
|
|
|
$delete = TRUE; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if($delete) { |
|
|
|
|
if ($delete) { |
|
|
|
|
$entity->delete(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -77,4 +77,5 @@ class DeleteMediaAndMultifiles extends DeleteMediaAndFile implements ContainerFa
|
|
|
|
|
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) { |
|
|
|
|
return $object->access('delete', $account, $return_as_object); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|