Skip to content
Snippets Groups Projects
Unverified Commit 5b1a9182 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3493287 by phenaproxima, alexpott, longwave, tim.plunkett: The default...

Issue #3493287 by phenaproxima, alexpott, longwave, tim.plunkett: The default content importer should handle Layout Builder section data

(cherry picked from commit a44cf1ef)
parent 3520ae25
Branches
Tags
23 merge requests!12079Issue #3523476 by matthiasm11: Add empty check on operator,!12024Fix: DocBlock comment for return value of Drupal\Core\Database\Connection::transactionManager(),!11974Draft: Issue #3495165 by catch, joeyroth, berdir, texas-bronius: Better warning...,!11934Issue #3520997: DefaultLazyPluginCollection unnecessarily instantiates plugins when sorting collection,!11887Issue #3520065: The migrate Row class API is incomplete,!11636Draft: Issue #3515643 by macsim: fieldNameExists method is inconsistent,!11515Issue #3480419 by mondrake, smustgrave, catch: Method...,!11380Issue #3490698 by catch, spokje: Bump MINIMUM_STABILITY back to 'stable' when...,!11281Use Drupal Core Leadership terminology in MAINTAINERS.txt,!11239Issue #3507548: Allow workspace changes listing to show all items, without a pager,!11238Fix issue #3051797,!11213Issue #3506743 by tomislav.matokovic: Increasing the color contrast for the navigation block title against the background of the navigation sidebar to at least 4.5:1,!11147Draft: Try to avoid manually setting required cache contexts,!11108Issue #3490298 by nicxvan: Profiles can be missed in OOP hooks,!11093Drupal on MongoDB 11.1.x,!11017Issue #3502540: Add date filter for moderated content.,!11009Issue #3486972 migrate feed icon,!10999Cleaning up Taxonomy hooks and updating baseline.,!10977Issue #3501457: Fix path used in a A11y Test Admin,!10881Issue #3489329 by mfb, casey: symfony/http-foundation commit 32310ff breaks PathValidator,!10570Issue #3494197: Convert Twig engine hooks,!10567Issue #3494154: Index is not added if entity doesn't support revisions,!10548Revert "Issue #3478621 by catch, longwave, nicxvan: Add filecache to OOP hook attribute parsing"
Pipeline #366545 passed
Pipeline: drupal

