You are here

public function QuickEditIntegration::quickEditRenderField in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/layout_builder/src/QuickEditIntegration.php \Drupal\layout_builder\QuickEditIntegration::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/layout_builder/src/QuickEditIntegration.php, line 249

Class

QuickEditIntegration
Helper methods for Quick Edit module integration.

Namespace

Drupal\layout_builder

Code

public function quickEditRenderField(FieldableEntityInterface $entity, $field_name, $quick_edit_view_mode_id, $langcode) {
  list($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 [];
}