Commit 88a73d86 authored by alexpott's avatar alexpott

Issue #2462907 by tstoeckler, penyaskito, Gábor Hojtsy, miro_dietiker: Entity...

Issue #2462907 by tstoeckler, penyaskito, Gábor Hojtsy, miro_dietiker: Entity operations to field UI shown in config overview
parent c2f5a3e8
......@@ -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);
......
......@@ -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,
);
......
......@@ -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.
......
......@@ -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');
......
name: 'Entity Operation Test'
type: module
description: 'Provides a test operation to entities.'
package: Testing
version: VERSION
core: 8.x
<?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,
],
];
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment