getRegionNames example

public function __construct(array $configuration$plugin_id$plugin_definition) {
    parent::__construct($configuration$plugin_id$plugin_definition);
    $this->setConfiguration($configuration);
  }

  /** * {@inheritdoc} */
  public function build(array $regions) {
    // Ensure $build only contains defined regions and in the order defined.     $build = [];
    foreach ($this->getPluginDefinition()->getRegionNames() as $region_name) {
      if (array_key_exists($region_name$regions)) {
        $build[$region_name] = $regions[$region_name];
      }
    }
    $build['#in_preview'] = $this->inPreview;
    $build['#settings'] = $this->getConfiguration();
    $build['#layout'] = $this->pluginDefinition;
    $build['#theme'] = $this->pluginDefinition->getThemeHook();
    if ($library = $this->pluginDefinition->getLibrary()) {
      $build['#attached']['library'][] = $library;
    }
    

  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']])) {
          $regions[$field['region']][$name] = $build[$name];
          unset($build[$name]);
        }
      }
Home | Imprint | This part of the site doesn't use cookies.