Skip to content
Snippets Groups Projects
Verified Commit 0fc730be authored by Alex Pott's avatar Alex Pott
Browse files

Issue #1956134 by smustgrave, dawehner, larowlan, jibran, jbloomfield,...

Issue #1956134 by smustgrave, dawehner, larowlan, jibran, jbloomfield, lokapujya, Oscaner, elachlan, mgifford, olli, srilakshmier, Manuel Garcia, Nitin shrivastava, afeijo, alexpott, jgeryk, garphy, grisendo, jessebeach, xjm, joachim, tim.plunkett, andypost, Wim Leers, EclipseGc, damiankloip, benjy, klonos: Provide helpful editing links on "admin/structure/block" for deriver blocks (menu, views, block content, etc.)

(cherry picked from commit f8a34d34)
parent 4d0abee5
Branches
Tags
44 merge requests!10663Issue #3495778: Update phpdoc in FileSaveHtaccessLoggingTest,!10451Issue #3472458 by watergate, smustgrave: CKEditor 5 show blocks label is not translated,!103032838547 Fix punctuation rules for inline label suffix colon with CSS only,!10150Issue #3467294 by quietone, nod_, smustgrave, catch, longwave: Change string...,!10130Resolve #3480321 "Second level menu",!9936Issue #3483087: Check the module:// prefix in the translation server path and replace it with the actual module path,!9933Issue #3394728 by ankondrat4: Undefined array key "#prefix" and deprecated function: explode() in Drupal\file\Element\ManagedFile::uploadAjaxCallback(),!9914Issue #3451136 by quietone, gapple, ghost of drupal past: Improve...,!9882Draft: Issue #3481777 In bulk_form ensure the triggering element is the bulk_form button,!9839Issue #3445469 by pooja_sharma, smustgrave: Add additional test coverage for...,!9815Issue #3480025: There is no way to remove entity cache items,!9757Issue #3478869 Add "All" or overview links to parent links,!9752Issue #3439910 by pooja_sharma, vensires: Fix Toolbar tests that rely on UID1's super user behavior,!9749Issue #3439910 by pooja_sharma, vensires: Fix Toolbar tests that rely on UID1's super user behavior,!9678Issue #3465132 by catch, Spokje, nod_: Show test run time by class in run-tests.sh output,!9578Issue #3304746 by scott_euser, casey, smustgrave: BigPipe cannot handle (GET)...,!9449Issue #3344041: Allow textarea widgets to be used for text (formatted) fields,!8945🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥...,!8893Resolve #3444391 "Navigation center sm logo",!8772Issue #3445909 by seanB, smustgrave, alexpott, catch: Add static caching to...,!8723Make dblog entities,!8708Filter out disabled display extenders on save,!8691#3459116 - Update Manager Settings: Validate same email address added multiple times,!8665Issue #3449743 by catch: Try to optimize test ordering when run-tests.sh is...,!8598Draft: Issue #3458215: Migrate Toolbar button to SDC,!8572Reorder checkboxes on "Development settings" page,!8538Issue #3457009: Fixing xxception message thrown.,!8516Update file EntityReferenceItem.php,!8505Issue #3456528: _node_mass_update_batch_process fails during user cancel when revision is deleted,!8494Issue #3452511: Convert ProviderRepositoryTest to a kernel test,!8482Resolve #3456202 "Phpunit tests support",!8463Prevent re-install if site already exists,!8392Issue #3454196: Filter placeholders without arguments are not replaced when HTML corrector filter applied afterwards,!8384Issue #3446403 by edutrul, jnicola, mradcliffe: [name]: This field is missing for example recipe,!8304Issue #2990766 by camilledavis, Gauravvvv, mgifford: Location of "Skip to...,!8178Issue #3439909 by SolimanHarkas, vensires: Fix Taxonomy tests that rely on...,!8138Remove inactive initiatives from maintainers list,!8078Issue #3439909 by SolimanHarkas, vensires: Fix Taxonomy tests that rely on...,!8065Adds Default Content and Recipes Subsystems,!8047Issue #3439909 by SolimanHarkas, vensires: Fix Taxonomy tests that rely on...,!7974Issue #3439909 by SolimanHarkas, vensires: Fix Taxonomy tests that rely on...,!7972Issue #3439909 by SolimanHarkas, vensires: Fix Taxonomy tests that rely on...,!7926Issue #3439909 by SolimanHarkas, vensires: Fix Taxonomy tests that rely on...,!5829Porting tabledrag CSS refactor from D10 branch
Pipeline #165258 passed
......@@ -5,7 +5,9 @@
* Allows the creation of content blocks through the user interface.
*/
use Drupal\block\BlockInterface;
use Drupal\block_content\BlockContentInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Url;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\field\Entity\FieldConfig;
......@@ -214,3 +216,28 @@ function block_content_theme_suggestions_block_alter(array &$suggestions, array
return $suggestions;
}
/**
* Implements hook_entity_operation().
*/
function block_content_entity_operation(EntityInterface $entity): array {
$operations = [];
if ($entity instanceof BlockInterface) {
$plugin = $entity->getPlugin();
if ($plugin->getBaseId() === 'block_content') {
$custom_block = \Drupal::entityTypeManager()->getStorage('block_content')->loadByProperties([
'uuid' => $plugin->getDerivativeId(),
]);
$custom_block = reset($custom_block);
if ($custom_block && $custom_block->access('update')) {
$operations['block-edit'] = [
'title' => t('Edit block'),
'url' => $custom_block->toUrl('edit-form')->setOptions([]),
'weight' => 50,
];
}
}
}
return $operations;
}
<?php
declare(strict_types=1);
namespace Drupal\Tests\block_content\Kernel;
use Drupal\block\Entity\Block;
use Drupal\block_content\Entity\BlockContent;
use Drupal\block_content\Entity\BlockContentType;
use Drupal\Component\Plugin\PluginBase;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\user\Traits\UserCreationTrait;
/**
* Tests the block content.
*
* @group block_content
*/
class BlockContentTest extends KernelTestBase {
use UserCreationTrait;
use StringTranslationTrait;
/**
* {@inheritdoc}
*/
protected static $modules = ['block', 'block_content', 'system', 'user'];
/**
* {@inheritdoc}
*/
public function setUp(): void {
parent::setUp();
$this->installEntitySchema('user');
$this->installEntitySchema('block_content');
}
/**
* Tests the editing links for BlockContentBlock.
*/
public function testOperationLinks(): void {
// Create a block content type.
BlockContentType::create([
'id' => 'spiffy',
'label' => 'Mucho spiffy',
'description' => "Provides a block type that increases your site's spiffiness by up to 11%",
])->save();
// And a block content entity.
$block_content = BlockContent::create([
'info' => 'Spiffy prototype',
'type' => 'spiffy',
]);
$block_content->save();
$block = Block::create([
'plugin' => 'block_content' . PluginBase::DERIVATIVE_SEPARATOR . $block_content->uuid(),
'region' => 'content',
'id' => 'machine_name',
'theme' => 'stark',
]);
// The anonymous user doesn't have the "administer block" permission.
$this->assertEmpty(block_content_entity_operation($block));
$this->setUpCurrentUser(['uid' => 1], ['edit any spiffy block content', 'administer blocks']);
// The admin user does have the "administer block" permission.
$this->assertEquals([
'block-edit' => [
'title' => $this->t('Edit block'),
'url' => $block_content->toUrl('edit-form')->setOptions([]),
'weight' => 50,
],
], block_content_entity_operation($block));
}
}
......@@ -8,6 +8,8 @@
* used for navigation.
*/
use Drupal\block\BlockInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Url;
use Drupal\Core\Breadcrumb\Breadcrumb;
use Drupal\Core\Cache\CacheableMetadata;
......@@ -466,3 +468,25 @@ function menu_ui_theme(): array {
],
];
}
/**
* Implements hook_entity_operation().
*/
function menu_ui_entity_operation(EntityInterface $entity): array {
$operations = [];
if ($entity instanceof BlockInterface) {
$plugin = $entity->getPlugin();
if ($plugin->getBaseId() === 'system_menu_block') {
$menu = Menu::load($plugin->getDerivativeId());
if ($menu && $menu->access('edit')) {
$operations['menu-edit'] = [
'title' => t('Edit menu'),
'url' => $menu->toUrl('edit-form'),
'weight' => 50,
];
}
}
}
return $operations;
}
<?php
declare(strict_types=1);
namespace Drupal\Tests\menu_ui\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\system\Entity\Menu;
use Drupal\block\Entity\Block;
use Drupal\system\MenuInterface;
use Drupal\Tests\user\Traits\UserCreationTrait;
/**
* Tests SystemMenuBlock.
*
* @group menu_ui
*/
class MenuBlockTest extends KernelTestBase {
use UserCreationTrait;
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'system',
'block',
'menu_ui',
'user',
];
/**
* The menu for testing.
*
* @var \Drupal\system\MenuInterface
*/
protected MenuInterface $menu;
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->installEntitySchema('user');
$this->setUpCurrentUser([], ['administer menu']);
// Add a new custom menu.
$menu_name = 'mock';
$label = $this->randomMachineName(16);
$this->menu = Menu::create([
'id' => $menu_name,
'label' => $label,
'description' => 'Description text',
]);
$this->menu->save();
}
/**
* Tests the editing links for SystemMenuBlock.
*/
public function testOperationLinks(): void {
$block = Block::create([
'plugin' => 'system_menu_block:' . $this->menu->id(),
'region' => 'footer',
'id' => 'machine_name',
'theme' => 'stark',
]);
// Test when user does have "administer menu" permission.
$this->assertEquals([
'menu-edit' => [
'title' => 'Edit menu',
'url' => $this->menu->toUrl('edit-form'),
'weight' => 50,
],
], menu_ui_entity_operation($block));
$this->setUpCurrentUser();
// Test when user doesn't have "administer menu" permission.
$this->assertEmpty(menu_ui_entity_operation($block));
}
}
<?php
declare(strict_types=1);
namespace Drupal\Tests\views_ui\Kernel;
use Drupal\Core\Url;
use Drupal\block\Entity\Block;
use Drupal\Tests\user\Traits\UserCreationTrait;
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
use Drupal\views\Tests\ViewTestData;
/**
* Tests ViewsBlock.
*
* @group views_ui
*/
class ViewsBlockTest extends ViewsKernelTestBase {
use UserCreationTrait;
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'system',
'block',
'block_test_views',
'views_ui',
'user',
];
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = ['test_view_block'];
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE): void {
parent::setUp();
ViewTestData::createTestViews(static::class, ['block_test_views']);
}
/**
* Tests the editing links for ViewsBlockBase.
*/
public function testOperationLinks(): void {
$this->setUpCurrentUser(['uid' => 0]);
$block = Block::create([
'plugin' => 'views_block:test_view_block-block_1',
'region' => 'content',
'id' => 'machine_name',
'theme' => 'stark',
]);
// The anonymous user doesn't have the "administer block" permission.
$this->assertEmpty(views_ui_entity_operation($block));
$this->setUpCurrentUser(['uid' => 1], ['administer views']);
// The admin user does have the "administer block" permission.
$this->assertEquals([
'view-edit' => [
'title' => 'Edit view',
'url' => Url::fromRoute('entity.view.edit_display_form', [
'view' => 'test_view_block',
'display_id' => 'block_1',
]),
'weight' => 50,
],
], views_ui_entity_operation($block));
}
}
......@@ -5,9 +5,12 @@
* Provide structure for the administrative interface to Views.
*/
use Drupal\block\BlockInterface;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Drupal\views\Entity\View;
use Drupal\views\ViewExecutable;
use Drupal\views\Analyzer;
......@@ -334,3 +337,31 @@ function views_ui_views_analyze(ViewExecutable $view) {
return $ret;
}
/**
* Implements hook_entity_operation().
*/
function views_ui_entity_operation(EntityInterface $entity): array {
$operations = [];
if ($entity instanceof BlockInterface) {
$plugin = $entity->getPlugin();
if ($plugin->getBaseId() === 'views_block') {
$view_id_parts = explode('-', $plugin->getDerivativeId());
$view_id = $view_id_parts[0] ?? '';
$display_id = $view_id_parts[1] ?? '';
$view = View::load($view_id);
if ($view && $view->access('edit')) {
$operations['view-edit'] = [
'title' => t('Edit view'),
'url' => Url::fromRoute('entity.view.edit_display_form', [
'view' => $view_id,
'display_id' => $display_id,
]),
'weight' => 50,
];
}
}
}
return $operations;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment