getLayoutSettings example


      'non_configurable_field_with_extra_field' => [
        '#markup' => 'Non-configurable with extra field',
      ],
    ];

    $display = $this->prophesize(EntityDisplayWithLayoutInterface::class);
    $display->getTargetEntityTypeId()->willReturn('the_entity_type_id');
    $display->getTargetBundle()->willReturn('the_entity_type_bundle');
    $display->getLayout()->willReturn($this->layoutPlugin);
    $display->getLayoutId()->willReturn('two_column');
    $display->getLayoutSettings()->willReturn([]);
    $display->getComponents()->willReturn([
      'test1' => [
        'region' => 'right',
      ],
      'test2' => [
        'region' => 'unknown_region',
      ],
      'non_configurable_field' => [
        'region' => 'left',
      ],
      'non_configurable_field_with_extra_field' => [
        

  public function setLayout(LayoutInterface $layout) {
    $this->setLayoutId($layout->getPluginId()$layout->getConfiguration());
    return $this;
  }

  /** * Implements \Drupal\field_layout\Display\EntityDisplayWithLayoutInterface::getLayout(). */
  public function getLayout() {
    return $this->doGetLayout($this->getLayoutId()$this->getLayoutSettings());
  }

  /** * Gets the layout plugin. * * @param string $layout_id * A layout plugin ID. * @param array $layout_settings * An array of settings. * * @return \Drupal\Core\Layout\LayoutInterface * The layout plugin. */
/** * Returns an array representation of the section. * * Only use this method if you are implementing custom storage for sections. * * @return array * An array representation of the section component. */
  public function toArray() {
    return [
      'layout_id' => $this->getLayoutId(),
      'layout_settings' => $this->getLayoutSettings(),
      'components' => array_map(function DSectionComponent $component) {
        return $component->toArray();
      }$this->getComponents()),
      'third_party_settings' => $this->thirdPartySettings,
    ];
  }

  /** * Creates an object from an array representation of the section. * * Only use this method if you are implementing custom storage for sections. * * @param array $section * An array of section data in the format returned by ::toArray(). * * @return static * The section object. */


    $this->sectionList->removeSection(0);
    $this->sectionList->removeSection(0);
    $this->assertSections($expected);
  }

  /** * Tests __clone(). */
  public function testClone() {
    $this->assertSame(['setting_1' => 'Default']$this->sectionList->getSection(0)->getLayoutSettings());

    $new_section_storage = clone $this->sectionList;
    $new_section_storage->getSection(0)->setLayoutSettings(['asdf' => 'qwer']);
    $this->assertSame(['setting_1' => 'Default']$this->sectionList->getSection(0)->getLayoutSettings());
  }

  /** * Asserts that the field list has the expected sections. * * @param \Drupal\layout_builder\Section[] $expected * The expected sections. */

  public function buildForm(array $form, FormStateInterface $form_state, SectionStorageInterface $section_storage = NULL, $delta = NULL, $plugin_id = NULL) {
    $this->sectionStorage = $section_storage;
    $this->delta = $delta;
    $this->isUpdate = is_null($plugin_id);
    $this->pluginId = $plugin_id;

    $section = $this->getCurrentSection();

    if ($this->isUpdate) {
      if ($label = $section->getLayoutSettings()['label']) {
        $form['#title'] = $this->t('Configure @section', ['@section' => $label]);
      }
    }
    // Passing available contexts to the layout plugin here could result in an     // exception since the layout may not have a context mapping for a required     // context slot on creation.     $this->layout = $section->getLayout();

    $form_state->setTemporaryValue('gathered_contexts', $this->getPopulatedContexts($this->sectionStorage));
    $form['#tree'] = TRUE;
    $form['layout_settings'] = [];
    

  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])) {
        foreach (Element::children($build[$region]) as $uuid) {
          $build[$region][$uuid]['#attributes']['class'][] = 'js-layout-builder-block';
          $build[$region][$uuid]['#attributes']['class'][] = 'layout-builder-block';
          
/** * {@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} */
  
$this->uuid = $uuid;
    $this->region = $region;

    $form['#attributes']['data-layout-builder-target-highlight-id'] = $this->blockUpdateHighlightId($uuid);

    $sections = $section_storage->getSections();
    $contexts = $this->getPopulatedContexts($section_storage);
    $region_options = [];
    foreach ($sections as $section_delta => $section) {
      $layout = $section->getLayout($contexts);
      $layout_definition = $layout->getPluginDefinition();
      if (!($section_label = $section->getLayoutSettings()['label'])) {
        $section_label = $this->t('Section: @delta', ['@delta' => $section_delta + 1])->render();
      }
      foreach ($layout_definition->getRegions() as $region_name => $region_info) {
        // Group regions by section.         $region_options[$section_label]["$section_delta:$region_name"] = $this->t(
          '@section, Region: @region',
          ['@section' => $section_label, '@region' => $region_info['label']]
        );
      }
    }

    

  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. */

  protected function getLayout(EntityDisplayWithLayoutInterface $entity, FormStateInterface $form_state) {
    if (!$layout_plugin = $form_state->get('layout_plugin')) {
      $stored_layout_id = $entity->getLayoutId();
      // Use selected layout if it exists, falling back to the stored layout.       $layout_id = $form_state->getValue('field_layout', $stored_layout_id);
      // If the current layout is the stored layout, use the stored layout       // settings. Otherwise leave the settings empty.       $layout_settings = $layout_id === $stored_layout_id ? $entity->getLayoutSettings() : [];

      $layout_plugin = $this->layoutPluginManager->createInstance($layout_id$layout_settings);
      $form_state->set('layout_plugin', $layout_plugin);
    }
    return $layout_plugin;
  }

  /** * Ajax callback for the field layout settings form. */
  public static function settingsAjax($form, FormStateInterface $form_state) {
    
Home | Imprint | This part of the site doesn't use cookies.