diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityListBuilder.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityListBuilder.php index c6ef6248987..601de73da18 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityListBuilder.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityListBuilder.php @@ -30,9 +30,8 @@ class ConfigEntityListBuilder extends EntityListBuilder { /** * {@inheritdoc} */ - public function getDefaultOperations(EntityInterface $entity) { - /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */ - $operations = parent::getDefaultOperations($entity); + public function getOperations(EntityInterface $entity) { + $operations = parent::getOperations($entity); if ($this->entityType->hasKey('status')) { if (!$entity->status() && $entity->hasLinkTemplate('enable')) { diff --git a/core/lib/Drupal/Core/Entity/EntityListBuilder.php b/core/lib/Drupal/Core/Entity/EntityListBuilder.php index b8a0dec63c2..626c275c6a7 100644 --- a/core/lib/Drupal/Core/Entity/EntityListBuilder.php +++ b/core/lib/Drupal/Core/Entity/EntityListBuilder.php @@ -93,25 +93,6 @@ class EntityListBuilder extends EntityControllerBase implements EntityListBuilde * {@inheritdoc} */ public function getOperations(EntityInterface $entity) { - $operations = $this->getDefaultOperations($entity); - $operations += $this->moduleHandler()->invokeAll('entity_operation', array($entity)); - $this->moduleHandler->alter('entity_operation', $operations, $entity); - uasort($operations, '\Drupal\Component\Utility\SortArray::sortByWeightElement'); - - return $operations; - } - - /** - * Gets this list's default operations. - * - * @param \Drupal\Core\Entity\EntityInterface $entity - * The entity the operations are for. - * - * @return array - * The array structure is identical to the return value of - * self::getOperations(). - */ - protected function getDefaultOperations(EntityInterface $entity) { $operations = array(); if ($entity->access('update') && $entity->hasLinkTemplate('edit-form')) { $operations['edit'] = array( @@ -170,11 +151,14 @@ class EntityListBuilder extends EntityControllerBase implements EntityListBuilde * @see \Drupal\Core\Entity\EntityListBuilder::buildRow() */ public function buildOperations(EntityInterface $entity) { + // Retrieve and sort operations. + $operations = $this->getOperations($entity); + $this->moduleHandler()->alter('entity_operation', $operations, $entity); + uasort($operations, array('Drupal\Component\Utility\SortArray', 'sortByWeightElement')); $build = array( '#type' => 'operations', - '#links' => $this->getOperations($entity), + '#links' => $operations, ); - return $build; } diff --git a/core/modules/action/lib/Drupal/action/ActionListBuilder.php b/core/modules/action/lib/Drupal/action/ActionListBuilder.php index e1b575fd336..7ef6e199846 100644 --- a/core/modules/action/lib/Drupal/action/ActionListBuilder.php +++ b/core/modules/action/lib/Drupal/action/ActionListBuilder.php @@ -101,8 +101,8 @@ class ActionListBuilder extends ConfigEntityListBuilder { /** * {@inheritdoc} */ - public function getDefaultOperations(EntityInterface $entity) { - $operations = $entity->isConfigurable() ? parent::getDefaultOperations($entity) : array(); + public function getOperations(EntityInterface $entity) { + $operations = $entity->isConfigurable() ? parent::getOperations($entity) : array(); if (isset($operations['edit'])) { $operations['edit']['title'] = t('Configure'); } diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockListBuilder.php b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockListBuilder.php index 5df5a1948b5..94c9e31e629 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockListBuilder.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockListBuilder.php @@ -36,8 +36,8 @@ class CustomBlockListBuilder extends EntityListBuilder { /** * {@inheritdoc} */ - public function getDefaultOperations(EntityInterface $entity) { - $operations = parent::getDefaultOperations($entity); + public function getOperations(EntityInterface $entity) { + $operations = parent::getOperations($entity); if (isset($operations['edit'])) { $operations['edit']['query']['destination'] = 'admin/structure/block/custom-blocks'; } diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeListBuilder.php b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeListBuilder.php index 00ec8be105c..901ef6f698a 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeListBuilder.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeListBuilder.php @@ -20,8 +20,8 @@ class CustomBlockTypeListBuilder extends ConfigEntityListBuilder { /** * {@inheritdoc} */ - public function getDefaultOperations(EntityInterface $entity) { - $operations = parent::getDefaultOperations($entity); + public function getOperations(EntityInterface $entity) { + $operations = parent::getOperations($entity); // Place the edit operation after the operations added by field_ui.module // which have the weights 15, 20, 25. if (isset($operations['edit'])) { diff --git a/core/modules/block/lib/Drupal/block/BlockListBuilder.php b/core/modules/block/lib/Drupal/block/BlockListBuilder.php index a2cad009489..31b3286b055 100644 --- a/core/modules/block/lib/Drupal/block/BlockListBuilder.php +++ b/core/modules/block/lib/Drupal/block/BlockListBuilder.php @@ -378,8 +378,8 @@ class BlockListBuilder extends ConfigEntityListBuilder implements FormInterface /** * {@inheritdoc} */ - public function getDefaultOperations(EntityInterface $entity) { - $operations = parent::getDefaultOperations($entity); + public function getOperations(EntityInterface $entity) { + $operations = parent::getOperations($entity); if (isset($operations['edit'])) { $operations['edit']['title'] = t('Configure'); diff --git a/core/modules/config_translation/config_translation.module b/core/modules/config_translation/config_translation.module index cd2ab8d1127..e6f808150d6 100644 --- a/core/modules/config_translation/config_translation.module +++ b/core/modules/config_translation/config_translation.module @@ -159,18 +159,15 @@ function config_translation_config_translation_info(&$info) { } /** - * Implements hook_entity_operation(). + * Implements hook_entity_operation_alter(). */ -function config_translation_entity_operation(EntityInterface $entity) { - $operations = array(); +function config_translation_entity_operation_alter(array &$operations, EntityInterface $entity) { if (\Drupal::currentUser()->hasPermission('translate configuration')) { $operations['translate'] = array( 'title' => t('Translate'), 'weight' => 50, ) + $entity->urlInfo('drupal:config-translation-overview'); } - - return $operations; } /** diff --git a/core/modules/config_translation/lib/Drupal/config_translation/Controller/ConfigTranslationEntityListBuilder.php b/core/modules/config_translation/lib/Drupal/config_translation/Controller/ConfigTranslationEntityListBuilder.php index 9d94468e234..44f5aad2be4 100644 --- a/core/modules/config_translation/lib/Drupal/config_translation/Controller/ConfigTranslationEntityListBuilder.php +++ b/core/modules/config_translation/lib/Drupal/config_translation/Controller/ConfigTranslationEntityListBuilder.php @@ -83,13 +83,13 @@ class ConfigTranslationEntityListBuilder extends EntityListBuilder implements Co /** * {@inheritdoc} */ - public function getDefaultOperations(EntityInterface $entity) { - $operations = parent::getDefaultOperations($entity); - foreach (array_keys($operations) as $operation) { + public function buildOperations(EntityInterface $entity) { + $operations = parent::buildOperations($entity); + foreach (array_keys($operations['#links']) as $operation) { // This is a translation UI for translators. Show the translation // operation only. if (!($operation == 'translate')) { - unset($operations[$operation]); + unset($operations['#links'][$operation]); } } return $operations; diff --git a/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php b/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php index ec398c14ff6..3b2b503b09a 100644 --- a/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php +++ b/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php @@ -23,7 +23,6 @@ use Drupal\field\FieldInstanceConfigInterface; * id = "field_instance_config", * label = @Translation("Field instance"), * controllers = { - * "list_builder" = "\Drupal\Core\Config\Entity\ConfigEntityListBuilder", * "storage" = "Drupal\field\FieldInstanceConfigStorageController" * }, * config_prefix = "instance", diff --git a/core/modules/field_ui/field_ui.module b/core/modules/field_ui/field_ui.module index 12d2d6e6527..40c8f286d19 100644 --- a/core/modules/field_ui/field_ui.module +++ b/core/modules/field_ui/field_ui.module @@ -172,10 +172,9 @@ function field_ui_form_node_type_form_alter(&$form, $form_state) { } /** - * Implements hook_entity_operation(). + * Implements hook_entity_operation_alter(). */ -function field_ui_entity_operation(EntityInterface $entity) { - $operations = array(); +function field_ui_entity_operation_alter(array &$operations, EntityInterface $entity) { $info = $entity->getEntityType(); // Add manage fields and display links if this entity type is the bundle // of another. @@ -199,8 +198,6 @@ function field_ui_entity_operation(EntityInterface $entity) { ) + $entity->urlInfo('field_ui-display'); } } - - return $operations; } /** diff --git a/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php b/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php index 3c48dfbfa79..ba359cfcbac 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php @@ -7,7 +7,6 @@ namespace Drupal\field_ui; -use Drupal\Core\Entity\EntityListBuilderInterface; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Field\FieldTypePluginManagerInterface; @@ -27,6 +26,13 @@ class FieldOverview extends OverviewBase { */ protected $fieldTypeManager; + /** + * The module handler service. + * + * @var \Drupal\Core\Extension\ModuleHandlerInterface + */ + protected $moduleHandler; + /** * Constructs a new FieldOverview. * @@ -34,10 +40,13 @@ class FieldOverview extends OverviewBase { * The entity manager. * @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager * The field type manager + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The module handler to invoke hooks on. */ - public function __construct(EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_manager) { + public function __construct(EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_manager, ModuleHandlerInterface $module_handler) { parent::__construct($entity_manager); $this->fieldTypeManager = $field_type_manager; + $this->moduleHandler = $module_handler; } /** @@ -46,7 +55,8 @@ class FieldOverview extends OverviewBase { public static function create(ContainerInterface $container) { return new static( $container->get('entity.manager'), - $container->get('plugin.manager.field.field_type') + $container->get('plugin.manager.field.field_type'), + $container->get('module_handler') ); } @@ -154,9 +164,11 @@ class FieldOverview extends OverviewBase { 'route_parameters' => $route_parameters, 'attributes' => array('title' => $this->t('Delete instance.')), ); + // Allow altering the operations on this entity listing. + $this->moduleHandler->alter('entity_operation', $links, $instance); $table[$name]['operations']['data'] = array( '#type' => 'operations', - '#links' => $this->entityManager->getListBuilder('field_instance_config')->getOperations($instance), + '#links' => $links, ); if (!empty($field->locked)) { diff --git a/core/modules/filter/lib/Drupal/filter/FilterFormatListBuilder.php b/core/modules/filter/lib/Drupal/filter/FilterFormatListBuilder.php index 30825cf9273..7ba51af0044 100644 --- a/core/modules/filter/lib/Drupal/filter/FilterFormatListBuilder.php +++ b/core/modules/filter/lib/Drupal/filter/FilterFormatListBuilder.php @@ -118,8 +118,8 @@ class FilterFormatListBuilder extends DraggableListBuilder { /** * {@inheritdoc} */ - public function getDefaultOperations(EntityInterface $entity) { - $operations = parent::getDefaultOperations($entity); + public function getOperations(EntityInterface $entity) { + $operations = parent::getOperations($entity); if (isset($operations['edit'])) { $operations['edit']['title'] = t('Configure'); diff --git a/core/modules/image/lib/Drupal/image/ImageStyleListBuilder.php b/core/modules/image/lib/Drupal/image/ImageStyleListBuilder.php index 80516c06c62..e6eac9ec0bb 100644 --- a/core/modules/image/lib/Drupal/image/ImageStyleListBuilder.php +++ b/core/modules/image/lib/Drupal/image/ImageStyleListBuilder.php @@ -74,13 +74,13 @@ class ImageStyleListBuilder extends ConfigEntityListBuilder { /** * {@inheritdoc} */ - public function getDefaultOperations(EntityInterface $entity) { + public function getOperations(EntityInterface $entity) { $flush = array( 'title' => t('Flush'), 'weight' => 200, ) + $entity->urlInfo('flush-form'); - return parent::getDefaultOperations($entity) + array('flush' => $flush); + return parent::getOperations($entity) + array('flush' => $flush); } /** diff --git a/core/modules/language/lib/Drupal/language/LanguageListBuilder.php b/core/modules/language/lib/Drupal/language/LanguageListBuilder.php index c5bd66a30f6..99fb9679135 100644 --- a/core/modules/language/lib/Drupal/language/LanguageListBuilder.php +++ b/core/modules/language/lib/Drupal/language/LanguageListBuilder.php @@ -44,8 +44,8 @@ class LanguageListBuilder extends DraggableListBuilder { /** * {@inheritdoc} */ - public function getDefaultOperations(EntityInterface $entity) { - $operations = parent::getDefaultOperations($entity); + public function getOperations(EntityInterface $entity) { + $operations = parent::getOperations($entity); $default = language_default(); // Deleting the site default language is not allowed. diff --git a/core/modules/menu/lib/Drupal/menu/MenuListBuilder.php b/core/modules/menu/lib/Drupal/menu/MenuListBuilder.php index 6255f8766d8..282ce008a95 100644 --- a/core/modules/menu/lib/Drupal/menu/MenuListBuilder.php +++ b/core/modules/menu/lib/Drupal/menu/MenuListBuilder.php @@ -45,8 +45,8 @@ class MenuListBuilder extends ConfigEntityListBuilder { /** * {@inheritdoc} */ - public function getDefaultOperations(EntityInterface $entity) { - $operations = parent::getDefaultOperations($entity); + public function getOperations(EntityInterface $entity) { + $operations = parent::getOperations($entity); if (isset($operations['edit'])) { $operations['edit']['title'] = t('Edit menu'); diff --git a/core/modules/node/lib/Drupal/node/NodeListBuilder.php b/core/modules/node/lib/Drupal/node/NodeListBuilder.php index 4860183b269..d80b6b29faf 100644 --- a/core/modules/node/lib/Drupal/node/NodeListBuilder.php +++ b/core/modules/node/lib/Drupal/node/NodeListBuilder.php @@ -124,8 +124,8 @@ class NodeListBuilder extends EntityListBuilder { /** * {@inheritdoc} */ - protected function getDefaultOperations(EntityInterface $entity) { - $operations = parent::getDefaultOperations($entity); + public function getOperations(EntityInterface $entity) { + $operations = parent::getOperations($entity); $destination = drupal_get_destination(); foreach ($operations as $key => $operation) { diff --git a/core/modules/node/lib/Drupal/node/NodeTypeListBuilder.php b/core/modules/node/lib/Drupal/node/NodeTypeListBuilder.php index 90e31f0465a..681fff4fb73 100644 --- a/core/modules/node/lib/Drupal/node/NodeTypeListBuilder.php +++ b/core/modules/node/lib/Drupal/node/NodeTypeListBuilder.php @@ -83,8 +83,8 @@ class NodeTypeListBuilder extends ConfigEntityListBuilder { /** * {@inheritdoc} */ - public function getDefaultOperations(EntityInterface $entity) { - $operations = parent::getDefaultOperations($entity); + public function getOperations(EntityInterface $entity) { + $operations = parent::getOperations($entity); // Place the edit operation after the operations added by field_ui.module // which have the weights 15, 20, 25. if (isset($operations['edit'])) { diff --git a/core/modules/responsive_image/lib/Drupal/responsive_image/ResponsiveImageMappingListBuilder.php b/core/modules/responsive_image/lib/Drupal/responsive_image/ResponsiveImageMappingListBuilder.php index 2beffdd4c7a..1de736bf1b0 100644 --- a/core/modules/responsive_image/lib/Drupal/responsive_image/ResponsiveImageMappingListBuilder.php +++ b/core/modules/responsive_image/lib/Drupal/responsive_image/ResponsiveImageMappingListBuilder.php @@ -36,8 +36,8 @@ class ResponsiveImageMappingListBuilder extends ConfigEntityListBuilder { /** * {@inheritdoc} */ - public function getDefaultOperations(EntityInterface $entity) { - $operations = parent::getDefaultOperations($entity); + public function getOperations(EntityInterface $entity) { + $operations = parent::getOperations($entity); $operations['duplicate'] = array( 'title' => t('Duplicate'), 'weight' => 15, diff --git a/core/modules/search/lib/Drupal/search/SearchPageListBuilder.php b/core/modules/search/lib/Drupal/search/SearchPageListBuilder.php index d5da48e9048..e2c61cdd761 100644 --- a/core/modules/search/lib/Drupal/search/SearchPageListBuilder.php +++ b/core/modules/search/lib/Drupal/search/SearchPageListBuilder.php @@ -260,9 +260,9 @@ class SearchPageListBuilder extends DraggableListBuilder implements FormInterfac /** * {@inheritdoc} */ - public function getDefaultOperations(EntityInterface $entity) { + public function getOperations(EntityInterface $entity) { /** @var $entity \Drupal\search\SearchPageInterface */ - $operations = parent::getDefaultOperations($entity); + $operations = parent::getOperations($entity); // Prevent the default search from being disabled or deleted. if ($entity->isDefaultSearch()) { diff --git a/core/modules/shortcut/lib/Drupal/shortcut/ShortcutSetListBuilder.php b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutSetListBuilder.php index 01a59df33a2..45b6a5f963a 100644 --- a/core/modules/shortcut/lib/Drupal/shortcut/ShortcutSetListBuilder.php +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutSetListBuilder.php @@ -28,8 +28,8 @@ class ShortcutSetListBuilder extends ConfigEntityListBuilder { /** * {@inheritdoc} */ - public function getDefaultOperations(EntityInterface $entity) { - $operations = parent::getDefaultOperations($entity); + public function getOperations(EntityInterface $entity) { + $operations = parent::getOperations($entity); if (isset($operations['edit'])) { $operations['edit']['title'] = t('Edit shortcut set'); diff --git a/core/modules/system/entity.api.php b/core/modules/system/entity.api.php index 92ed070c311..0acf2c35e91 100644 --- a/core/modules/system/entity.api.php +++ b/core/modules/system/entity.api.php @@ -754,27 +754,6 @@ function hook_entity_bundle_field_info_alter(&$fields, \Drupal\Core\Entity\Entit } } -/** - * Declares entity operations. - * - * @param \Drupal\Core\Entity\EntityInterface $entity - * The entity on which the linked operations will be performed. - * - * @return array - * An operations array as returned by - * \Drupal\Core\Entity\EntityListBuilderInterface::getOperations(). - */ -function hook_entity_operation(\Drupal\Core\Entity\EntityInterface $entity) { - $operations = array(); - $operations['translate'] = array( - 'title' => t('Translate'), - 'route_name' => 'foo_module.entity.translate', - 'weight' => 50, - ); - - return $operations; -} - /** * Alter entity operations. * @@ -785,11 +764,10 @@ function hook_entity_operation(\Drupal\Core\Entity\EntityInterface $entity) { * The entity on which the linked operations will be performed. */ function hook_entity_operation_alter(array &$operations, \Drupal\Core\Entity\EntityInterface $entity) { - // Alter the title and weight. - $operations['translate']['title'] = t('Translate @entity_type', array( - '@entity_type' => $entity->getEntityTypeId(), - )); - $operations['translate']['weight'] = 99; + $operations['translate'] = array( + 'title' => t('Translate'), + 'weight' => 50, + ) + $entity->urlInfo('my-custom-link-template'); } /** diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyListBuilder.php b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyListBuilder.php index a8e11735ae6..28235519055 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyListBuilder.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyListBuilder.php @@ -32,8 +32,8 @@ class VocabularyListBuilder extends DraggableListBuilder { /** * {@inheritdoc} */ - public function getDefaultOperations(EntityInterface $entity) { - $operations = parent::getDefaultOperations($entity); + public function getOperations(EntityInterface $entity) { + $operations = parent::getOperations($entity); if (isset($operations['edit'])) { $operations['edit']['title'] = t('edit vocabulary'); diff --git a/core/modules/user/lib/Drupal/user/RoleListBuilder.php b/core/modules/user/lib/Drupal/user/RoleListBuilder.php index c6cb7635f59..2d2b9be99d8 100644 --- a/core/modules/user/lib/Drupal/user/RoleListBuilder.php +++ b/core/modules/user/lib/Drupal/user/RoleListBuilder.php @@ -43,8 +43,8 @@ class RoleListBuilder extends DraggableListBuilder { /** * {@inheritdoc} */ - public function getDefaultOperations(EntityInterface $entity) { - $operations = parent::getDefaultOperations($entity); + public function getOperations(EntityInterface $entity) { + $operations = parent::getOperations($entity); if ($entity->hasLinkTemplate('edit-permissions-form')) { $operations['permissions'] = array( diff --git a/core/modules/views_ui/lib/Drupal/views_ui/ViewListBuilder.php b/core/modules/views_ui/lib/Drupal/views_ui/ViewListBuilder.php index 90563e54a61..36f20c351e3 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/ViewListBuilder.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/ViewListBuilder.php @@ -135,8 +135,8 @@ class ViewListBuilder extends ConfigEntityListBuilder { /** * {@inheritdoc} */ - public function getDefaultOperations(EntityInterface $entity) { - $operations = parent::getDefaultOperations($entity); + public function getOperations(EntityInterface $entity) { + $operations = parent::getOperations($entity); if ($entity->hasLinkTemplate('clone')) { $operations['clone'] = array( diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php index afe54e58b53..0d9881fce62 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php @@ -7,9 +7,7 @@ namespace Drupal\Tests\Core\Entity; -use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\EntityListBuilder; use Drupal\entity_test\EntityTestListBuilder; use Drupal\Tests\UnitTestCase; @@ -22,41 +20,6 @@ use Drupal\Tests\UnitTestCase; */ class EntityListBuilderTest extends UnitTestCase { - /** - * The entity type used for testing. - * - * @var \Drupal\Core\Entity\EntityTypeInterface|\PHPUnit_Framework_MockObject_MockObject - */ - protected $entityType; - - /** - * The module handler used for testing. - * - * @var \Drupal\Core\Extension\ModuleHandlerInterface|\PHPUnit_Framework_MockObject_MockObject - */ - protected $moduleHandler; - - /** - * The translation manager used for testing. - * - * @var \Drupal\Core\StringTranslation\TranslationInterface - */ - protected $translationManager; - - /** - * The role storage used for testing. - * - * @var \Drupal\user\RoleStorageControllerInterface|\PHPUnit_Framework_MockObject_MockObject - */ - protected $roleStorage; - - /** - * The service container used for testing. - * - * @var \Drupal\Core\DependencyInjection\ContainerBuilder - */ - protected $container; - /** * The entity used to construct the EntityListBuilder. * @@ -86,59 +49,10 @@ class EntityListBuilderTest extends UnitTestCase { parent::setUp(); $this->role = $this->getMock('Drupal\user\RoleInterface'); - $this->roleStorage = $this->getMock('\Drupal\user\RoleStorageControllerInterface'); - $this->moduleHandler = $this->getMock('\Drupal\Core\Extension\ModuleHandlerInterface'); - $this->entityType = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface'); - $this->translationManager = $this->getMock('\Drupal\Core\StringTranslation\TranslationInterface'); - $this->entityListBuilder = new TestEntityListBuilder($this->entityType, $this->roleStorage, $this->moduleHandler); - $this->container = new ContainerBuilder(); - \Drupal::setContainer($this->container); - } - - /** - * @covers \Drupal\Core\Entity\EntityListBuilder::getOperations - */ - public function testGetOperations() { - $operation_name = $this->randomName(); - $operations = array( - $operation_name => array( - 'title' => $this->randomName(), - ), - ); - $this->moduleHandler->expects($this->once()) - ->method('invokeAll') - ->with('entity_operation', array($this->role)) - ->will($this->returnValue($operations)); - $this->moduleHandler->expects($this->once()) - ->method('alter') - ->with('entity_operation'); - - $this->container->set('module_handler', $this->moduleHandler); - - $this->role->expects($this->any()) - ->method('access') - ->will($this->returnValue(TRUE)); - $this->role->expects($this->any()) - ->method('hasLinkTemplate') - ->will($this->returnValue(TRUE)); - $this->role->expects($this->any()) - ->method('urlInfo') - ->will($this->returnValue(array())); - - $list = new EntityListBuilder($this->entityType, $this->roleStorage, $this->moduleHandler); - $list->setTranslationManager($this->translationManager); - - $operations = $list->getOperations($this->role); - $this->assertInternalType('array', $operations); - $this->assertArrayHasKey('edit', $operations); - $this->assertInternalType('array', $operations['edit']); - $this->assertArrayHasKey('title', $operations['edit']); - $this->assertArrayHasKey('delete', $operations); - $this->assertInternalType('array', $operations['delete']); - $this->assertArrayHasKey('title', $operations['delete']); - $this->assertArrayHasKey($operation_name, $operations); - $this->assertInternalType('array', $operations[$operation_name]); - $this->assertArrayHasKey('title', $operations[$operation_name]); + $role_storage_controller = $this->getMock('Drupal\user\RoleStorageControllerInterface'); + $module_handler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface'); + $entity_type = $this->getMock('Drupal\Core\Entity\EntityTypeInterface'); + $this->entityListBuilder = new TestEntityListBuilder($entity_type, $role_storage_controller, $module_handler); } /**