#366546

    ...@@ -31,6 +31,9 @@ class SectionData extends TypedData { ...@@ -31,6 +31,9 @@ class SectionData extends TypedData {
    * {@inheritdoc} * {@inheritdoc}
    */ */
    public function setValue($value, $notify = TRUE) { public function setValue($value, $notify = TRUE) {
    if (is_array($value)) {
    $value = Section::fromArray($value);
    }
    if ($value && !$value instanceof Section) { if ($value && !$value instanceof Section) {
    throw new \InvalidArgumentException(sprintf('Value assigned to "%s" is not a valid section', $this->getName())); throw new \InvalidArgumentException(sprintf('Value assigned to "%s" is not a valid section', $this->getName()));
    } }
    ......
    <?php
    declare(strict_types=1);
    namespace Drupal\Tests\layout_builder\Kernel;
    use Drupal\Core\TypedData\DataDefinition;
    use Drupal\Core\TypedData\TypedDataManagerInterface;
    use Drupal\KernelTests\KernelTestBase;
    use Drupal\layout_builder\Section;
    /**
    * @coversDefaultClass \Drupal\layout_builder\Plugin\DataType\SectionData
    *
    * @group layout_builder
    */
    class SectionDataTest extends KernelTestBase {
    /**
    * {@inheritdoc}
    */
    protected static $modules = ['layout_builder'];
    /**
    * @covers ::setValue
    */
    public function testSetArrayValue(): void {
    $definition = DataDefinition::create('layout_section');
    $data = $this->container->get(TypedDataManagerInterface::class)
    ->create($definition, name: 'test_section');
    // If an array is passed, it's converted to a Section object.
    $data->setValue([]);
    $this->assertInstanceOf(Section::class, $data->getValue());
    // Anything else should raise an exception.
    $this->expectExceptionMessage('Value assigned to "test_section" is not a valid section');
    $data->setValue('[]');
    }
    }
    ...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
    use Drupal\Core\DefaultContent\Importer; use Drupal\Core\DefaultContent\Importer;
    use Drupal\Core\DefaultContent\ImportException; use Drupal\Core\DefaultContent\ImportException;
    use Drupal\Core\DefaultContent\InvalidEntityException; use Drupal\Core\DefaultContent\InvalidEntityException;
    use Drupal\Core\Entity\EntityDisplayRepositoryInterface;
    use Drupal\Core\Entity\EntityRepositoryInterface; use Drupal\Core\Entity\EntityRepositoryInterface;
    use Drupal\Core\File\FileExists; use Drupal\Core\File\FileExists;
    use Drupal\Core\Url; use Drupal\Core\Url;
    ...@@ -22,6 +23,7 @@ ...@@ -22,6 +23,7 @@
    use Drupal\FunctionalTests\Core\Recipe\RecipeTestTrait; use Drupal\FunctionalTests\Core\Recipe\RecipeTestTrait;
    use Drupal\language\Entity\ConfigurableLanguage; use Drupal\language\Entity\ConfigurableLanguage;
    use Drupal\language\Entity\ContentLanguageSettings; use Drupal\language\Entity\ContentLanguageSettings;
    use Drupal\layout_builder\Section;
    use Drupal\media\MediaInterface; use Drupal\media\MediaInterface;
    use Drupal\menu_link_content\MenuLinkContentInterface; use Drupal\menu_link_content\MenuLinkContentInterface;
    use Drupal\node\NodeInterface; use Drupal\node\NodeInterface;
    ...@@ -57,6 +59,7 @@ class ContentImportTest extends BrowserTestBase { ...@@ -57,6 +59,7 @@ class ContentImportTest extends BrowserTestBase {
    'block_content', 'block_content',
    'content_translation', 'content_translation',
    'entity_test', 'entity_test',
    'layout_builder',
    'media', 'media',
    'menu_link_content', 'menu_link_content',
    'node', 'node',
    ...@@ -108,6 +111,13 @@ protected function setUp(): void { ...@@ -108,6 +111,13 @@ protected function setUp(): void {
    $this->contentDir = $this->getDrupalRoot() . '/core/tests/fixtures/default_content'; $this->contentDir = $this->getDrupalRoot() . '/core/tests/fixtures/default_content';
    \Drupal::service('file_system')->copy($this->contentDir . '/file/druplicon_copy.png', $this->publicFilesDirectory . '/druplicon_copy.png', FileExists::Error); \Drupal::service('file_system')->copy($this->contentDir . '/file/druplicon_copy.png', $this->publicFilesDirectory . '/druplicon_copy.png', FileExists::Error);
    // Enable Layout Builder for the Page content type, with custom overrides.
    \Drupal::service(EntityDisplayRepositoryInterface::class)
    ->getViewDisplay('node', 'page')
    ->enableLayoutBuilder()
    ->setOverridable()
    ->save();
    } }
    /** /**
    ...@@ -259,6 +269,15 @@ private function assertContentWasImported(): void { ...@@ -259,6 +269,15 @@ private function assertContentWasImported(): void {
    $translation = $node->getTranslation('fr'); $translation = $node->getTranslation('fr');
    $this->assertSame('Perdu en traduction', $translation->label()); $this->assertSame('Perdu en traduction', $translation->label());
    $this->assertSame("Içi c'est la version français.", $translation->body->value); $this->assertSame("Içi c'est la version français.", $translation->body->value);
    // Layout data should be imported.
    $node = $entity_repository->loadEntityByUuid('node', '32650de8-9edd-48dc-80b8-8bda180ebbac');
    $this->assertInstanceOf(NodeInterface::class, $node);
    $section = $node->layout_builder__layout[0]->section;
    $this->assertInstanceOf(Section::class, $section);
    $this->assertCount(2, $section->getComponents());
    $this->assertSame('system_powered_by_block', $section->getComponent('03b45f14-cf74-469a-8398-edf3383ce7fa')->getPluginId());
    } }
    } }
    _meta:
    version: '1.0'
    entity_type: node
    uuid: 32650de8-9edd-48dc-80b8-8bda180ebbac
    bundle: page
    default_langcode: en
    default:
    revision_uid:
    -
    target_id: 1
    status:
    -
    value: true
    uid:
    -
    target_id: 1
    title:
    -
    value: 'Layout override'
    created:
    -
    value: 1733930395
    promote:
    -
    value: true
    sticky:
    -
    value: false
    revision_translation_affected:
    -
    value: true
    layout_builder__layout:
    -
    section:
    layout_id: layout_onecol
    layout_settings:
    label: ''
    components:
    199f7eea-3e6e-4a91-bf5e-7b1d6f13fecd:
    uuid: 199f7eea-3e6e-4a91-bf5e-7b1d6f13fecd
    region: content
    configuration:
    id: 'extra_field_block:node:test:links'
    label_display: '0'
    context_mapping:
    entity: layout_builder.entity
    weight: 1
    additional: { }
    03b45f14-cf74-469a-8398-edf3383ce7fa:
    uuid: 03b45f14-cf74-469a-8398-edf3383ce7fa
    region: content
    configuration:
    id: system_powered_by_block
    label: 'Powered by Drupal'
    label_display: 0
    provider: system
    context_mapping: { }
    weight: 0
    additional: { }
    third_party_settings: { }
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment