diff --git a/core/lib/Drupal/Core/Entity/EntityListBuilderInterface.php b/core/lib/Drupal/Core/Entity/EntityListBuilderInterface.php index 67e65a3..9d1a98c 100644 --- a/core/lib/Drupal/Core/Entity/EntityListBuilderInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityListBuilderInterface.php @@ -41,8 +41,7 @@ public function load(); * An associative array of operation link data for this list, keyed by * operation name, containing the following key-value pairs: * - title: The localized title of the operation. - * - href: The path for the operation. - * - options: An array of URL options for the path. + * - url: An instance of \Drupal\Core\Url for the operation URL. * - weight: The weight of this operation. */ public function getOperations(EntityInterface $entity); diff --git a/core/lib/Drupal/Core/Entity/entity.api.php b/core/lib/Drupal/Core/Entity/entity.api.php index 3c68a57..c2638c4 100644 --- a/core/lib/Drupal/Core/Entity/entity.api.php +++ b/core/lib/Drupal/Core/Entity/entity.api.php @@ -1808,13 +1808,15 @@ function hook_entity_field_storage_info_alter(&$fields, \Drupal\Core\Entity\Enti * * @return array * An operations array as returned by - * \Drupal\Core\Entity\EntityListBuilderInterface::getOperations(). + * EntityListBuilderInterface::getOperations(). + * + * @see \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', + 'url' => \Drupal\Core\Url::fromRoute('foo_module.entity.translate'), 'weight' => 50, ); diff --git a/core/modules/config_translation/src/Controller/ConfigTranslationEntityListBuilder.php b/core/modules/config_translation/src/Controller/ConfigTranslationEntityListBuilder.php index 1db0164..0c50f2a 100644 --- a/core/modules/config_translation/src/Controller/ConfigTranslationEntityListBuilder.php +++ b/core/modules/config_translation/src/Controller/ConfigTranslationEntityListBuilder.php @@ -84,8 +84,8 @@ public function buildHeader() { /** * {@inheritdoc} */ - public function getDefaultOperations(EntityInterface $entity) { - $operations = parent::getDefaultOperations($entity); + public function getOperations(EntityInterface $entity) { + $operations = parent::getOperations($entity); foreach (array_keys($operations) as $operation) { // This is a translation UI for translators. Show the translation // operation only. diff --git a/core/modules/config_translation/src/Tests/ConfigTranslationOverviewTest.php b/core/modules/config_translation/src/Tests/ConfigTranslationOverviewTest.php index a2f6a6c..4c83a38 100644 --- a/core/modules/config_translation/src/Tests/ConfigTranslationOverviewTest.php +++ b/core/modules/config_translation/src/Tests/ConfigTranslationOverviewTest.php @@ -23,7 +23,16 @@ class ConfigTranslationOverviewTest extends WebTestBase { * * @var array */ - public static $modules = array('contact', 'config_translation', 'views', 'views_ui', 'contextual', 'config_test', 'config_translation_test'); + public static $modules = [ + 'config_test', + 'config_translation', + 'config_translation_test', + 'contact', + 'contextual', + 'entity_test_operation', + 'views', + 'views_ui', + ]; /** * Languages to enable. @@ -67,6 +76,14 @@ public function testMapperListPage() { $this->drupalGet('admin/config/regional/config-translation'); $this->assertLinkByHref('admin/config/regional/config-translation/config_test'); $this->assertLinkByHref('admin/config/people/accounts/translate'); + // Make sure there is only a single operation for each dropbutton, either + // 'List' or 'Translate'. + foreach ($this->cssSelect('ul.dropbutton') as $i => $dropbutton) { + $this->assertIdentical(1, $dropbutton->count()); + foreach ($dropbutton->li as $link) { + $this->assertTrue(((string) $link->a === 'Translate') || ((string) $link->a === 'List')); + } + } $labels = array( '&$nxd~i0', @@ -86,6 +103,15 @@ public function testMapperListPage() { $this->assertLinkByHref($base_url . '/translate'); $this->assertText(SafeMarkup::checkPlain($test_entity->label())); + // Make sure there is only a single 'Translate' operation for each + // dropbutton. + foreach ($this->cssSelect('ul.dropbutton') as $i => $dropbutton) { + $this->assertIdentical(1, $dropbutton->count()); + foreach ($dropbutton->li as $link) { + $this->assertIdentical('Translate', (string) $link->a); + } + } + $entity_type = \Drupal::entityManager()->getDefinition($test_entity->getEntityTypeId()); $this->drupalGet($base_url . '/translate'); diff --git a/core/modules/system/tests/modules/entity_test_operation/entity_test_operation.info.yml b/core/modules/system/tests/modules/entity_test_operation/entity_test_operation.info.yml new file mode 100644 index 0000000..eb905d4 --- /dev/null +++ b/core/modules/system/tests/modules/entity_test_operation/entity_test_operation.info.yml @@ -0,0 +1,6 @@ +name: 'Entity Operation Test' +type: module +description: 'Provides a test operation to entities.' +package: Testing +version: VERSION +core: 8.x diff --git a/core/modules/system/tests/modules/entity_test_operation/entity_test_operation.module b/core/modules/system/tests/modules/entity_test_operation/entity_test_operation.module new file mode 100644 index 0000000..bdea7ba --- /dev/null +++ b/core/modules/system/tests/modules/entity_test_operation/entity_test_operation.module @@ -0,0 +1,21 @@ + [ + 'title' => t('Front page'), + 'url' => Url::fromRoute(''), + 'weight' => 0, + ], + ]; +}