function FieldLayoutBuilder::getFields
Same name in other branches
- 9 core/modules/field_layout/src/FieldLayoutBuilder.php \Drupal\field_layout\FieldLayoutBuilder::getFields()
- 8.9.x core/modules/field_layout/src/FieldLayoutBuilder.php \Drupal\field_layout\FieldLayoutBuilder::getFields()
- 10 core/modules/field_layout/src/FieldLayoutBuilder.php \Drupal\field_layout\FieldLayoutBuilder::getFields()
Gets the fields that need to be processed.
Parameters
array $build: A renderable array representing the entity content or form.
\Drupal\field_layout\Display\EntityDisplayWithLayoutInterface $display: The entity display holding the display options configured for the entity components.
string $display_context: The display context, either 'form' or 'view'.
Return value
array An array of configurable fields present in the build.
2 calls to FieldLayoutBuilder::getFields()
- FieldLayoutBuilder::buildForm in core/
modules/ field_layout/ src/ FieldLayoutBuilder.php - Applies the layout to an entity form.
- FieldLayoutBuilder::buildView in core/
modules/ field_layout/ src/ FieldLayoutBuilder.php - Applies the layout to an entity build.
File
-
core/
modules/ field_layout/ src/ FieldLayoutBuilder.php, line 138
Class
- FieldLayoutBuilder
- Builds a field layout.
Namespace
Drupal\field_layoutCode
protected function getFields(array $build, EntityDisplayWithLayoutInterface $display, $display_context) {
$components = $display->getComponents();
// Ignore any extra fields from the list of field definitions. Field
// definitions can have a non-configurable display, but all extra fields are
// always displayed.
$field_definitions = array_diff_key($this->entityFieldManager
->getFieldDefinitions($display->getTargetEntityTypeId(), $display->getTargetBundle()), $this->entityFieldManager
->getExtraFields($display->getTargetEntityTypeId(), $display->getTargetBundle()));
$fields_to_exclude = array_filter($field_definitions, function (FieldDefinitionInterface $field_definition) use ($display_context) {
// Remove fields with a non-configurable display.
return !$field_definition->isDisplayConfigurable($display_context);
});
$components = array_diff_key($components, $fields_to_exclude);
// Only include fields present in the build.
$components = array_intersect_key($components, $build);
return $components;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.