getDefaultRegion example


  protected function init() {
    // Only populate defaults for "official" view modes and form modes.     if (!$this->initialized && $this->mode !== static::CUSTOM_MODE) {
      $this->initialized = TRUE;
      $default_region = $this->getDefaultRegion();
      // Fill in defaults for extra fields.       $context = $this->displayContext == 'view' ? 'display' : $this->displayContext;
      $extra_fields = \Drupal::service('entity_field.manager')->getExtraFields($this->targetEntityType, $this->bundle);
      $extra_fields = $extra_fields[$context] ?? [];
      foreach ($extra_fields as $name => $definition) {
        if (!isset($this->content[$name]) && !isset($this->hidden[$name])) {
          // Extra fields are visible by default unless they explicitly say so.           if (!isset($definition['visible']) || $definition['visible'] == TRUE) {
            $this->setComponent($name[
              'weight' => $definition['weight'],
            ]);
          }
// 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. */
  
$this->layoutSettings = $layout_settings;
    return $this;
  }

  /** * Gets the default region. * * @return string * The machine-readable name of the default region. */
  public function getDefaultRegion() {
    return $this->layoutPluginManager()->getDefinition($this->getLayoutId())->getDefaultRegion();
  }

  /** * Returns the components of the section. * * @return \Drupal\layout_builder\SectionComponent[] * An array of components, keyed by the component UUID. */
  public function getComponents() {
    return $this->components;
  }

  
$template = array_pop($template_parts);
      $template_path = $path;
      if (count($template_parts) > 0) {
        $template_path .= '/' . implode('/', $template_parts);
      }
      $definition->setTemplate($template);
      $definition->setThemeHook(strtr($template, '-', '_'));
      $definition->setTemplatePath($template_path);
    }

    if (!$definition->getDefaultRegion()) {
      $definition->setDefaultRegion(key($definition->getRegions()));
    }
    // Makes sure region names are translatable.     $regions = array_map(function D$region) {
      if (!$region['label'] instanceof TranslatableMarkup) {
        // Region labels from YAML discovery needs translation.         $region['label'] = new TranslatableMarkup($region['label'][]['context' => 'layout_region']);
      }
      return $region;
    }$definition->getRegions());
    $definition->setRegions($regions);
  }
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);
        }
      }
    }
    $this->setThirdPartySetting('field_layout', 'id', $layout_id);
    // Instantiate the plugin and consult it for the updated plugin     // configuration. Once layouts are no longer stored as third party settings,
$this->assertSame('Columns: 2', (string) $layout_definition->getCategory());
    $this->assertSame('A theme provided layout', (string) $layout_definition->getDescription());
    $this->assertInstanceOf(TranslatableMarkup::class$layout_definition->getLabel());
    $this->assertInstanceOf(TranslatableMarkup::class$layout_definition->getCategory());
    $this->assertInstanceOf(TranslatableMarkup::class$layout_definition->getDescription());
    $this->assertSame('twocol', $layout_definition->getTemplate());
    $this->assertSame('themes/theme_a/templates', $layout_definition->getPath());
    $this->assertSame('theme_a/twocol', $layout_definition->getLibrary());
    $this->assertSame('twocol', $layout_definition->getThemeHook());
    $this->assertSame('themes/theme_a/templates', $layout_definition->getTemplatePath());
    $this->assertSame('theme_a', $layout_definition->getProvider());
    $this->assertSame('right', $layout_definition->getDefaultRegion());
    $this->assertSame(LayoutDefault::class$layout_definition->getClass());
    $expected_regions = [
      'left' => [
        'label' => new TranslatableMarkup('Left region', []['context' => 'layout_region']),
      ],
      'right' => [
        'label' => new TranslatableMarkup('Right region', []['context' => 'layout_region']),
      ],
    ];
    $regions = $layout_definition->getRegions();
    $this->assertEquals($expected_regions$regions);
    
Home | Imprint | This part of the site doesn't use cookies.