diff --git a/core/modules/outside_in/outside_in.module b/core/modules/outside_in/outside_in.module index 298b994..dfba07e 100644 --- a/core/modules/outside_in/outside_in.module +++ b/core/modules/outside_in/outside_in.module @@ -39,6 +39,10 @@ function outside_in_contextual_links_view_alter(&$element, $items) { 'data-dialog-type' => 'dialog', 'data-dialog-renderer' => 'offcanvas', ]; + // If this is content block change title to avoid duplicate "Quick Edit". + if (isset($element['#links']['block-contentblock-edit'])) { + $element['#links']['outside-inblock-configure']['title'] .= ' settings'; + } $element['#attached']['library'][] = 'outside_in/drupal.off_canvas'; } diff --git a/core/modules/outside_in/tests/src/FunctionalJavascript/OutsideInBlockFormTest.php b/core/modules/outside_in/tests/src/FunctionalJavascript/OutsideInBlockFormTest.php index dd79fc2..7044e9a 100644 --- a/core/modules/outside_in/tests/src/FunctionalJavascript/OutsideInBlockFormTest.php +++ b/core/modules/outside_in/tests/src/FunctionalJavascript/OutsideInBlockFormTest.php @@ -2,6 +2,9 @@ namespace Drupal\Tests\outside_in\FunctionalJavascript; +use Drupal\block_content\Entity\BlockContent; +use Drupal\block_content\Entity\BlockContentType; + /** * Testing opening and saving block forms in the off-canvas tray. * @@ -22,6 +25,7 @@ class OutsideInBlockFormTest extends OutsideInJavascriptTestBase { 'outside_in', 'quickedit', 'search', + 'block_content', ]; /** @@ -29,6 +33,10 @@ class OutsideInBlockFormTest extends OutsideInJavascriptTestBase { */ protected function setUp() { parent::setUp(); + + $this->createBlockContentType('basic', TRUE); + $block_content = $this->createBlockContent('Custom Block', 'basic', TRUE); + // @todo Ensure that this test class works against bartik and stark: // https://www.drupal.org/node/2784881. $this->enableTheme('bartik'); @@ -42,6 +50,7 @@ protected function setUp() { ]); $this->drupalLogin($user); + $this->placeBlock('block_content:' . $block_content->uuid(), ['id' => 'custom']); $this->placeBlock('system_powered_by_block', ['id' => 'powered']); $this->placeBlock('system_branding_block', ['id' => 'branding']); $this->placeBlock('search_form_block', ['id' => 'search']); @@ -116,6 +125,20 @@ public function testBlocks() { // Exit edit mode. $this->toggleEditingMode(); } + + // Check custom block labels. + // "Quick edit" is quickedit.module link. + // "Quick edit settings" is outside_in.module link. + $links = $page->findAll('css', "#block-custom .contextual-links li a"); + $link_labels = []; + /** @var \Behat\Mink\Element\NodeElement $link */ + foreach ($links as $link) { + $link_labels[$link->getAttribute('href')] = $link->getText(); + } + $href = array_search('Quick edit', $link_labels); + self::assertEquals('', $href); + $href = array_search('Quick edit settings', $link_labels); + self::assertEquals('/admin/structure/block/manage/custom/offcanvas?destination=user/2', $href); } /** @@ -155,4 +178,60 @@ protected function openBlockForm($block_selector) { $this->waitForOffCanvasToOpen(); $this->assertOffCanvasBlockFormIsValid(); } + + /** + * Creates a custom block. + * + * @param bool|string $title + * (optional) Title of block. When no value is given uses a random name. + * Defaults to FALSE. + * @param string $bundle + * (optional) Bundle name. Defaults to 'basic'. + * @param bool $save + * (optional) Whether to save the block. Defaults to TRUE. + * + * @return \Drupal\block_content\Entity\BlockContent + * Created custom block. + */ + protected function createBlockContent($title = FALSE, $bundle = 'basic', $save = TRUE) { + $title = $title ?: $this->randomMachineName(); + $block_content = BlockContent::create([ + 'info' => $title, + 'type' => $bundle, + 'langcode' => 'en', + 'body' => [ + 'value' => 'The name "llama" was adopted by European settlers from native Peruvians.', + 'format' => 'plain_text', + ], + ]); + if ($block_content && $save === TRUE) { + $block_content->save(); + } + return $block_content; + } + + /** + * Creates a custom block type (bundle). + * + * @param string $label + * The block type label. + * @param bool $create_body + * Whether or not to create the body field. + * + * @return \Drupal\block_content\Entity\BlockContentType + * Created custom block type. + */ + protected function createBlockContentType($label, $create_body = FALSE) { + $bundle = BlockContentType::create([ + 'id' => $label, + 'label' => $label, + 'revision' => FALSE, + ]); + $bundle->save(); + if ($create_body) { + block_content_add_body_field($bundle->id()); + } + return $bundle; + } + }