Issue by benjifisher, smustgrave, acbramley, larowlan, xjm, AaronMcHale, catch: Create a redirect for the new Block types path

merge-requests/3282/head^2
Lee Rowlands 2023-02-07 11:00:42 +10:00
parent 4e49b11ac2
commit 7ff6338975
No known key found for this signature in database
GPG Key ID: 2B829A3DF9204DC4
3 changed files with 53 additions and 0 deletions
core/modules/block_content

View File

@ -8,6 +8,19 @@ block_content.add_page:
requirements:
_permission: 'administer blocks'
# @todo Deprecate this route once
# https://www.drupal.org/project/drupal/issues/3159210 is fixed, or remove
# it in Drupal 11.
# @see https://www.drupal.org/node/3320855
entity.block_content_type.collection.bc:
path: '/admin/structure/block/block-content/types'
defaults:
_controller: '\Drupal\block_content\Controller\BlockContentController::blockContentTypeRedirect'
options:
_admin_route: TRUE
requirements:
_permission: 'administer blocks'
block_content.add_form:
path: '/block/add/{block_content_type}'
defaults:

View File

@ -9,6 +9,7 @@ use Drupal\Core\Extension\ThemeHandlerInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
class BlockContentController extends ControllerBase {
@ -128,4 +129,30 @@ class BlockContentController extends ControllerBase {
return $this->t('Add %type custom block', ['%type' => $block_content_type->label()]);
}
/**
* Provides a redirect to the list of custom block types.
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*
* @deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use
* /admin/structure/block-content directly instead of
* /admin/structure/block/block-content/types.
*
* @see https://www.drupal.org/node/3320855
*/
public function blockContentTypeRedirect(): RedirectResponse {
@trigger_error('The path /admin/structure/block/block-content/types is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use /admin/structure/block-content. See https://www.drupal.org/node/3320855.', E_USER_DEPRECATED);
$route = 'entity.block_content_type.collection';
$params = [
'%old_path' => Url::fromRoute("$route.bc")->toString(),
'%new_path' => Url::fromRoute($route)->toString(),
'%change_record' => 'https://www.drupal.org/node/3320855',
];
$warning_message = $this->t('You have been redirected from %old_path. Update links, shortcuts, and bookmarks to use %new_path.', $params);
$this->messenger()->addWarning($warning_message);
$this->getLogger('block_content')->warning('A user was redirected from %old_path to %new_path. This redirect will be removed in a future version of Drupal. Update links, shortcuts, and bookmarks to use %new_path. See %change_record for more information.', $params);
return $this->redirect($route, [], [], 301);
}
}

View File

@ -255,4 +255,17 @@ class BlockContentTypeTest extends BlockContentTestBase {
}
}
/**
* Tests the deprecation message from the old block-type page.
*
* @group legacy
*/
public function testBlockContentTypeRedirect() {
$this->drupalLogin($this->adminUser);
$this->expectDeprecation('The path /admin/structure/block/block-content/types is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use /admin/structure/block-content. See https://www.drupal.org/node/3320855.');
$this->drupalGet('/admin/structure/block/block-content/types');
$base_path = parse_url($this->baseUrl, PHP_URL_PATH) ?? '';
$this->assertSession()->pageTextContains("You have been redirected from $base_path/admin/structure/block/block-content/types. Update links, shortcuts, and bookmarks to use $base_path/admin/structure/block-content.");
}
}