You are here

function ief_table_view_mode_table_field_extra_field_callback in Inline Entity Form Table View Mode 8.2

Same name and namespace in other branches
  1. 8 ief_table_view_mode.module \ief_table_view_mode_table_field_extra_field_callback()

The callback function use from table field.

1 string reference to 'ief_table_view_mode_table_field_extra_field_callback'
EntityInlineTableViewModeForm::getTableFields in src/Form/EntityInlineTableViewModeForm.php
Gets the columns used to represent an entity in the IEF table.

File

./ief_table_view_mode.module, line 89
Defines a view mode to set up the columns of the table for the IEF widget.

Code

function ief_table_view_mode_table_field_extra_field_callback(EntityInterface $entity, $variables, $field_name) {

  /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager */
  $entityTypeManager = \Drupal::service('entity_type.manager');

  /** @var \Drupal\Core\Entity\EntityViewBuilderInterface $render_controller */
  $render_controller = $entityTypeManager
    ->getViewBuilder($entity
    ->getEntityTypeId());
  $view = $render_controller
    ->view($entity, EntityInlineTableViewModeForm::IEF_TABLE_VIEW_MODE_NAME);
  $render = $render_controller
    ->build($view);
  $value = isset($render[$field_name]) ? $render[$field_name] : [];

  // Prevent the exception \DomainException by #lazy_builder.
  // see https://www.drupal.org/project/ief_table_view_mode/issues/3178470
  if (!empty($value['#lazy_builder'])) {
    $value = [
      'content' => $value,
    ];
  }
  return $value;
}