You are here

public function GridStackEntityFormatterBase::buildElement in GridStack 8.2

File

src/Plugin/Field/FieldFormatter/GridStackEntityFormatterBase.php, line 41

Class

GridStackEntityFormatterBase
Base class for gridstack entity reference formatters without field details.

Namespace

Drupal\gridstack\Plugin\Field\FieldFormatter

Code

public function buildElement(array &$build, $entity, $langcode) {
  $view_mode = empty($build['settings']['view_mode']) ? 'full' : $build['settings']['view_mode'];
  $delta = $build['settings']['delta'];

  // Adds element box to contain any entity as expected by GridStackManager.
  $build['items'][$delta] = [
    'box' => $this
      ->formatter()
      ->getEntityTypeManager()
      ->getViewBuilder($entity
      ->getEntityTypeId())
      ->view($entity, $view_mode, $langcode),
  ];
}