getComponentsByRegion example

/** * Returns the next highest weight of the component in a region. * * @param string $region * The region name. * * @return int * A number higher than the highest weight of the component in the region. */
  protected function getNextHighestWeight($region) {
    $components = $this->getComponentsByRegion($region);
    $weights = array_map(function DSectionComponent $component) {
      return $component->getWeight();
    }$components);
    return $weights ? max($weights) + 1 : 0;
  }

  /** * Gets the components for a specific region. * * @param string $region * The region name. * * @return \Drupal\layout_builder\SectionComponent[] * An array of components in the specified region, sorted by weight. */
'container' => [
          '#attributes' => [
            'id' => 'layout-builder-components-table',
            'class' => ['layout-builder-components-table'],
            'aria-label' => $aria_label,
          ],
        ],
      ],
    ];

    /** @var \Drupal\layout_builder\SectionComponent[] $components */
    $components = $current_section->getComponentsByRegion($selected_region);

    // If the component is not in this region, add it to the listed components.     if (!isset($components[$uuid])) {
      $components[$uuid] = $sections[$delta]->getComponent($uuid);
    }
    $state_weight_delta = round(count($components) / 2);
    foreach ($components as $component_uuid => $component) {
      /** @var \Drupal\Core\Block\BlockPluginInterface $plugin */
      $plugin = $component->getPlugin();
      $is_current_block = $component_uuid === $uuid;
      $row_classes = [
        
Home | Imprint | This part of the site doesn't use cookies.