Commit b1e477ec authored by larowlan's avatar larowlan

Issue #2938900 by David_Rothstein, navneet0693, JayKandari: Replace...

Issue #2938900 by David_Rothstein, navneet0693, JayKandari: Replace profile-defined blocks with custom blocks to fix a variety of problems
parent aa3dcb5b
langcode: en
status: true
dependencies: { }
id: disclaimer_block
label: 'Disclaimer block'
revision: 0
description: 'A disclaimer block contains disclaimer and copyright text.'
langcode: en
status: true
dependencies: { }
id: footer_promo_block
label: 'Footer promo block'
revision: 0
description: 'A footer promo block contains a title, promo text, and a "find out more" link.'
langcode: en
status: true
dependencies:
config:
- block_content.type.disclaimer_block
- field.field.block_content.disclaimer_block.field_copyright
- field.field.block_content.disclaimer_block.field_disclaimer
module:
- text
id: block_content.disclaimer_block.default
targetEntityType: block_content
bundle: disclaimer_block
mode: default
content:
field_copyright:
weight: 28
settings:
rows: 5
placeholder: ''
third_party_settings: { }
type: text_textarea
region: content
field_disclaimer:
weight: 27
settings:
rows: 5
placeholder: ''
third_party_settings: { }
type: text_textarea
region: content
info:
type: string_textfield
weight: -5
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
hidden: { }
langcode: en
status: true
dependencies:
config:
- block_content.type.footer_promo_block
- field.field.block_content.footer_promo_block.field_content_link
- field.field.block_content.footer_promo_block.field_summary
- field.field.block_content.footer_promo_block.field_title
module:
- link
id: block_content.footer_promo_block.default
targetEntityType: block_content
bundle: footer_promo_block
mode: default
content:
field_content_link:
weight: 3
settings:
placeholder_url: ''
placeholder_title: ''
third_party_settings: { }
type: link_default
region: content
field_summary:
weight: 2
settings:
rows: 5
placeholder: ''
third_party_settings: { }
type: string_textarea
region: content
field_title:
weight: 1
settings:
size: 60
placeholder: ''
third_party_settings: { }
type: string_textfield
region: content
info:
type: string_textfield
weight: 0
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
hidden: { }
langcode: en
status: true
dependencies:
config:
- block_content.type.disclaimer_block
- field.field.block_content.disclaimer_block.field_copyright
- field.field.block_content.disclaimer_block.field_disclaimer
module:
- text
id: block_content.disclaimer_block.default
targetEntityType: block_content
bundle: disclaimer_block
mode: default
content:
field_copyright:
weight: 2
label: hidden
settings: { }
third_party_settings: { }
type: text_default
region: content
field_disclaimer:
weight: 1
label: hidden
settings: { }
third_party_settings: { }
type: text_default
region: content
hidden: { }
langcode: en
status: true
dependencies:
config:
- block_content.type.footer_promo_block
- field.field.block_content.footer_promo_block.field_content_link
- field.field.block_content.footer_promo_block.field_summary
- field.field.block_content.footer_promo_block.field_title
module:
- link
id: block_content.footer_promo_block.default
targetEntityType: block_content
bundle: footer_promo_block
mode: default
content:
field_content_link:
weight: 2
label: hidden
settings:
trim_length: 80
url_only: false
url_plain: false
rel: ''
target: ''
third_party_settings: { }
type: link
region: content
field_summary:
weight: 1
label: hidden
settings: { }
third_party_settings: { }
type: basic_string
region: content
field_title:
weight: 0
label: hidden
settings:
link_to_entity: false
third_party_settings: { }
type: string
region: content
hidden: { }
langcode: en
status: true
dependencies:
config:
- block_content.type.disclaimer_block
- field.storage.block_content.field_copyright
module:
- text
id: block_content.disclaimer_block.field_copyright
field_name: field_copyright
entity_type: block_content
bundle: disclaimer_block
label: Copyright
description: ''
required: false
translatable: true
default_value: { }
default_value_callback: ''
settings: { }
field_type: text_long
langcode: en
status: true
dependencies:
config:
- block_content.type.disclaimer_block
- field.storage.block_content.field_disclaimer
module:
- text
id: block_content.disclaimer_block.field_disclaimer
field_name: field_disclaimer
entity_type: block_content
bundle: disclaimer_block
label: Disclaimer
description: ''
required: false
translatable: true
default_value: { }
default_value_callback: ''
settings: { }
field_type: text_long
langcode: en
status: true
dependencies:
config:
- block_content.type.footer_promo_block
- field.storage.block_content.field_content_link
module:
- link
id: block_content.footer_promo_block.field_content_link
field_name: field_content_link
entity_type: block_content
bundle: footer_promo_block
label: 'Find out more link'
description: ''
required: false
translatable: true
default_value: { }
default_value_callback: ''
settings:
link_type: 17
title: 2
field_type: link
langcode: en
status: true
dependencies:
config:
- block_content.type.footer_promo_block
- field.storage.block_content.field_summary
id: block_content.footer_promo_block.field_summary
field_name: field_summary
entity_type: block_content
bundle: footer_promo_block
label: 'Promo text'
description: ''
required: false
translatable: true
default_value: { }
default_value_callback: ''
settings: { }
field_type: string_long
langcode: en
status: true
dependencies:
config:
- block_content.type.footer_promo_block
- field.storage.block_content.field_title
id: block_content.footer_promo_block.field_title
field_name: field_title
entity_type: block_content
bundle: footer_promo_block
label: 'Promo title'
description: ''
required: false
translatable: true
default_value: { }
default_value_callback: ''
settings: { }
field_type: string
langcode: en
status: true
dependencies:
module:
- block_content
- text
id: block_content.field_copyright
field_name: field_copyright
entity_type: block_content
type: text_long
settings: { }
module: text
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
langcode: en
status: true
dependencies:
module:
- block_content
- text
id: block_content.field_disclaimer
field_name: field_disclaimer
entity_type: block_content
type: text_long
settings: { }
module: text
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
langcode: en
status: true
dependencies:
content:
- 'block_content:disclaimer_block:9b4dcd67-99f3-48d0-93c9-2c46648b29de'
enforced:
module:
- demo_umami_content
module:
- demo_umami
- block_content
theme:
- umami
id: umami_disclaimer
......@@ -10,16 +15,13 @@ theme: umami
region: bottom
weight: 10
provider: null
plugin: umami_disclaimer
plugin: 'block_content:9b4dcd67-99f3-48d0-93c9-2c46648b29de'
settings:
id: umami_disclaimer
id: 'block_content:9b4dcd67-99f3-48d0-93c9-2c46648b29de'
label: 'Umami disclaimer'
provider: demo_umami
provider: block_content
label_display: '0'
umami_disclaimer:
value: '<strong>Umami Magazine & Umami Publications</strong> is a fictional magazine and publisher for illustrative purposes only.'
format: basic_html
umami_copyright:
value: '&copy; 2018 Terms & Conditions'
format: basic_html
status: true
info: ''
view_mode: full
visibility: { }
langcode: en
status: true
dependencies:
content:
- 'block_content:footer_promo_block:924ab293-8f5f-45a1-9c7f-2423ae61a241'
enforced:
module:
- demo_umami_content
module:
- demo_umami
- block_content
theme:
- umami
id: umami_footer_promo
......@@ -10,14 +15,13 @@ theme: umami
region: footer
weight: -1
provider: null
plugin: umami_footer_promo
plugin: 'block_content:924ab293-8f5f-45a1-9c7f-2423ae61a241'
settings:
id: umami_footer_promo
label: 'Umami Footer promo'
provider: demo_umami
id: 'block_content:924ab293-8f5f-45a1-9c7f-2423ae61a241'
label: 'Umami footer promo'
provider: block_content
label_display: '0'
promo_title: 'Umami Food Magazine'
promo_text: 'Skills and know-how. Magazine exclusive articles, recipes and plenty of reasons to get your copy today.'
findmore_url: '/about-umami'
findmore_text: 'Find out more'
status: true
info: ''
view_mode: full
visibility: { }
block.settings.umami_disclaimer:
type: block_settings
label: 'Disclaimer block'
mapping:
umami_disclaimer:
type: text_format
label: 'Disclaimer'
umami_copyright:
type: text_format
label: 'Copyright'
block.settings.umami_footer_promo:
type: block_settings
label: 'Footer promo block'
mapping:
promo_title:
type: string
label: 'Promo title'
promo_text:
type: string
label: 'Promo text'
findmore_url:
type: string
label: 'Find more URL'
findmore_text:
type: string
label: 'Find more text'
......@@ -313,6 +313,38 @@ protected function importBlockContent() {
'alt' => 'Mouth watering vegetarian pasta bake with rich tomato sauce and cheese toppings',
],
],
'umami_disclaimer' => [
'uuid' => '9b4dcd67-99f3-48d0-93c9-2c46648b29de',
'info' => 'Umami disclaimer',
'type' => 'disclaimer_block',
'field_disclaimer' => [
'value' => '<strong>Umami Magazine & Umami Publications</strong> is a fictional magazine and publisher for illustrative purposes only.',
'format' => 'basic_html',
],
'field_copyright' => [
'value' => '&copy; 2018 Terms & Conditions',
'format' => 'basic_html',
],
],
'umami_footer_promo' => [
'uuid' => '924ab293-8f5f-45a1-9c7f-2423ae61a241',
'info' => 'Umami footer promo',
'type' => 'footer_promo_block',
'field_title' => [
'value' => 'Umami Food Magazine',
],
'field_summary' => [
'value' => 'Skills and know-how. Magazine exclusive articles, recipes and plenty of reasons to get your copy today.',
],
'field_content_link' => [
'uri' => 'internal:' . call_user_func(function () {
$nodes = $this->entityTypeManager->getStorage('node')->loadByProperties(['title' => 'About Umami']);
$node = reset($nodes);
return $this->aliasManager->getAliasByPath('/node/' . $node->id());
}),
'title' => 'Find out more',
],
],
];
// Create block content.
......
......@@ -45,12 +45,15 @@ public function testReinstall() {
$node_storage->resetCache();
// Assert the removal of blocks on uninstall.
$count = $block_storage->getQuery()
->condition('type', 'banner_block')
->count()
->execute();
$this->assertEquals(0, $count);
$this->assertNull($this->container->get('entity_type.manager')->getStorage('block')->load('umami_banner_recipes'));
foreach ($this->expectedBlocks() as $block_info) {
$count = $block_storage->getQuery()
->condition('type', $block_info['type'])
->count()
->execute();
$this->assertEquals(0, $count);
$block = $block_storage->loadByProperties(['uuid' => $block_info['uuid']]);
$this->assertCount(0, $block);
}
// Assert the removal of nodes on uninstall.
$count = $node_storage->getQuery()
......@@ -95,20 +98,49 @@ protected function assertRecipesImported(EntityStorageInterface $node_storage) {
* Block storage.
*/
protected function assertImportedCustomBlock(EntityStorageInterface $block_storage) {
// Verify that block is placed.
$assert = $this->assertSession();
$this->drupalGet('/recipes');
$assert->pageTextContains('Super easy vegetarian pasta bake');
$img_alt_text = $assert->elementExists('css', '#block-umami-banner-recipes img')->getAttribute('alt');
$this->assertEquals('Mouth watering vegetarian pasta bake with rich tomato sauce and cheese toppings', $img_alt_text);
foreach ($this->expectedBlocks() as $block_info) {
// Verify that the block is placed.
$assert->pageTextContains($block_info['unique_text']);
// For the banner block, also verify the presence of alt text on the
// banner image.
if ($block_info['type'] == 'banner_block') {
$img_alt_text = $assert->elementExists('css', '#block-umami-banner-recipes img')->getAttribute('alt');
$this->assertEquals('Mouth watering vegetarian pasta bake with rich tomato sauce and cheese toppings', $img_alt_text);
}
// Verify that the block can be loaded.
$count = $block_storage->getQuery()
->condition('type', $block_info['type'])
->count()
->execute();
$this->assertGreaterThan(0, $count);
$block = $block_storage->loadByProperties(['uuid' => $block_info['uuid']]);
$this->assertCount(1, $block);
}
}
$count = $block_storage->getQuery()
->condition('type', 'banner_block')
->count()
->execute();
$this->assertGreaterThan(0, $count);
$block = $block_storage->loadByProperties(['uuid' => '4c7d58a3-a45d-412d-9068-259c57e40541']);
$this->assertCount(1, $block);
/**
* Returns the expected properties of this profile's custom blocks.
*/
protected function expectedBlocks() {
return [
[
'type' => 'banner_block',
'uuid' => '4c7d58a3-a45d-412d-9068-259c57e40541',
'unique_text' => 'A wholesome pasta bake is the ultimate comfort food.',
],
[
'type' => 'disclaimer_block',
'uuid' => '9b4dcd67-99f3-48d0-93c9-2c46648b29de',
'unique_text' => 'is a fictional magazine and publisher for illustrative purposes only',
],
[
'type' => 'footer_promo_block',
'uuid' => '924ab293-8f5f-45a1-9c7f-2423ae61a241',
'unique_text' => 'Magazine exclusive articles, recipes and plenty of reasons to get your copy today.',
],
];
}
}
<?php
namespace Drupal\demo_umami\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Provides a 'Umami disclaimer' block.
*
* @Block(
* id = "umami_disclaimer",
* admin_label = @Translation("Umami disclaimer")
* )
*
* @internal
* This code is only for use by the Umami demo profile.
*/
class UmamiDisclaimer extends BlockBase {
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'label_display' => FALSE,
'umami_disclaimer' => [
'value' => '',
'format' => '',
],
'umami_copyright' => [
'value' => '',
'format' => '',
],
] + parent::defaultConfiguration();
}
/**
* {@inheritdoc}
*/
public function build() {
$disclaimer_markup = check_markup($this->configuration['umami_disclaimer']['value'], $this->configuration['umami_disclaimer']['format']);
$copyright_markup = check_markup($this->configuration['umami_copyright']['value'], $this->configuration['umami_copyright']['format']);
return [
'#type' => 'inline_template',
'#template' => '<span class="umami-disclaimer">{{ disclaimer }}</span><span class="umami-copyright">{{ copyright }}</span>',
'#context' => [
'disclaimer' => $disclaimer_markup,
'copyright' => $copyright_markup,
],
];
}
/**
* {@inheritdoc}
*/
public function blockForm($form, FormStateInterface $form_state) {
$form = parent::blockForm($form, $form_state);
$form['umami_disclaimer'] = [
'#type' => 'text_format',
'#title' => $this->t('Umami Disclaimer'),
'#default_value' => $this->configuration['umami_disclaimer']['value'],
'#format' => $this->configuration['umami_disclaimer']['format'],
];
$form['umami_copyright'] = [
'#type' => 'text_format',
'#title' => $this->t('Umami Copyright Text'),
'#default_value' => $this->configuration['umami_copyright']['value'],
'#format' => $this->configuration['umami_copyright']['format'],
];
return $form;
}
/**
* {@inheritdoc}
*/
public function blockSubmit($form, FormStateInterface $form_state) {
parent::blockSubmit($form, $form_state);
$this->configuration['umami_disclaimer'] = $form_state->getValue('umami_disclaimer');
$this->configuration['umami_copyright'] = $form_state->getValue('umami_copyright');
}
}
<?php
namespace Drupal\demo_umami\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element\PathElement;
/**
* Provides a 'Promo banner' block for footer.
*
* @Block(
* id = "umami_footer_promo",
* admin_label = @Translation("Umami Bundle")
* )
*
* @internal
* This code is only for use by the Umami demo profile.
*/
class UmamiFooterPromo extends BlockBase {
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'label_display' => FALSE,
'promo_title' => '',
'promo_text' => '',