Issue #2419905 by Arla: Views field 'Operations links' fails to set destination

8.0.x
Alex Pott 2015-02-18 11:30:28 +00:00
parent 7e41973fc9
commit c2f94345fc
4 changed files with 34 additions and 65 deletions

View File

@ -99,10 +99,10 @@ class EntityOperations extends FieldPluginBase {
$operations = $this->entityManager->getListBuilder($entity->getEntityTypeId())->getOperations($entity); $operations = $this->entityManager->getListBuilder($entity->getEntityTypeId())->getOperations($entity);
if ($this->options['destination']) { if ($this->options['destination']) {
foreach ($operations as &$operation) { foreach ($operations as &$operation) {
if (!isset($operation['options']['query'])) { if (!isset($operation['query'])) {
$operation['options']['query'] = array(); $operation['query'] = array();
} }
$operation['options']['query'] += drupal_get_destination(); $operation['query'] += drupal_get_destination();
} }
} }
$build = array( $build = array(

View File

@ -7,8 +7,8 @@
namespace Drupal\views\Tests\Handler; namespace Drupal\views\Tests\Handler;
use Drupal\views\Tests\ViewUnitTestBase; use Drupal\Core\Url;
use Drupal\views\Views; use Drupal\entity_test\Entity\EntityTest;
/** /**
* Tests the core Drupal\views\Plugin\views\field\EntityOperations handler. * Tests the core Drupal\views\Plugin\views\field\EntityOperations handler.
@ -29,28 +29,30 @@ class FieldEntityOperationsTest extends HandlerTestBase {
* *
* @var array * @var array
*/ */
public static $modules = array('node'); public static $modules = array('entity_test');
/** /**
* Tests entity operations field. * Tests entity operations field.
*/ */
public function testEntityOperations() { public function testEntityOperations() {
// Create some test nodes. // Create some test entities.
$nodes = array();
for ($i = 0; $i < 5; $i++) { for ($i = 0; $i < 5; $i++) {
$nodes[] = $this->drupalCreateNode(); EntityTest::create(array(
'name' => $this->randomString(),
))->save();
} }
$entities = EntityTest::loadMultiple();
$admin_user = $this->drupalCreateUser(array('access administration pages', 'bypass node access')); $admin_user = $this->drupalCreateUser(array('access administration pages', 'administer entity_test content'));
$this->drupalLogin($admin_user); $this->drupalLogin($admin_user);
$this->drupalGet('test-entity-operations'); $this->drupalGet('test-entity-operations');
/* @var $node \Drupal\node\NodeInterface */ foreach ($entities as $entity) {
foreach ($nodes as $node) { $operations = \Drupal::entityManager()->getListBuilder('entity_test')->getOperations($entity);
$operations = \Drupal::entityManager()->getListBuilder('node')->getOperations($node);
foreach ($operations as $operation) { foreach ($operations as $operation) {
$result = $this->xpath('//ul[contains(@class, dropbutton)]/li/a[contains(@href, :path) and text()=:title]', array(':path' => $operation['url']->getInternalPath(), ':title' => $operation['title'])); $expected_destination = Url::fromUri('user-path:/test-entity-operations');
$this->assertEqual(count($result), 1, t('Found node @operation link.', array('@operation' => $operation['title']))); $result = $this->xpath('//ul[contains(@class, dropbutton)]/li/a[contains(@href, :path) and text()=:title]', array(':path' => $operation['url'] . '?destination=' . $expected_destination, ':title' => $operation['title']));
$this->assertEqual(count($result), 1, t('Found entity @operation link with destination parameter.', array('@operation' => $operation['title'])));
} }
} }
} }

View File

@ -108,7 +108,7 @@ class EntityOperationsUnitTest extends UnitTestCase {
'#type' => 'operations', '#type' => 'operations',
'#links' => $operations '#links' => $operations
); );
$expected_build['#links']['foo']['options']['query'] = drupal_get_destination(); $expected_build['#links']['foo']['query'] = drupal_get_destination();
$build = $this->plugin->render($result); $build = $this->plugin->render($result);
$this->assertSame($expected_build, $build); $this->assertSame($expected_build, $build);
} }

View File

@ -2,15 +2,14 @@ langcode: und
status: true status: true
dependencies: dependencies:
module: module:
- node - entity_test
- user
id: test_entity_operations id: test_entity_operations
label: test_entity_operations label: test_entity_operations
module: views module: views
description: '' description: ''
tag: '' tag: ''
base_table: node base_table: entity_test
base_field: nid base_field: id
core: 8.x core: 8.x
display: display:
default: default:
@ -20,7 +19,7 @@ display:
position: null position: null
display_options: display_options:
access: access:
type: perm type: none
cache: cache:
type: none type: none
query: query:
@ -36,16 +35,15 @@ display:
row: row:
type: fields type: fields
fields: fields:
nid: name:
id: nid id: name
table: node table: entity_test
field: nid field: name
plugin_id: node
relationship: none relationship: none
group_type: group group_type: group
admin_label: '' admin_label: ''
label: Nid label: ''
exclude: true exclude: false
alter: alter:
alter_text: false alter_text: false
text: '' text: ''
@ -77,7 +75,7 @@ display:
element_class: '' element_class: ''
element_label_type: '' element_label_type: ''
element_label_class: '' element_label_class: ''
element_label_colon: true element_label_colon: false
element_wrapper_type: '' element_wrapper_type: ''
element_wrapper_class: '' element_wrapper_class: ''
element_default_classes: true element_default_classes: true
@ -85,32 +83,12 @@ display:
hide_empty: false hide_empty: false
empty_zero: false empty_zero: false
hide_alter_empty: true hide_alter_empty: true
link_to_node: false entity_type: entity_test
entity_type: node entity_field: name
entity_field: nid plugin_id: standard
title:
id: title
table: node_field_data
field: title
plugin_id: node
label: ''
alter:
alter_text: false
make_link: false
absolute: false
trim: false
word_boundary: false
ellipsis: false
strip_tags: false
html: false
hide_empty: false
empty_zero: false
link_to_node: true
entity_type: node
entity_field: title
operations: operations:
id: operations id: operations
table: node table: entity_test
field: operations field: operations
relationship: none relationship: none
group_type: group group_type: group
@ -158,18 +136,7 @@ display:
hide_alter_empty: true hide_alter_empty: true
destination: true destination: true
plugin_id: entity_operations plugin_id: entity_operations
filters: filters: { }
status:
value: true
table: node_field_data
field: status
id: status
plugin_id: boolean
expose:
operator: '0'
group: 1
entity_type: node
entity_field: status
sorts: sorts:
created: created:
id: created id: created