getSection example

$this->overwriteWithDefaultShopValues($config);

        return parent::write($config$fields$update$force$allowReset);
    }

    /** * If there is a snippet missing, set the shopID and localeID to the main shop since all * language shops derive from it. */
    private function overwriteWithDefaultShopValues(Enlight_Config $config): void
    {
        $section = explode($config->getSectionSeparator()$config->getSection());
        if (!\is_array($section)) {
            return;
        }

        if (!\is_array($this->_sectionColumn)) {
            return;
        }

        foreach ($this->_sectionColumn as $key => $columnName) {
            switch ($columnName) {
                case 'shopID':
                

  public function build(SectionStorageInterface $section_storage, int $delta_from, int $delta_to$region_to$block_uuid$preceding_block_uuid = NULL) {
    $section = $section_storage->getSection($delta_from);

    $component = $section->getComponent($block_uuid);
    $section->removeComponent($block_uuid);

    // If the block is moving from one section to another, update the original     // section and load the new one.     if ($delta_from !== $delta_to) {
      $section = $section_storage->getSection($delta_to);
    }

    // If a preceding block was specified, insert after that. Otherwise add the

  protected function getPathForFieldBlock($entity_type_id$bundle$view_mode$field_name) {
    $delta = 0;
    /** @var \Drupal\layout_builder\Entity\LayoutEntityDisplayInterface $display */
    $display = $this->container->get('entity_type.manager')->getStorage('entity_view_display')->load("$entity_type_id.$bundle.$view_mode");
    $body_component = NULL;
    foreach ($display->getSection($delta)->getComponents() as $component) {
      if ($component->getPluginId() === "field_block:$entity_type_id:$bundle:$field_name") {
        $body_component = $component;
      }
    }
    $this->assertNotNull($body_component);
    return 'layout_builder/update/block/defaults/node.after.default/0/content/' . $body_component->getUuid();
  }

}

  protected $uuid;

  /** * {@inheritdoc} */
  public function getQuestion() {
    $label = $this->sectionStorage
      ->getSection($this->delta)
      ->getComponent($this->uuid)
      ->getPlugin()
      ->label();

    return $this->t('Are you sure you want to remove the %label block?', ['%label' => $label]);
  }

  /** * {@inheritdoc} */
  public function getConfirmText() {
    
// Disable Layout Builder and remove any sections copied from the original.     return parent::createCopy($mode)
      ->setSections([])
      ->disableLayoutBuilder();
  }

  /** * {@inheritdoc} */
  protected function getDefaultRegion() {
    if ($this->hasSection(0)) {
      return $this->getSection(0)->getDefaultRegion();
    }

    return parent::getDefaultRegion();
  }

  /** * Wraps the context repository service. * * @return \Drupal\Core\Plugin\Context\ContextRepositoryInterface * The context repository service. */
  
->addContextDefinition('display', EntityContextDefinition::fromEntityTypeId('entity_view_display'))
      ->addContextDefinition('view_mode', new ContextDefinition('string'));
    $this->plugin = DefaultsSectionStorage::create($this->container, [], 'defaults', $definition);
  }

  /** * Tests installing defaults via config install. */
  public function testConfigInstall() {
    /** @var \Drupal\layout_builder\Entity\LayoutEntityDisplayInterface $display */
    $display = LayoutBuilderEntityViewDisplay::load('entity_test.bundle_with_extra_fields.default');
    $section = $display->getSection(0);
    $this->assertInstanceOf(Section::class$section);
    $this->assertEquals('layout_twocol_section', $section->getLayoutId());
    $this->assertEquals([
      'column_widths' => '50-50',
      'label' => '',
    ]$section->getLayoutSettings());
  }

  /** * @covers ::access * @dataProvider providerTestAccess * * @param bool $expected * The expected outcome of ::access(). * @param string $operation * The operation to pass to ::access(). * @param bool $is_enabled * Whether Layout Builder is enabled for this display. * @param array $section_data * Data to store as the sections value for Layout Builder. */
$form['actions']['submit']['#ajax']['callback'] = '::ajaxSubmit';
    }
    return $form;
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $region = $this->getSelectedRegion($form_state);
    $delta = $this->getSelectedDelta($form_state);
    $original_section = $this->sectionStorage->getSection($this->delta);
    $component = $original_section->getComponent($this->uuid);
    $section = $this->sectionStorage->getSection($delta);
    if ($delta !== $this->delta) {
      // Remove component from old section and add it to the new section.       $original_section->removeComponent($this->uuid);
      $section->insertComponent(0, $component);
    }
    $component->setRegion($region);
    foreach ($form_state->getValue('components') as $uuid => $component_info) {
      $section->getComponent($uuid)->setWeight($component_info['weight']);
    }
    
/** * {@inheritdoc} */
  public function getSections() {
    return $this->getSectionList()->getSections();
  }

  /** * {@inheritdoc} */
  public function getSection($delta) {
    return $this->getSectionList()->getSection($delta);
  }

  /** * {@inheritdoc} */
  public function appendSection(Section $section) {
    $this->getSectionList()->appendSection($section);
    return $this;
  }

  /** * {@inheritdoc} */
