From 88a73d862e715e0c2bc119fb5f927d1fdd090342 Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Fri, 17 Jul 2015 17:23:27 +0100 Subject: [PATCH] =?UTF-8?q?Issue=20#2462907=20by=20tstoeckler,=20penyaskit?= =?UTF-8?q?o,=20G=C3=A1bor=20Hojtsy,=20miro=5Fdietiker:=20Entity=20operati?= =?UTF-8?q?ons=20to=20field=20UI=20shown=20in=20config=20overview?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entity/EntityListBuilderInterface.php | 3 +- core/lib/Drupal/Core/Entity/entity.api.php | 6 ++-- .../ConfigTranslationEntityListBuilder.php | 4 +-- .../Tests/ConfigTranslationOverviewTest.php | 28 ++++++++++++++++++- .../entity_test_operation.info.yml | 6 ++++ .../entity_test_operation.module | 21 ++++++++++++++ 6 files changed, 61 insertions(+), 7 deletions(-) create mode 100644 core/modules/system/tests/modules/entity_test_operation/entity_test_operation.info.yml create mode 100644 core/modules/system/tests/modules/entity_test_operation/entity_test_operation.module diff --git a/core/lib/Drupal/Core/Entity/EntityListBuilderInterface.php b/core/lib/Drupal/Core/Entity/EntityListBuilderInterface.php index 67e65a38c443..9d1a98c5518a 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 3c68a577ec4d..c2638c40a1bb 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 1db0164a2ec1..0c50f2a499b0 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 a2f6a6cf91dc..4c83a38133ed 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 000000000000..eb905d4f6fd9 --- /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 000000000000..bdea7ba2a029 --- /dev/null +++ b/core/modules/system/tests/modules/entity_test_operation/entity_test_operation.module @@ -0,0 +1,21 @@ +<?php + +/** + * @file + * Contains hook implementations for Entity Operation Test Module. + */ + +use Drupal\Core\Url; + +/** + * Implements hook_entity_operation(). + */ +function entity_test_operation_entity_operation(\Drupal\Core\Entity\EntityInterface $entity) { + return [ + 'test' => [ + 'title' => t('Front page'), + 'url' => Url::fromRoute('<front>'), + 'weight' => 0, + ], + ]; +} -- GitLab