getRegions example

$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']]
        );
      }
    }

    // $this->region and $this->delta are where the block is currently placed.     // $selected_region and $selected_delta are the values from this form     // specifying where the block should be moved to.

  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.'),
    ];

    
$this->blockStorage = $entity_type_manager->getStorage('block');
    $this->themeManager = $theme_manager;
    $this->contextHandler = $context_handler;
  }

  /** * {@inheritdoc} */
  public function getVisibleBlocksPerRegion(array &$cacheable_metadata = []) {
    $active_theme = $this->themeManager->getActiveTheme();
    // Build an array of the region names in the right order.     $empty = array_fill_keys($active_theme->getRegions()[]);

    $full = [];
    foreach ($this->blockStorage->loadByProperties(['theme' => $active_theme->getName()]) as $block_id => $block) {
      /** @var \Drupal\block\BlockInterface $block */
      $access = $block->access('view', NULL, TRUE);
      $region = $block->getRegion();
      if (!isset($cacheable_metadata[$region])) {
        $cacheable_metadata[$region] = CacheableMetadata::createFromObject($access);
      }
      else {
        $cacheable_metadata[$region] = $cacheable_metadata[$region]->merge(CacheableMetadata::createFromObject($access));
      }
// Generate a #type => page render array using the page display variant,       // the page display will build the content for the various page regions.       $page = [
        '#type' => 'page',
      ];
      $page += $page_display->build();
    }

    // $page is now fully built. Find all non-empty page regions, and add a     // theme wrapper function that allows them to be consistently themed.     $regions = $this->themeManager->getActiveTheme()->getRegions();
    foreach ($regions as $region) {
      if (!empty($page[$region])) {
        $page[$region]['#theme_wrappers'][] = 'region';
        $page[$region]['#region'] = $region;
      }
    }

    // Allow hooks to add attachments to $page['#attached'].     $this->renderer->executeInRenderContext(new RenderContext()function D) use (&$page) {
      $this->invokePageAttachmentHooks($page);
    });

    
$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);
    $this->assertInstanceOf(TranslatableMarkup::class$regions['left']['label']);
    $this->assertInstanceOf(TranslatableMarkup::class$regions['right']['label']);

    $layout_definition = $this->layoutPluginManager->getDefinition('module_a_provided_layout');
    $this->assertSame('module_a_provided_layout', $layout_definition->id());
    $this->assertSame('1 column layout', (string) $layout_definition->getLabel());
    $this->assertSame('Columns: 1', (string) $layout_definition->getCategory());
    $this->assertSame('A module provided layout', (string) $layout_definition->getDescription());
    $this->assertInstanceOf(TranslatableMarkup::class$layout_definition->getLabel());
    $this->assertInstanceOf(TranslatableMarkup::class$layout_definition->getCategory());
    
$this->regions = $regions;
    return $this;
  }

  /** * Gets the machine-readable region names. * * @return string[] * An array of machine-readable region names. */
  public function getRegionNames() {
    return array_keys($this->getRegions());
  }

  /** * Gets the human-readable region labels. * * @return string[] * An array of human-readable region labels. */
  public function getRegionLabels() {
    $regions = $this->getRegions();
    return array_combine(array_keys($regions)array_column($regions, 'label'));
  }
$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';
          $build[$region][$uuid]['#attributes']['data-layout-block-uuid'] = $uuid;
          $build[$region][$uuid]['#attributes']['data-layout-builder-highlight-id'] = $this->blockUpdateHighlightId($uuid);
          $build[$region][$uuid]['#contextual_links'] = [
            'layout_builder_block' => [
              'route_parameters' => [
                'section_storage_type' => $storage_type,
                'section_storage' => $storage_id,
                

  }

  /** * Returns an associative array of all regions. * * @return array * An array containing the region options. */
  public function getRegionOptions() {
    $options = [];
    foreach ($this->getRegions() as $region => $data) {
      $options[$region] = $data['title'];
    }
    return $options;
  }

  /** * Collects the definitions of fields whose display is configurable. * * @return \Drupal\Core\Field\FieldDefinitionInterface[] * The array of field definitions */
  
$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);
  }

  


  /** * 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 will be handled by the code in
Home | Imprint | This part of the site doesn't use cookies.