Browse Source

Remove duplicate media delete action (#153)

* Removing duplicate delete media action

* Torching test

* Update hook

* Coding standards
pull/729/head
dannylamb 6 years ago committed by Mark Jordan
parent
commit
310481be34
  1. 13
      config/install/system.action.delete_media.yml
  2. 4
      config/schema/islandora.schema.yml
  3. 12
      islandora.install
  4. 35
      src/Plugin/Action/DeleteMedia.php
  5. 25
      tests/src/Functional/DeleteMediaTest.php

13
config/install/system.action.delete_media.yml

@ -1,13 +0,0 @@
langcode: en
status: true
dependencies:
enforced:
module:
- islandora
module:
- islandora
id: delete_media
label: 'Delete media'
type: media
plugin: delete_media
configuration: { }

4
config/schema/islandora.schema.yml

@ -68,10 +68,6 @@ action.configuration.emit_term_event:
type: text
label: 'Event Type'
action.configuration.delete_media:
type: action_configuration_default
label: 'Delete media'
action.configuration.delete_media_and_file:
type: action_configuration_default
label: 'Delete media and file'

12
islandora.install

@ -40,3 +40,15 @@ function islandora_schema() {
];
return $schema;
}
/**
* Delete the 'delete_media' action we used to provide, if it exists.
*
* Use the core 'media_delete_action' instead.
*/
function islandora_update_8001(&$sandbox) {
$action = \Drupal::service('entity_type.manager')->getStorage('action')->load('delete_media');
if ($action) {
$action->delete();
}
}

35
src/Plugin/Action/DeleteMedia.php

@ -1,35 +0,0 @@
<?php
namespace Drupal\islandora\Plugin\Action;
use Drupal\Core\Action\ActionBase;
use Drupal\Core\Session\AccountInterface;
/**
* Deletes a media.
*
* @Action(
* id = "delete_media",
* label = @Translation("Delete media"),
* type = "media"
* )
*/
class DeleteMedia extends ActionBase {
/**
* {@inheritdoc}
*/
public function execute($entity = NULL) {
if ($entity) {
$entity->delete();
}
}
/**
* {@inheritdoc}
*/
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
return $object->access('delete', $account, $return_as_object);
}
}

25
tests/src/Functional/DeleteMediaTest.php

@ -35,31 +35,6 @@ class DeleteMediaTest extends IslandoraFunctionalTestBase {
list($this->file, $this->media) = $this->makeMediaAndFile($account);
}
/**
* Tests the delete_media action.
*
* @covers \Drupal\islandora\Plugin\Action\DeleteMedia::execute
*/
public function testDeleteMedia() {
$action = $this->container->get('entity_type.manager')->getStorage('action')->load('delete_media');
$mid = $this->media->id();
$fid = $this->file->id();
$action->execute([$this->media]);
// Attempt to reload the entities.
// Media should be gone but file should remain.
$this->assertTrue(
!$this->container->get('entity_type.manager')->getStorage('media')->load($mid),
"Media must be deleted after running action"
);
$this->assertTrue(
$this->container->get('entity_type.manager')->getStorage('file')->load($fid),
"File must remain after running action"
);
}
/**
* Tests the delete_media_and_file action.
*

Loading…
Cancel
Save