QuickEditController::renderField

protected QuickEditController::renderField(EntityInterface $entity, $field_name, $langcode, $view_mode_id)

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()

File

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

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->entityManager()->getViewModes($entity->getEntityTypeId()));
  if (in_array($view_mode_id, $entity_view_mode_ids)) {
    $entity = \Drupal::entityManager()->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 = array($entity, $field_name, $view_mode_id, $langcode);
    $output = $this->moduleHandler()->invoke($module, 'quickedit_render_field', $args);
  }

  return $this->renderer->renderRoot($output);
}
doc_Drupal
2016-10-29 09:36:10
Comments
Leave a Comment

Please login to continue.