You are here

trait SlickFormatterTrait in Slick Carousel 7.3

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldFormatter/SlickFormatterTrait.php \Drupal\slick\Plugin\Field\FieldFormatter\SlickFormatterTrait
  2. 8 src/Plugin/Field/FieldFormatter/SlickFormatterTrait.php \Drupal\slick\Plugin\Field\FieldFormatter\SlickFormatterTrait

A Trait common for slick formatters.

Hierarchy

File

src/Plugin/Field/FieldFormatter/SlickFormatterTrait.php, line 11

Namespace

Drupal\slick\Plugin\Field\FieldFormatter
View source
trait SlickFormatterTrait {
  use BlazyFormatterTrait;

  /**
   * Returns the slick admin service.
   */
  public function admin() {
    if (!isset($this->admin)) {
      $this->admin = new SlickAdmin($this->manager);
    }
    return $this->admin;
  }

  /**
   * {@inheritdoc}
   */
  public function viewElements($items, $entity) {
    $entities = $this
      ->getEntitiesToView($items);

    // Early opt-out if the field is empty.
    if (empty($entities)) {
      return [];
    }

    // Collects specific settings to this formatter.
    $this->entity = $entity;
    $settings = $this
      ->buildSettings();
    $build = [
      'settings' => $settings,
    ];

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

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

    // Modifies settings post building elements.
    $this
      ->formatter()
      ->postBuildElements($build, $entities, $entity);

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

}

Members

Namesort descending Modifiers Type Description Overrides
BlazyFormatterTrait::$formatter protected property The blazy-related formatter service.
BlazyFormatterTrait::$manager protected property The blazy field formatter manager.
BlazyFormatterTrait::formatter public function Returns the blazy-related formatter.
BlazyFormatterTrait::manager public function Returns the blazy service.
BlazyFormatterTrait::settingsSummary public function
SlickFormatterTrait::admin public function Returns the slick admin service.
SlickFormatterTrait::viewElements public function 1