You are here

ListBase.php in Double Field 4.x

Same filename and directory in other branches
  1. 8.3 src/Plugin/Field/FieldFormatter/ListBase.php

File

src/Plugin/Field/FieldFormatter/ListBase.php
View source
<?php

namespace Drupal\double_field\Plugin\Field\FieldFormatter;

use Drupal\Core\Form\FormStateInterface;

/**
 * Base class for list formatters.
 */
abstract class ListBase extends Base {

  /**
   * {@inheritdoc}
   */
  public static function defaultSettings() : array {
    return [
      'inline' => TRUE,
    ] + parent::defaultSettings();
  }

  /**
   * {@inheritdoc}
   */
  public function settingsForm(array $form, FormStateInterface $form_state) : array {
    $element = parent::settingsForm($form, $form_state);
    $settings = $this
      ->getSettings();
    $element['inline'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Display as inline element'),
      '#default_value' => $settings['inline'],
      '#weight' => -10,
    ];
    return $element;
  }

  /**
   * {@inheritdoc}
   */
  public function settingsSummary() : array {
    $summary = [];
    if ($this
      ->getSetting('inline')) {
      $summary[] = $this
        ->t('Display as inline element');
    }
    return array_merge($summary, parent::settingsSummary());
  }

}

Classes

Namesort descending Description
ListBase Base class for list formatters.