updated core to 8.6.3

This commit is contained in:
2018-11-21 12:49:46 +01:00
parent 8ca34853a3
commit c92c348eee
521 changed files with 12199 additions and 4578 deletions
@@ -5,6 +5,7 @@ namespace Drupal\layout_builder\Controller;
use Drupal\Core\Ajax\AjaxHelperTrait;
use Drupal\Core\Block\BlockManagerInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Url;
use Drupal\layout_builder\Context\LayoutBuilderContextTrait;
use Drupal\layout_builder\SectionStorageInterface;
@@ -19,6 +20,7 @@ class ChooseBlockController implements ContainerInjectionInterface {
use AjaxHelperTrait;
use LayoutBuilderContextTrait;
use StringTranslationTrait;
/**
* The block manager.
@@ -60,6 +62,7 @@ class ChooseBlockController implements ContainerInjectionInterface {
* A render array.
*/
public function build(SectionStorageInterface $section_storage, $delta, $region) {
$build['#title'] = $this->t('Choose a block');
$build['#type'] = 'container';
$build['#attributes']['class'][] = 'block-categories';
@@ -112,8 +112,8 @@ class LayoutBuilderEntityViewDisplay extends BaseEntityViewDisplay implements La
if ($new_value) {
$this->addSectionField($entity_type_id, $bundle, 'layout_builder__layout');
}
elseif ($field = FieldConfig::loadByName($entity_type_id, $bundle, 'layout_builder__layout')) {
$field->delete();
else {
$this->removeSectionField($entity_type_id, $bundle, 'layout_builder__layout');
}
}
@@ -139,6 +139,31 @@ class LayoutBuilderEntityViewDisplay extends BaseEntityViewDisplay implements La
}
}
/**
* Removes a layout section field if it is no longer needed.
*
* Because the field is shared across all view modes, the field will only be
* removed if no other view modes are using it.
*
* @param string $entity_type_id
* The entity type ID.
* @param string $bundle
* The bundle.
* @param string $field_name
* The name for the layout section field.
*/
protected function removeSectionField($entity_type_id, $bundle, $field_name) {
$query = $this->entityTypeManager()->getStorage($this->getEntityTypeId())->getQuery()
->condition('targetEntityType', $this->getTargetEntityTypeId())
->condition('bundle', $this->getTargetBundle())
->condition('mode', $this->getMode(), '<>')
->condition('third_party_settings.layout_builder.allow_custom', TRUE);
$enabled = (bool) $query->count()->execute();
if (!$enabled && $field = FieldConfig::loadByName($entity_type_id, $bundle, $field_name)) {
$field->delete();
}
}
/**
* Adds a layout section field to a given bundle.
*
@@ -172,6 +197,16 @@ class LayoutBuilderEntityViewDisplay extends BaseEntityViewDisplay implements La
}
}
/**
* {@inheritdoc}
*/
public function createCopy($mode) {
// Disable Layout Builder and remove any sections copied from the original.
return parent::createCopy($mode)
->setSections([])
->disableLayoutBuilder();
}
/**
* {@inheritdoc}
*/
@@ -47,9 +47,12 @@ class LayoutSectionItemList extends FieldItemList implements SectionListInterfac
/**
* {@inheritdoc}
*/
public function __wakeup() {
public function getEntity() {
$entity = parent::getEntity();
// Ensure the entity is updated with the latest value.
$this->getEntity()->set($this->getName(), $this->getValue());
$entity->set($this->getName(), $this->getValue());
return $entity;
}
}
@@ -47,6 +47,10 @@ class LayoutBuilderEntityViewDisplayForm extends EntityViewDisplayEditForm {
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
// Remove the Layout Builder field from the list.
$form['#fields'] = array_diff($form['#fields'], ['layout_builder__layout']);
unset($form['fields']['layout_builder__layout']);
$is_enabled = $this->entity->isLayoutBuilderEnabled();
if ($is_enabled) {
// Hide the table of fields.
@@ -54,10 +58,6 @@ class LayoutBuilderEntityViewDisplayForm extends EntityViewDisplayEditForm {
$form['#fields'] = [];
$form['#extra'] = [];
}
else {
// Remove the Layout Builder field from the list.
$form['#fields'] = array_diff($form['#fields'], ['layout_builder__layout']);
}
$form['manage_layout'] = [
'#type' => 'link',
@@ -180,7 +180,7 @@ class LayoutBuilderEntityViewDisplayForm extends EntityViewDisplayEditForm {
* {@inheritdoc}
*/
protected function buildFieldRow(FieldDefinitionInterface $field_definition, array $form, FormStateInterface $form_state) {
if ($this->entity->isLayoutBuilderEnabled() || $field_definition->getType() === 'layout_section') {
if ($this->entity->isLayoutBuilderEnabled()) {
return [];
}
@@ -103,10 +103,6 @@ class RevertOverridesForm extends ConfirmFormBase {
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// Ensure the section storage is loaded from the database.
// @todo Remove after https://www.drupal.org/node/2970801.
$this->sectionStorage = \Drupal::service('plugin.manager.layout_builder.section_storage')->loadFromStorageId($this->sectionStorage->getStorageType(), $this->sectionStorage->getStorageId());
// Remove all sections.
while ($this->sectionStorage->count()) {
$this->sectionStorage->removeSection(0);
@@ -87,8 +87,10 @@ class InlineBlockUsage {
* The block content entity IDs.
*/
public function deleteUsage(array $block_content_ids) {
$query = $this->database->delete('inline_block_usage')->condition('block_content_id', $block_content_ids, 'IN');
$query->execute();
if (!empty($block_content_ids)) {
$query = $this->database->delete('inline_block_usage')->condition('block_content_id', $block_content_ids, 'IN');
$query->execute();
}
}
/**
@@ -191,11 +191,21 @@ class LayoutBuilderTest extends BrowserTestBase {
// Reverting the override returns it to the defaults.
$this->clickLink('Layout');
$assert_session->linkExists('Add Block');
$this->clickLink('Add Block');
$assert_session->linkExists('ID');
$this->clickLink('ID');
$page->pressButton('Add Block');
// The title field is present.
$assert_session->elementExists('css', '.field--name-nid');
$assert_session->pageTextContains('ID');
$assert_session->pageTextContains('1');
$assert_session->linkExists('Revert to defaults');
$this->clickLink('Revert to defaults');
$page->pressButton('Revert');
$assert_session->pageTextContains('The layout has been reverted back to defaults.');
$assert_session->elementExists('css', '.field--name-title');
$assert_session->elementNotExists('css', '.field--name-nid');
$assert_session->pageTextContains('The first node body');
$assert_session->pageTextContains('Powered by Drupal');
$assert_session->pageTextContains('Placeholder for the "Extra label" field');
@@ -225,6 +235,63 @@ class LayoutBuilderTest extends BrowserTestBase {
$assert_session->elementNotExists('css', '.field--name-field-my-text');
}
/**
* Tests that a non-default view mode works as expected.
*/
public function testNonDefaultViewMode() {
$assert_session = $this->assertSession();
$page = $this->getSession()->getPage();
$this->drupalLogin($this->drupalCreateUser([
'configure any layout',
'administer node display',
]));
$field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
// Allow overrides for the layout.
$this->drupalGet("$field_ui_prefix/display/default");
$page->checkField('layout[enabled]');
$page->pressButton('Save');
$page->checkField('layout[allow_custom]');
$page->pressButton('Save');
$this->clickLink('Manage layout');
// Confirm the body field only is shown once.
$assert_session->elementsCount('css', '.field--name-body', 1);
$this->clickLink('Cancel Layout');
$this->clickLink('Teaser');
// Enabling Layout Builder for the default mode does not affect the teaser.
$assert_session->addressEquals("$field_ui_prefix/display/teaser");
$assert_session->elementNotExists('css', '#layout-builder__layout');
$assert_session->checkboxNotChecked('layout[enabled]');
$page->checkField('layout[enabled]');
$page->pressButton('Save');
$assert_session->linkExists('Manage layout');
$page->clickLink('Manage layout');
// Confirm the body field only is shown once.
$assert_session->elementsCount('css', '.field--name-body', 1);
// Enable a disabled view mode.
$page->clickLink('Cancel Layout');
$assert_session->addressEquals("$field_ui_prefix/display/teaser");
$page->clickLink('Default');
$assert_session->addressEquals("$field_ui_prefix/display");
$assert_session->linkNotExists('Full content');
$page->checkField('display_modes_custom[full]');
$page->pressButton('Save');
$assert_session->linkExists('Full content');
$page->clickLink('Full content');
$assert_session->addressEquals("$field_ui_prefix/display/full");
$page->checkField('layout[enabled]');
$page->pressButton('Save');
$assert_session->linkExists('Manage layout');
$page->clickLink('Manage layout');
// Confirm the body field only is shown once.
$assert_session->elementsCount('css', '.field--name-body', 1);
}
/**
* Tests that component's dependencies are respected during removal.
*/
@@ -335,6 +402,7 @@ class LayoutBuilderTest extends BrowserTestBase {
// Enable the full view mode and customize it.
$this->drupalPostForm("$field_ui_prefix/display/default", ['display_modes_custom[full]' => TRUE], 'Save');
$this->drupalPostForm("$field_ui_prefix/display/full", ['layout[enabled]' => TRUE], 'Save');
$this->drupalGet("$field_ui_prefix/display-layout/full");
$this->clickLink('Add Block');
$this->clickLink('Powered by Drupal');
@@ -0,0 +1,94 @@
<?php
namespace Drupal\Tests\layout_builder\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Tests functionality of the entity view display with regard to Layout Builder.
*
* @group layout_builder
*/
class LayoutDisplayTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['field_ui', 'layout_builder', 'block', 'node'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// @todo The Layout Builder UI relies on local tasks; fix in
// https://www.drupal.org/project/drupal/issues/2917777.
$this->drupalPlaceBlock('local_tasks_block');
$this->createContentType([
'type' => 'bundle_with_section_field',
]);
$this->createNode(['type' => 'bundle_with_section_field']);
$this->drupalLogin($this->drupalCreateUser([
'configure any layout',
'administer node display',
'administer display modes',
], 'foobar'));
}
/**
* Tests the interaction between multiple view modes.
*/
public function testMultipleViewModes() {
$assert_session = $this->assertSession();
$page = $this->getSession()->getPage();
$field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field/display';
// Enable Layout Builder for the default view modes, and overrides.
$this->drupalGet("$field_ui_prefix/default");
$page->checkField('layout[enabled]');
$page->pressButton('Save');
$page->checkField('layout[allow_custom]');
$page->pressButton('Save');
$this->drupalGet('node/1');
$assert_session->pageTextNotContains('Powered by Drupal');
$assert_session->linkExists('Layout');
$this->clickLink('Layout');
$assert_session->linkExists('Add Block');
$this->clickLink('Add Block');
$assert_session->linkExists('Powered by Drupal');
$this->clickLink('Powered by Drupal');
$page->pressButton('Add Block');
$assert_session->linkExists('Save Layout');
$this->clickLink('Save Layout');
$assert_session->pageTextContains('Powered by Drupal');
// Add a new view mode.
$this->drupalGet('admin/structure/display-modes/view/add/node');
$page->fillField('label', 'New');
$page->fillField('id', 'new');
$page->pressButton('Save');
// Enable the new view mode.
$this->drupalGet("$field_ui_prefix/default");
$page->checkField('display_modes_custom[new]');
$page->pressButton('Save');
// Enable and disable Layout Builder for the new view mode.
$this->drupalGet("$field_ui_prefix/new");
$page->checkField('layout[enabled]');
$page->pressButton('Save');
$page->uncheckField('layout[enabled]');
$page->pressButton('Save');
$page->pressButton('Confirm');
// The node using the default view mode still contains its overrides.
$this->drupalGet('node/1');
$assert_session->pageTextContains('Powered by Drupal');
}
}
@@ -0,0 +1,28 @@
<?php
namespace Drupal\Tests\layout_builder\Unit;
use Drupal\Core\Database\Connection;
use Drupal\layout_builder\InlineBlockUsage;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass \Drupal\layout_builder\InlineBlockUsage
*
* @group layout_builder
*/
class InlineBlockUsageTest extends UnitTestCase {
/**
* Tests calling deleteUsage() with empty array.
*
* @covers ::deleteUsage
*/
public function testEmptyDeleteUsageCall() {
$connection = $this->prophesize(Connection::class);
$connection->delete('inline_block_usage')->shouldNotBeCalled();
(new InlineBlockUsage($connection->reveal()))->deleteUsage([]);
}
}