function QuickEditController::renderField

Same name in other branches
  1. 9 core/modules/quickedit/src/QuickEditController.php \Drupal\quickedit\QuickEditController::renderField()

Renders a field.

If the view mode ID is not an Entity Display view mode ID, then the field was rendered using a custom render pipeline (not the Entity/Field API render pipeline).

An example could be Views' render pipeline. In that case, the view mode ID would probably contain the View's ID, display and the row index.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity being edited.

string $field_name: The name of the field that is being edited.

string $langcode: The name of the language for which the field is being edited.

string $view_mode_id: The view mode the field should be rerendered in. Either an Entity Display view mode ID, or a custom one. See hook_quickedit_render_field().

Return value

\Drupal\Component\Render\MarkupInterface Rendered HTML.

See also

hook_quickedit_render_field()

1 call to QuickEditController::renderField()
QuickEditController::fieldForm in core/modules/quickedit/src/QuickEditController.php
Returns a single field edit form as an Ajax response.

File

core/modules/quickedit/src/QuickEditController.php, line 318

Class

QuickEditController
Returns responses for Quick Edit module routes.

Namespace

Drupal\quickedit

Code

protected function renderField(EntityInterface $entity, $field_name, $langcode, $view_mode_id) {
    $entity_view_mode_ids = array_keys($this->entityDisplayRepository
        ->getViewModes($entity->getEntityTypeId()));
    if (in_array($view_mode_id, $entity_view_mode_ids)) {
        $entity = $this->entityRepository
            ->getTranslationFromContext($entity, $langcode);
        $output = $entity->get($field_name)
            ->view($view_mode_id);
    }
    else {
        // Each part of a custom (non-Entity Display) view mode ID is separated
        // by a dash; the first part must be the module name.
        $mode_id_parts = explode('-', $view_mode_id, 2);
        $module = reset($mode_id_parts);
        $args = [
            $entity,
            $field_name,
            $view_mode_id,
            $langcode,
        ];
        $output = $this->moduleHandler()
            ->invoke($module, 'quickedit_render_field', $args);
    }
    return $this->renderer
        ->renderRoot($output);
}

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