Section example

    $result = $this->plugin->access('view');
    $this->assertFalse($result);
    $result = $this->plugin->access('view', $account);
    $this->assertFalse($result);
  }

  /** * Provides test data for ::testAccess(). */
  public function providerTestAccess() {
    $section_data = [
      new Section('layout_onecol', [][
        '10000000-0000-1000-a000-000000000000' => new SectionComponent('10000000-0000-1000-a000-000000000000', 'content', ['id' => 'foo']),
      ]),
    ];

    // Data provider values are:     // - the expected outcome of the call to ::access()     // - whether Layout Builder has been enabled for this display     // - any section data     // - any permissions to grant to the user.     $data = [];
    $data['disabled, no data, no permissions'] = [
      
$this->assertEmpty($this->cssSelect('.layout__region .field--name-test-display-non-configurable'));

    $this->installLayoutBuilder();

    // Without using Layout Builder for an override, the result has not changed.     $this->assertFieldAttributes($this->entity, $expected_fields);

    // Add a layout override.     $this->enableOverrides();
    /** @var \Drupal\layout_builder\SectionStorageInterface $field_list */
    $field_list = $this->entity->get(OverridesSectionStorage::FIELD_NAME);
    $field_list->appendSection(new Section('layout_onecol'));
    $this->entity->save();

    // The rendered entity has now changed. The non-configurable field is shown     // outside the layout, the configurable field is not shown at all, and the     // layout itself is rendered (but empty).     $new_expected_fields = [
      'field field--name-name field--type-string field--label-hidden field__item',
      'clearfix text-formatted field field--name-test-display-non-configurable field--type-text field--label-above',
      'clearfix text-formatted field field--name-test-display-multiple field--type-text field--label-above',
    ];
    $this->assertFieldAttributes($this->entity, $new_expected_fields);
    

  public function testSimpleConfigBasedLayout() {
    $assert_session = $this->assertSession();

    $this->drupalLogin($this->createUser(['configure any layout']));

    // Prepare an object with a pre-existing section.     $this->container->get('config.factory')->getEditable('layout_builder_test.test_simple_config.existing')
      ->set('sections', [(new Section('layout_twocol'))->toArray()])
      ->save();

    // The pre-existing section is found.     $this->drupalGet('layout-builder-test-simple-config/existing');
    $assert_session->elementsCount('css', '.layout', 1);
    $assert_session->elementsCount('css', '.layout--twocol', 1);

    // No layout is selected for a new object.     $this->drupalGet('layout-builder-test-simple-config/new');
    $assert_session->elementNotExists('css', '.layout');
  }

  

class TestStateBasedSectionStorage extends SectionStorageBase {

  /** * {@inheritdoc} */
  public function getSections() {
    // Return a custom section.     $section = new Section('layout_onecol');
    $section->appendComponent(new SectionComponent('fake-uuid', 'content', [
      'id' => 'system_powered_by_block',
      'label' => 'Test block title',
      'label_display' => 'visible',
    ]));
    return [$section];
  }

  /** * {@inheritdoc} */
  
$this->validateNumberOfActions();
    }

    public static function fromNotification(Notification $notification): self
    {
        $options = (new self())
            ->title($notification->getSubject())
            ->text($notification->getContent());

        if ($exception = $notification->getExceptionAsString()) {
            $options->section((new Section())->text($exception));
        }

        return $options;
    }

    public function toArray(): array
    {
        $options = $this->options;

        // Send a text, not a message card         if (1 === \count($options) && isset($options['text'])) {
            

  protected $section;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->section = new Section(
      'layout_onecol',
      [],
      [
        new SectionComponent('existing-uuid', 'some-region', ['id' => 'existing-block-id']),
        (new SectionComponent('20000000-0000-1000-a000-000000000000', 'ordered-region', ['id' => 'second-block-id']))->setWeight(3),
        (new SectionComponent('10000000-0000-1000-a000-000000000000', 'ordered-region', ['id' => 'first-block-id']))->setWeight(2),
      ],
      [
        'bad_judgement' => ['blink_speed' => 'fast', 'spin_direction' => 'clockwise'],
        'hunt_and_peck' => ['delay' => '300ms'],
      ]
    );
$block->getConfiguration()->willReturn([]);
    $block->getPreviewFallbackString()->willReturn($placeholder_label);

    $section = [
      new SectionComponent('some_uuid', 'content', ['id' => 'block_plugin_id']),
    ];
    $expected = [
      'content' => [
        'some_uuid' => $render_array,
      ],
    ];
    $result = (new Section('layout_onecol', []$section))->toRenderArray();
    $this->assertEquals($expected$result);
  }

  /** * @covers ::toRenderArray */
  public function testToRenderArrayAccessDenied() {
    $block = $this->prophesize(BlockPluginInterface::class);
    $this->blockManager->createInstance('block_plugin_id', ['id' => 'block_plugin_id'])->willReturn($block->reveal());

    $access_result = AccessResult::forbidden();
    

  protected function addBlankSection() {
    if ($this->hasSection(0)) {
      throw new \Exception('A blank section must only be added to an empty list');
    }

    $this->appendSection(new Section('layout_builder_blank'));
    return $this;
  }

  /** * Indicates if this section list contains a blank section. * * A blank section is used to differentiate the difference between a layout * that has never been instantiated and one that has purposefully had all * sections removed. * * @return bool * TRUE if the section list contains a blank section, FALSE otherwise. * * @see \Drupal\layout_builder\Plugin\Layout\BlankLayout */

  protected $sectionList;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $section_data = [
      new Section('layout_test_plugin', [][
        '10000000-0000-1000-a000-000000000000' => new SectionComponent('10000000-0000-1000-a000-000000000000', 'content', ['id' => 'foo']),
      ]),
      new Section('layout_test_plugin', ['setting_1' => 'bar'][
        '20000000-0000-1000-a000-000000000000' => new SectionComponent('20000000-0000-1000-a000-000000000000', 'content', ['id' => 'foo']),
      ]),
    ];
    $this->sectionList = $this->getSectionList($section_data);
  }

  /** * Sets up the section list. * * @param array $section_data * An array of section data. * * @return \Drupal\layout_builder\SectionListInterface * The section list. */


  /** * @covers ::getEntitySections */
  public function testGetEntitySections() {
    $entity = EntityTest::create(['name' => 'updated']);
    $section_storage_manager = $this->prophesize(SectionStorageManagerInterface::class);
    $section_storage_manager->load('')->willReturn(NULL);
    $section_storage = $this->prophesize(SectionStorageInterface::class);
    $sections = [
      new Section('layout_onecol'),
    ];
    $this->assertCount(1, $sections);
    $section_storage->getSections()->willReturn($sections);
    $section_storage->count()->willReturn(1);

    $section_storage_manager->findByContext(Argument::cetera())->willReturn($section_storage->reveal());
    $this->container->set('plugin.manager.layout_builder.section_storage', $section_storage_manager->reveal());
    $class = new TestLayoutEntityHelperTrait();
    // Ensure that if the entity has a section storage the sections will be     // returned.     $this->assertSame($sections$class->getEntitySections($entity));

    

  public function onBeforePrepareLayout(PrepareLayoutEvent $event) {
    $section_storage = $event->getSectionStorage();
    $context = $section_storage->getContextValues();

    if (!empty($context['entity'])) {
      /** @var \Drupal\Core\Entity\EntityInterface $entity */
      $entity = $context['entity'];

      // Node 1 or 2: Append a block to the layout.       if (in_array($entity->id()['1', '2'])) {
        $section = new Section('layout_onecol');
        $section->appendComponent(new SectionComponent('fake-uuid', 'content', [
          'id' => 'static_block',
          'label' => 'Test static block title',
          'label_display' => 'visible',
          'provider' => 'fake_provider',
        ]));
        $section_storage->appendSection($section);
      }

      // Node 2: Stop event propagation.       if ($entity->id() === '2') {
        
$this->plugin->setContext('display', EntityContext::fromEntity($display));
    $result = $this->plugin->access($operation);
    $this->assertSame($expected$result);
  }

  /** * Provides test data for ::testAccess(). */
  public function providerTestAccess() {
    $section_data = [
      new Section(
        'layout_onecol',
        [],
        [
          '10000000-0000-1000-a000-000000000000' => new SectionComponent('10000000-0000-1000-a000-000000000000', 'content', ['id' => 'foo']['harold' => 'maude']),
        ],
        ['layout_builder_defaults_test' => ['which_party' => 'third']]
      ),
    ];

    // Data provider values are:     // - the expected outcome of the call to ::access()
->save();
    FieldConfig::loadByName('entity_test', 'entity_test', OverridesSectionStorage::FIELD_NAME)
      ->setTranslatable(TRUE)
      ->save();
  }

  /** * Tests that sections on cleared when creating a new translation. */
  public function testSectionsClearedOnCreateTranslation() {
    $section_data = [
      new Section('layout_onecol', [][
        '10000000-0000-1000-a000-000000000000' => new SectionComponent('10000000-0000-1000-a000-000000000000', 'content', ['id' => 'foo']),
      ]),
    ];
    $entity = EntityTest::create([OverridesSectionStorage::FIELD_NAME => $section_data]);
    $entity->save();
    $this->assertFalse($entity->get(OverridesSectionStorage::FIELD_NAME)->isEmpty());

    $entity = EntityTest::load($entity->id());
    /** @var \Drupal\entity_test\Entity\EntityTest $translation */
    $translation = $entity->addTranslation('es', $entity->toArray());

    
yield [' '];
        yield ['red'];
        yield ['#1'];
        yield ['#22'];
        yield ['#4444'];
        yield ['#55555'];
    }

    public function testSectionViaConstructor()
    {
        $options = new MicrosoftTeamsOptions([
            'sections' => $sections = [(new Section())->toArray()],
        ]);

        $this->assertSame($sections$options->toArray()['sections']);
    }

    public function testSectionViaSetter()
    {
        $options = (new MicrosoftTeamsOptions())
            ->section($section = new Section());

        $this->assertSame([$section->toArray()]$options->toArray()['sections']);
    }

  public function getCurrentSection(): Section {
    if (!isset($this->section)) {
      if ($this->isUpdate) {
        $this->section = $this->sectionStorage->getSection($this->delta);
      }
      else {
        $this->section = new Section($this->pluginId);
      }
    }

    return $this->section;
  }

}
Home | Imprint | This part of the site doesn't use cookies.