You are here

protected function NameAdditionalPreferredTrait::settingsNameAdditionalPreferredSummary in Name Field 8

1 call to NameAdditionalPreferredTrait::settingsNameAdditionalPreferredSummary()
NameFormatter::settingsSummary in src/Plugin/Field/FieldFormatter/NameFormatter.php
Returns a short summary for the current formatter settings.

File

src/Traits/NameAdditionalPreferredTrait.php, line 83

Class

NameAdditionalPreferredTrait
Name form for preferred and alternative settings trait.

Namespace

Drupal\name\Traits

Code

protected function settingsNameAdditionalPreferredSummary(&$summary) {
  if ($type = $this
    ->getSetting('preferred_field_reference')) {
    $targets = $this
      ->getAdditionalSources();
    $summary[] = $this
      ->t('Preferred: @label', [
      '@label' => empty($targets[$type]) ? t('-- invalid --') : $targets[$type],
    ]);
  }
  elseif (!$this
    ->getTraitUsageIsField()) {
    if ($type = $this->fieldDefinition
      ->getSetting('preferred_field_reference')) {
      $targets = $this
        ->getAdditionalSources();
      $summary[] = $this
        ->t('Preferred: field default (@label)', [
        '@label' => empty($targets[$type]) ? t('-- invalid --') : $targets[$type],
      ]);
    }
    else {
      $summary[] = $this
        ->t('Preferred: field default (-- none --)');
    }
  }
  if ($type = $this
    ->getSetting('alternative_field_reference')) {
    $targets = $this
      ->getAdditionalSources();
    $summary[] = $this
      ->t('Alternative: @label', [
      '@label' => empty($targets[$type]) ? t('-- invalid --') : $targets[$type],
    ]);
  }
  elseif (!$this
    ->getTraitUsageIsField()) {
    if ($type = $this->fieldDefinition
      ->getSetting('alternative_field_reference')) {
      $targets = $this
        ->getAdditionalSources();
      $summary[] = $this
        ->t('Alternative: field default (@label)', [
        '@label' => empty($targets[$type]) ? t('-- invalid --') : $targets[$type],
      ]);
    }
    else {
      $summary[] = $this
        ->t('Alternative: field default (-- none --)');
    }
  }
}