Skip to content
Snippets Groups Projects
Verified Commit 1b83f796 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)
(cherry picked from commit 98887e87)
parent 12097985
No related branches found
No related tags found
18 merge requests!10602Issue #3438769 by vinmayiswamy, antonnavi, michelle, amateescu: Sub workspace does not clear,!10301Issue #3469309 by mstrelan, smustgrave, moshe weitzman: Use one-time login...,!10187Issue #3487488 by dakwamine: ExtensionMimeTypeGuesser::guessMimeType must support file names with "0" (zero) like foo.0.zip,!9929Issue #3445469 by pooja_sharma, smustgrave: Add additional test coverage for...,!9787Resolve issue 3479427 - bootstrap barrio issue under Windows,!9742Issue #3463908 by catch, quietone: Split OptionsFieldUiTest into two,!9526Issue #3458177 by mondrake, catch, quietone, godotislate, longwave, larowlan,...,!8949Backport .gitlabci.yml changes.,!8738Issue #3424162 by camilledavis, dineshkumarbollu, smustgrave: Claro...,!8704Make greek characters available in ckeditor5,!8597Draft: Issue #3442259 by catch, quietone, dww: Reduce time of Migrate Upgrade tests...,!8533Issue #3446962 by kim.pepper: Remove incorrectly added...,!8517Issue #3443748 by NexusNovaz, smustgrave: Testcase creates false positive,!7930Resolve #3427374 "Taxonomytid viewsargumentdefault plugin",!7445Issue #3440169: When using drupalGet(), provide an associative array for $headers,!6502Draft: Resolve #2938524 "Plach testing issue",!38582585169-10.1.x,!3226Issue #2987537: Custom menu link entity type should not declare "bundle" entity key
Pipeline #165347 passed with warnings
Pipeline: drupal

#165389

    Pipeline: drupal

    #165383

      Pipeline: drupal

      #165381

        +6
        ...@@ -5,7 +5,9 @@ ...@@ -5,7 +5,9 @@
        * Allows the creation of content blocks through the user interface. * Allows the creation of content blocks through the user interface.
        */ */
        use Drupal\block\BlockInterface;
        use Drupal\block_content\BlockContentInterface; use Drupal\block_content\BlockContentInterface;
        use Drupal\Core\Entity\EntityInterface;
        use Drupal\Core\Url; use Drupal\Core\Url;
        use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Routing\RouteMatchInterface;
        use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldConfig;
        ...@@ -214,3 +216,28 @@ function block_content_theme_suggestions_block_alter(array &$suggestions, array ...@@ -214,3 +216,28 @@ function block_content_theme_suggestions_block_alter(array &$suggestions, array
        return $suggestions; 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 @@ ...@@ -8,6 +8,8 @@
        * used for navigation. * used for navigation.
        */ */
        use Drupal\block\BlockInterface;
        use Drupal\Core\Entity\EntityInterface;
        use Drupal\Core\Url; use Drupal\Core\Url;
        use Drupal\Core\Breadcrumb\Breadcrumb; use Drupal\Core\Breadcrumb\Breadcrumb;
        use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Cache\CacheableMetadata;
        ...@@ -466,3 +468,25 @@ function menu_ui_theme(): array { ...@@ -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,10 +5,13 @@ ...@@ -5,10 +5,13 @@
        * Provide structure for the administrative interface to Views. * Provide structure for the administrative interface to Views.
        */ */
        use Drupal\block\BlockInterface;
        use Drupal\Component\Utility\Unicode; use Drupal\Component\Utility\Unicode;
        use Drupal\Component\Utility\Xss; use Drupal\Component\Utility\Xss;
        use Drupal\Core\Entity\EntityInterface;
        use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Routing\RouteMatchInterface;
        use Drupal\Core\Url; use Drupal\Core\Url;
        use Drupal\views\Entity\View;
        use Drupal\views\ViewExecutable; use Drupal\views\ViewExecutable;
        use Drupal\views\Analyzer; use Drupal\views\Analyzer;
        ...@@ -350,3 +353,31 @@ function views_ui_truncate($string, $length) { ...@@ -350,3 +353,31 @@ function views_ui_truncate($string, $length) {
        @trigger_error('views_ui_truncate() is deprecated in drupal:10.3.0 and is removed from drupal:12.0.0. Use \Drupal\Component\Utility\Unicode::truncate(). See https://www.drupal.org/node/3408283', E_USER_DEPRECATED); @trigger_error('views_ui_truncate() is deprecated in drupal:10.3.0 and is removed from drupal:12.0.0. Use \Drupal\Component\Utility\Unicode::truncate(). See https://www.drupal.org/node/3408283', E_USER_DEPRECATED);
        return Unicode::truncate($string, $length, FALSE, TRUE); return Unicode::truncate($string, $length, FALSE, TRUE);
        } }
        /**
        * 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.
        Finish editing this message first!
        Please register or to comment