You are here

public function SlickTextFormatter::viewElements in Slick Carousel 7.3

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldFormatter/SlickTextFormatter.php \Drupal\slick\Plugin\Field\FieldFormatter\SlickTextFormatter::viewElements()
  2. 8 src/Plugin/Field/FieldFormatter/SlickTextFormatter.php \Drupal\slick\Plugin\Field\FieldFormatter\SlickTextFormatter::viewElements()

Implements hook_field_formatter_view().

Overrides SlickFormatterTrait::viewElements

File

src/Plugin/Field/FieldFormatter/SlickTextFormatter.php, line 45

Class

SlickTextFormatter
Plugin implementation of the 'Slick Text' formatter.

Namespace

Drupal\slick\Plugin\Field\FieldFormatter

Code

public function viewElements($items, $entity) {
  $settings = $this
    ->buildSettings();

  // Hand over to default formatter if not multiple.
  // @todo figure out to disable formatter like isApplicable() at D8 in the
  // first place, and remove this.
  if (!$this->isMultiple) {
    $types = field_info_field_types($this->fieldDefinition['type']);
    $display['type'] = isset($types['default_formatter']) ? $types['default_formatter'] : '';
    if ($fallback = text_field_formatter_view($settings['entity_type_id'], $entity, $this->fieldDefinition, $this->fieldInstance, $this->langcode, $items, $display)) {
      return $fallback;
    }
  }
  $settings['vanilla'] = TRUE;

  // Build the settings.
  $build = [
    'settings' => $settings,
  ];

  // Modifies settings before building elements.
  $this
    ->formatter()
    ->preBuildElements($build, $items, $entity);

  // Build the elements.
  $this
    ->buildElements($build, $items);

  // If using 0, or directly passed like D8, taken over by theme_field().
  $element = $this
    ->manager()
    ->build($build);
  return $element;
}