Commit aa08b8c5 authored by webchick's avatar webchick
Browse files

Issue #2905098 by tedbow, Jo Fitzgerald, Wim Leers, MerryHamster, Yogesh...

Issue #2905098 by tedbow, Jo Fitzgerald, Wim Leers, MerryHamster, Yogesh Pawar, rajeshwari10, larowlan, xjm: Change block entity form handler from 'off_canvas' to 'settings_tray'
parent 420400cf
settings_tray.block_configure:
title: 'Quick edit'
route_name: 'entity.block.off_canvas_form'
route_name: 'entity.block.settings_tray_form'
group: 'block'
options:
attributes:
......
......@@ -7,10 +7,9 @@
use Drupal\Core\Asset\AttachedAssetsInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Drupal\settings_tray\Block\BlockEntityOffCanvasForm;
use Drupal\block\entity\Block;
use Drupal\block\BlockInterface;
use Drupal\settings_tray\Block\BlockEntitySettingTrayForm;
/**
* Implements hook_help().
......@@ -96,8 +95,8 @@ function settings_tray_block_view_alter(array &$build) {
function settings_tray_entity_type_build(array &$entity_types) {
/* @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
$entity_types['block']
->setFormClass('off_canvas', BlockEntityOffCanvasForm::class)
->setLinkTemplate('off_canvas-form', '/admin/structure/block/manage/{block}/off-canvas');
->setFormClass('settings_tray', BlockEntitySettingTrayForm::class)
->setLinkTemplate('settings_tray-form', '/admin/structure/block/manage/{block}/settings-tray');
}
/**
......
entity.block.off_canvas_form:
path: '/admin/structure/block/manage/{block}/off-canvas'
entity.block.settings_tray_form:
path: '/admin/structure/block/manage/{block}/settings-tray'
defaults:
_entity_form: 'block.off_canvas'
_title_callback: '\Drupal\settings_tray\Block\BlockEntityOffCanvasForm::title'
_entity_form: 'block.settings_tray'
_title_callback: '\Drupal\settings_tray\Block\BlockEntitySettingTrayForm::title'
requirements:
_permission: 'administer blocks'
_access_block_plugin_has_settings_tray_form: 'TRUE'
_access_block_has_overrides_settings_tray_form: 'TRUE'
# Deprecated.
# @see entity.block.settings_tray_form
# @see \Drupal\settings_tray\RouteProcessor\BlockEntityOffCanvasFormRouteProcessorBC
# @todo Remove in Drupal 9.0.0.
entity.block.off_canvas_form:
path: ''
......@@ -7,3 +7,12 @@ services:
class: Drupal\settings_tray\Access\BlockPluginHasSettingsTrayFormAccessCheck
tags:
- { name: access_check, applies_to: _access_block_plugin_has_settings_tray_form }
# BC layers.
# @todo Remove in Drupal 9.0.0.
settings_tray.route_processor_off_canvas_form_bc:
class: \Drupal\settings_tray\RouteProcessor\BlockEntityOffCanvasFormRouteProcessorBC
arguments: ['@router.route_provider']
public: false
tags:
- { name: route_processor_outbound }
......@@ -21,7 +21,7 @@
*
* @internal
*/
class BlockEntityOffCanvasForm extends BlockForm {
class BlockEntitySettingTrayForm extends BlockForm {
/**
* Provides a title callback to get the block's admin label.
......
<?php
namespace Drupal\settings_tray\RouteProcessor;
use Drupal\Core\Render\BubbleableMetadata;
use Drupal\Core\RouteProcessor\OutboundRouteProcessorInterface;
use Drupal\Core\Routing\RouteProviderInterface;
use Symfony\Component\Routing\Route;
/**
* Processes the Block entity off-canvas form BC route.
*
* @internal
*/
class BlockEntityOffCanvasFormRouteProcessorBC implements OutboundRouteProcessorInterface {
/**
* The route provider.
*
* @var \Drupal\Core\Routing\RouteProviderInterface
*/
protected $routeProvider;
/**
* Constructs a BlockEntityOffCanvasFormRouteProcessorBC object.
*
* @param \Drupal\Core\Routing\RouteProviderInterface $route_provider
* The route provider.
*/
public function __construct(RouteProviderInterface $route_provider) {
$this->routeProvider = $route_provider;
}
/**
* {@inheritdoc}
*/
public function processOutbound($route_name, Route $route, array &$parameters, BubbleableMetadata $bubbleable_metadata = NULL) {
if ($route_name === 'entity.block.off_canvas_form') {
$redirected_route_name = 'entity.block.settings_tray_form';
@trigger_error(sprintf("The '%s' route is deprecated since version 8.5.x and will be removed in 9.0.0. Use the '%s' route instead.", $route_name, $redirected_route_name), E_USER_DEPRECATED);
static::overwriteRoute($route, $this->routeProvider->getRouteByName($redirected_route_name));
}
}
/**
* Overwrites one route's metadata with the other's.
*
* @param \Symfony\Component\Routing\Route $target_route
* The route whose metadata to overwrite.
* @param \Symfony\Component\Routing\Route $source_route
* The route whose metadata to read from.
*
* @see \Symfony\Component\Routing\Route
*/
protected static function overwriteRoute(Route $target_route, Route $source_route) {
$target_route->setPath($source_route->getPath());
$target_route->setDefaults($source_route->getDefaults());
$target_route->setRequirements($source_route->getRequirements());
$target_route->setOptions($source_route->getOptions());
$target_route->setHost($source_route->getHost());
$target_route->setSchemes($source_route->getSchemes());
$target_route->setMethods($source_route->getMethods());
}
}
<?php
namespace Drupal\Tests\settings_tray\Functional;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
/**
* Tests Settings Tray BC routes.
*
* @group settings_tray
* @group legacy
*/
class BcRoutesTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
public static $modules = [
'settings_tray',
];
/**
* @expectedDeprecation The 'entity.block.off_canvas_form' route is deprecated since version 8.5.x and will be removed in 9.0.0. Use the 'entity.block.settings_tray_form' route instead.
*/
public function testOffCanvasFormRouteBc() {
$block = $this->placeBlock('system_powered_by_block');
$url_for_current_route = Url::fromRoute('entity.block.settings_tray_form', ['block' => $block->id()])->toString(TRUE)->getGeneratedUrl();
$url_for_bc_route = Url::fromRoute('entity.block.off_canvas_form', ['block' => $block->id()])->toString(TRUE)->getGeneratedUrl();
$this->assertSame($url_for_current_route, $url_for_bc_route);
}
}
......@@ -84,7 +84,7 @@ public function testBlocks($theme, $block_plugin, $new_page_text, $element_selec
$link = $page->find('css', "$block_selector .contextual-links li a");
$this->assertEquals('Quick edit', $link->getText(), "'Quick edit' is the first contextual link for the block.");
$this->assertContains("/admin/structure/block/manage/$block_id/off-canvas?destination=user/2", $link->getAttribute('href'));
$this->assertContains("/admin/structure/block/manage/$block_id/settings-tray?destination=user/2", $link->getAttribute('href'));
if (isset($toolbar_item)) {
// Check that you can open a toolbar tray and it will be closed after
......@@ -525,7 +525,7 @@ public function testCustomBlockLinks() {
$href = array_search('Quick edit', $link_labels);
$this->assertEquals('', $href);
$href = array_search('Quick edit settings', $link_labels);
$this->assertTrue(strstr($href, '/admin/structure/block/manage/custom/off-canvas?destination=user/2') !== FALSE);
$this->assertTrue(strstr($href, '/admin/structure/block/manage/custom/settings-tray?destination=user/2') !== FALSE);
}
/**
......
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