function LayoutBuilderIntegration::quickEditRenderField

Re-renders a field rendered by Layout Builder, edited with Quick Edit.

Parameters

\Drupal\Core\Entity\FieldableEntityInterface $entity: The entity.

string $field_name: The field name.

string $quick_edit_view_mode_id: The Quick Edit view mode ID.

string $langcode: The language code.

Return value

array The re-rendered field.

File

core/modules/quickedit/src/LayoutBuilderIntegration.php, line 249

Class

LayoutBuilderIntegration
Helper methods for Layout Builder module integration.

Namespace

Drupal\quickedit

Code

public function quickEditRenderField(FieldableEntityInterface $entity, $field_name, $quick_edit_view_mode_id, $langcode) {
    [
        $entity_view_mode,
        $delta,
        $component_uuid,
    ] = static::deconstructViewModeId($quick_edit_view_mode_id);
    $entity_build = $this->entityTypeManager
        ->getViewBuilder($entity->getEntityTypeId())
        ->view($entity, $entity_view_mode, $langcode);
    $this->buildEntityView($entity_build);
    if (isset($entity_build['_layout_builder'][$delta])) {
        foreach (Element::children($entity_build['_layout_builder'][$delta]) as $region) {
            if (isset($entity_build['_layout_builder'][$delta][$region][$component_uuid])) {
                return $entity_build['_layout_builder'][$delta][$region][$component_uuid]['content'];
            }
        }
    }
    $this->getLogger('layout_builder')
        ->warning('The field "%field" failed to render.', [
        '%field' => $field_name,
    ]);
    return [];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.