You are here

private function LayoutBuilderEntityViewDisplay::getSectionComponentForFieldName in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay::getSectionComponentForFieldName()

Gets the component for a given field name if any.

Parameters

string $field_name: The field name.

Return value

\Drupal\layout_builder\SectionComponent|null The section component if it is available.

1 call to LayoutBuilderEntityViewDisplay::getSectionComponentForFieldName()
LayoutBuilderEntityViewDisplay::getComponent in core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php
Gets the display options set for a component.

File

core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php, line 557

Class

LayoutBuilderEntityViewDisplay
Provides an entity view display entity that has a layout.

Namespace

Drupal\layout_builder\Entity

Code

private function getSectionComponentForFieldName($field_name) {

  // Loop through every component until the first match is found.
  foreach ($this
    ->getSections() as $section) {
    foreach ($section
      ->getComponents() as $component) {
      $plugin = $component
        ->getPlugin();
      if ($plugin instanceof DerivativeInspectionInterface && $plugin
        ->getBaseId() === 'field_block') {

        // FieldBlock derivative IDs are in the format
        // [entity_type]:[bundle]:[field].
        list(, , $field_block_field_name) = explode(PluginBase::DERIVATIVE_SEPARATOR, $plugin
          ->getDerivativeId());
        if ($field_block_field_name === $field_name) {
          return $component;
        }
      }
    }
  }
  return NULL;
}