Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. FieldLayoutBuilder.php

function 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_layout

Code

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal