Issue #2838968 by Ginovski, Berdir: BlockContentListBuilder should use RedirectDestinationTrait instead of hardcoding the collection link template

8.3.x
Alex Pott 2017-01-11 14:39:20 +00:00
parent b8d54eea18
commit 0f613741ee
3 changed files with 288 additions and 1 deletions

View File

@ -4,6 +4,7 @@ namespace Drupal\block_content;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Routing\RedirectDestinationTrait;
/**
* Defines a class to build a listing of custom block entities.
@ -12,6 +13,8 @@ use Drupal\Core\Entity\EntityListBuilder;
*/
class BlockContentListBuilder extends EntityListBuilder {
use RedirectDestinationTrait;
/**
* {@inheritdoc}
*/
@ -34,7 +37,7 @@ class BlockContentListBuilder extends EntityListBuilder {
public function getDefaultOperations(EntityInterface $entity) {
$operations = parent::getDefaultOperations($entity);
if (isset($operations['edit'])) {
$operations['edit']['query']['destination'] = $entity->url('collection');
$operations['edit']['query']['destination'] = $this->getRedirectDestination()->get();
}
return $operations;
}

View File

@ -0,0 +1,50 @@
<?php
namespace Drupal\block_content\Tests\Views;
/**
* Tests the redirect destination on block content on entity operations.
*
* @group block_content
*/
class BlockContentRedirectTest extends BlockContentTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = ['test_block_content_redirect_destination'];
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('block', 'block_content', 'views');
/**
* Tests the redirect destination when editing block content.
*/
public function testRedirectDestination() {
$this->drupalLogin($this->drupalCreateUser(array('administer blocks')));
$this->drupalGet('admin/structure/block/block-content');
// Create a custom block.
$this->clickLink('custom block');
$edit = array();
$edit['info[0][value]'] = 'Test redirect destination';
$edit['body[0][value]'] = $this->randomMachineName(16);
$this->drupalPostForm(NULL, $edit, 'Save');
// Check the block content is present in the view redirect destination.
$this->drupalGet('admin/content/redirect_destination');
$this->assertText('Test redirect destination');
// Edit the created block and save.
$this->clickLink('Edit');
$this->drupalPostForm(NULL, [], 'Save');
$this->assertUrl('admin/content/redirect_destination');
}
}

View File

@ -0,0 +1,234 @@
langcode: en
status: true
dependencies:
module:
- block_content
id: test_block_content_redirect_destination
label: 'Redirect destination'
module: views
description: ''
tag: ''
base_table: block_content_field_data
base_field: id
core: 8.x
display:
default:
display_plugin: default
id: default
display_title: Master
position: 0
display_options:
access:
type: none
options: { }
cache:
type: tag
options: { }
query:
type: views_query
options:
disable_sql_rewrite: false
distinct: false
replica: false
query_comment: ''
query_tags: { }
exposed_form:
type: basic
options:
submit_button: Apply
reset_button: false
reset_button_label: Reset
exposed_sorts_label: 'Sort by'
expose_sort_order: true
sort_asc_label: Asc
sort_desc_label: Desc
pager:
type: mini
options:
items_per_page: 10
offset: 0
id: 0
total_pages: null
expose:
items_per_page: false
items_per_page_label: 'Items per page'
items_per_page_options: '5, 10, 25, 50'
items_per_page_options_all: false
items_per_page_options_all_label: '- All -'
offset: false
offset_label: Offset
tags:
previous:
next:
style:
type: table
options:
grouping: { }
row_class: ''
default_row_class: true
override: true
sticky: false
caption: ''
summary: ''
description: ''
columns:
info: info
info:
info:
sortable: false
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
default: '-1'
empty_table: false
row:
type: 'entity:block_content'
fields:
info:
table: block_content_field_data
field: info
id: info
entity_type: null
entity_field: info
plugin_id: field
relationship: none
group_type: group
admin_label: ''
label: ''
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
click_sort_column: value
type: string
settings: { }
group_column: value
group_columns: { }
group_rows: true
delta_limit: 0
delta_offset: 0
delta_reversed: false
delta_first_last: false
multi_type: separator
separator: ', '
field_api_classes: false
operations:
id: operations
table: block_content
field: operations
relationship: none
group_type: group
admin_label: ''
label: 'Operations links'
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
destination: true
entity_type: block_content
plugin_id: entity_operations
filters: { }
sorts: { }
title: 'Redirect destination'
header: { }
footer: { }
empty: { }
relationships: { }
arguments: { }
display_extenders: { }
cache_metadata:
max-age: 0
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url.query_args
tags: { }
page_1:
display_plugin: page
id: page_1
display_title: Page
position: 1
display_options:
display_extenders: { }
path: /admin/content/redirect_destination
cache_metadata:
max-age: 0
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url.query_args
tags: { }