function LayoutBuilderEntityViewDisplay::getSectionComponentForFieldName
Same name in other branches
- 9 core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay::getSectionComponentForFieldName()
- 8.9.x core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay::getSectionComponentForFieldName()
- 11.x 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 511
Class
- LayoutBuilderEntityViewDisplay
- Provides an entity view display entity that has a layout.
Namespace
Drupal\layout_builder\EntityCode
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 && in_array($plugin->getBaseId(), [
'field_block',
'extra_field_block',
], TRUE)) {
// FieldBlock derivative IDs are in the format
// [entity_type]:[bundle]:[field].
[
,
,
$field_block_field_name,
] = explode(PluginBase::DERIVATIVE_SEPARATOR, $plugin->getDerivativeId());
if ($field_block_field_name === $field_name) {
return $component;
}
}
}
}
return NULL;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.