getLayoutId example

$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. */
/** * Gets the layout plugin for this section. * * @param \Drupal\Core\Plugin\Context\ContextInterface[] $contexts * An array of available contexts. * * @return \Drupal\Core\Layout\LayoutInterface * The layout plugin. */
  public function getLayout(array $contexts = []) {
    $layout = $this->layoutPluginManager()->createInstance($this->getLayoutId()$this->layoutSettings);
    if ($contexts) {
      $this->contextHandler()->applyContextMapping($layout$contexts);
    }
    return $layout;
  }

  /** * Gets the layout plugin ID for this section. * * @return string * The layout plugin ID. * * @internal * This method should only be used by code responsible for storing the data. */
'#markup' => 'Non-configurable',
      ],
      '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',
      ],
      

  protected $layoutPluginManager;

  /** * Overrides \Drupal\field_ui\Form\EntityDisplayFormBase::getRegions(). */
  public function getRegions() {
    $regions = [];

    $layout_definition = $this->layoutPluginManager->getDefinition($this->getEntity()->getLayoutId());
    foreach ($layout_definition->getRegions() as $name => $region) {
      $regions[$name] = [
        'title' => $region['label'],
        'message' => $this->t('No field is displayed.'),
      ];
    }

    $regions['hidden'] = [
      'title' => $this->t('Disabled', []['context' => 'Plural']),
      'message' => $this->t('No field is hidden.'),
    ];

    
/** * Applies the layout to an entity build. * * @param array $build * A renderable array representing the entity content or form. * @param \Drupal\field_layout\Display\EntityDisplayWithLayoutInterface $display * The entity display holding the display options configured for the entity * components. */
  public function buildView(array &$build, EntityDisplayWithLayoutInterface $display) {
    $layout_definition = $this->layoutPluginManager->getDefinition($display->getLayoutId(), FALSE);
    if ($layout_definition && $fields = $this->getFields($build$display, 'view')) {
      // Add the regions to the $build in the correct order.       $regions = array_fill_keys($layout_definition->getRegionNames()[]);

      foreach ($fields as $name => $field) {
        // If the region is controlled by the layout, move the field from the         // top-level of $build into a region-specific section. Custom regions         // could be set by other code at run-time; these should be ignored.         // @todo Ideally the array structure would remain unchanged, see         // https://www.drupal.org/node/2846393.         if (isset($regions[$field['region']])) {
          
/** * Implements \Drupal\field_layout\Display\EntityDisplayWithLayoutInterface::getLayoutSettings(). */
  public function getLayoutSettings() {
    return $this->getThirdPartySetting('field_layout', 'settings', []);
  }

  /** * Implements \Drupal\field_layout\Display\EntityDisplayWithLayoutInterface::setLayoutId(). */
  public function setLayoutId($layout_id, array $layout_settings = []) {
    if ($this->getLayoutId() !== $layout_id) {
      // @todo Devise a mechanism for mapping old regions to new ones in       // https://www.drupal.org/node/2796877.       $layout_definition = $this->getLayoutDefinition($layout_id);
      $new_region = $layout_definition->getDefaultRegion();
      $layout_regions = $layout_definition->getRegions();
      foreach ($this->getComponents() as $name => $component) {
        if (isset($component['region']) && !isset($layout_regions[$component['region']])) {
          $component['region'] = $new_region;
          $this->setComponent($name$component);
        }
      }
    }

  protected function hasBlankSection() {
    // A blank section will only ever exist when the delta is 0, as added by     // ::removeSection().     return $this->hasSection(0) && $this->getSection(0)->getLayoutId() === 'layout_builder_blank';
  }

  /** * {@inheritdoc} */
  public function removeSection($delta) {
    // Clear the section list if there is currently a blank section.     if ($this->hasBlankSection()) {
      $this->removeAllSections();
    }

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