You are here

public function DoubleField::settingsSummary in Double Field 8.3

Returns a short summary for the current widget settings.

If an empty result is returned, a UI can still be provided to display a settings form in case the widget has configurable settings.

Return value

array A short summary of the widget settings.

Overrides WidgetBase::settingsSummary

File

src/Plugin/Field/FieldWidget/DoubleField.php, line 185

Class

DoubleField
Plugin implementation of the 'double_field' widget.

Namespace

Drupal\double_field\Plugin\Field\FieldWidget

Code

public function settingsSummary() {
  $settings = $this
    ->getSettings();
  $field_settings = $this
    ->getFieldSettings();
  $subfield_types = DoubleFieldItem::subfieldTypes();
  $summary = [];
  if ($settings['inline']) {
    $summary[] = $this
      ->t('Display as inline element');
  }
  foreach ([
    'first',
    'second',
  ] as $subfield) {
    $subfield_type = $subfield_types[$field_settings['storage'][$subfield]['type']];
    $summary[] = new FormattableMarkup('<b>@subfield - @subfield_type</b>', [
      '@subfield' => $subfield == 'first' ? $this
        ->t('First subfield') : $this
        ->t('Second subfield'),
      '@subfield_type' => strtolower($subfield_type),
    ]);
    $summary[] = $this
      ->t('Widget: @type', [
      '@type' => $settings[$subfield]['type'],
    ]);
    if (self::isLabelSupported($settings[$subfield]['type'])) {
      $summary[] = $this
        ->t('Label display: @label', [
        '@label' => $settings[$subfield]['label_display'],
      ]);
    }
    switch ($settings[$subfield]['type']) {
      case 'textfield':
      case 'email':
      case 'tel':
      case 'url':
        $summary[] = $this
          ->t('Size: @size', [
          '@size' => $settings[$subfield]['size'],
        ]);
        if ($settings[$subfield]['placeholder'] != '') {
          $summary[] = $this
            ->t('Placeholder: @placeholder', [
            '@placeholder' => $settings[$subfield]['placeholder'],
          ]);
        }
        break;
      case 'checkbox':
        $summary[] = $this
          ->t('Label: @label', [
          '@label' => $settings[$subfield]['label'],
        ]);
        break;
      case 'select':
        break;
      case 'textarea':
        $summary[] = $this
          ->t('Columns: @cols', [
          '@cols' => $settings[$subfield]['cols'],
        ]);
        $summary[] = $this
          ->t('Rows: @rows', [
          '@rows' => $settings[$subfield]['rows'],
        ]);
        if ($settings[$subfield]['placeholder'] != '') {
          $summary[] = $this
            ->t('Placeholder: @placeholder', [
            '@placeholder' => $settings[$subfield]['placeholder'],
          ]);
        }
        break;
    }
    if ($settings[$subfield]['prefix'] != '') {
      $summary[] = $this
        ->t('Prefix (deprecated): @prefix', [
        '@prefix' => $settings[$subfield]['prefix'],
      ]);
    }
    if ($settings[$subfield]['suffix'] != '') {
      $summary[] = $this
        ->t('Suffix (deprecated): @suffix', [
        '@suffix' => $settings[$subfield]['suffix'],
      ]);
    }
  }
  return $summary;
}