new Section('layout_test_plugin', ['setting_1' => 'bar'][
        '20000000-0000-1000-a000-000000000000' => new SectionComponent('20000000-0000-1000-a000-000000000000', 'content', ['id' => 'foo']),
      ]),
    ];
    $this->assertSections($expected);
  }

  /** * @covers ::getSection */
  public function testGetSection() {
    $this->assertInstanceOf(Section::class$this->sectionList->getSection(0));
  }

  /** * @covers ::getSection */
  public function testGetSectionInvalidDelta() {
    $this->expectException(\OutOfBoundsException::class);
    $this->expectExceptionMessage('Invalid delta "2"');
    $this->sectionList->getSection(2);
  }

  

  protected function buildAdministrativeSection(SectionStorageInterface $section_storage$delta) {
    $storage_type = $section_storage->getStorageType();
    $storage_id = $section_storage->getStorageId();
    $section = $section_storage->getSection($delta);

    $layout = $section->getLayout($this->getPopulatedContexts($section_storage));
    $layout_settings = $section->getLayoutSettings();
    $section_label = !empty($layout_settings['label']) ? $layout_settings['label'] : $this->t('Section @section', ['@section' => $delta + 1]);

    $build = $section->toRenderArray($this->getPopulatedContexts($section_storage), TRUE);
    $layout_definition = $layout->getPluginDefinition();

    $region_labels = $layout_definition->getRegionLabels();
    foreach ($layout_definition->getRegions() as $region => $info) {
      if (!empty($build[$region])) {
        

    public function read(Enlight_Config $config)
    {
        $name = $this->_namePrefix . $config->getName() . $this->_nameSuffix;

        $data = [];

        $extends = $config->getExtends();
        $currentSection = $config->getSection();
        while ($currentSection !== null) {
            $data += $this->readSection($name$currentSection);
            $currentSection = isset($extends[$currentSection]) ? $extends[$currentSection] : null;
        }

        $config->setData($data);

        return $this;
    }

    /** * Saves the data changes in the data store. * * @param string[]|null $fields * @param bool|null $update If false, existing rows are not updated * @param bool $force If true, existing dirty columns are updated * @param bool $allowReset If true, updating existing columns with existing value will reset dirty flag * * @return Enlight_Config_Adapter_DbTable */
/** * {@inheritdoc} */
  public function getFormId() {
    return 'layout_builder_remove_section';
  }

  /** * {@inheritdoc} */
  public function getQuestion() {
    $configuration = $this->sectionStorage->getSection($this->delta)->getLayoutSettings();
    // Layouts may choose to use a class that might not have a label     // configuration.     if (!empty($configuration['label'])) {
      return $this->t('Are you sure you want to remove @section?', ['@section' => $configuration['label']]);
    }
    return $this->t('Are you sure you want to remove section @section?', ['@section' => $this->delta + 1]);
  }

  /** * {@inheritdoc} */
  

  public function buildForm(array $form, FormStateInterface $form_state, SectionStorageInterface $section_storage = NULL, $delta = NULL, $region = NULL, $uuid = NULL) {
    $component = $section_storage->getSection($delta)->getComponent($uuid);
    $form['#attributes']['data-layout-builder-target-highlight-id'] = $this->blockUpdateHighlightId($uuid);
    return $this->doBuildForm($form$form_state$section_storage$delta$component);
  }

  /** * {@inheritdoc} */
  protected function submitLabel() {
    return $this->t('Update');
  }

}

  public function buildForm(array $form, FormStateInterface $form_state, SectionStorageInterface $section_storage = NULL, $delta = NULL, $region = NULL, $plugin_id = NULL) {
    // Only generate a new component once per form submission.     if (!$component = $form_state->get('layout_builder__component')) {
      $component = new SectionComponent($this->uuidGenerator->generate()$region['id' => $plugin_id]);
      $section_storage->getSection($delta)->appendComponent($component);
      $form_state->set('layout_builder__component', $component);
    }
    $form['#attributes']['data-layout-builder-target-highlight-id'] = $this->blockAddHighlightId($delta$region);
    return $this->doBuildForm($form$form_state$section_storage$delta$component);
  }

}
'name' => 'The test entity',
      OverridesSectionStorage::FIELD_NAME => $section_data,
    ]);
    $entity->save();
    return $entity->get(OverridesSectionStorage::FIELD_NAME);
  }

  /** * @covers ::equals */
  public function testEquals() {
    $this->sectionList->getSection(0)->setLayoutSettings(['foo' => 1]);

    $second_section_storage = clone $this->sectionList;
    $this->assertTrue($this->sectionList->equals($second_section_storage));

    $second_section_storage->getSection(0)->setLayoutSettings(['foo' => '1']);
    $this->assertFalse($this->sectionList->equals($second_section_storage));
  }

  /** * @covers ::equals */
  
Home | Imprint | This part of the site doesn't use cookies.