You are here

public function FieldRedirectionFormatter::settingsSummary in Field Redirection 8.2

Returns a short summary for the current formatter settings.

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

Return value

string[] A short summary of the formatter settings.

Overrides FormatterBase::settingsSummary

File

src/Plugin/Field/FieldFormatter/FieldRedirectionFormatter.php, line 170

Class

FieldRedirectionFormatter
Plugin implementation of the 'field_redirection_formatter' formatter.

Namespace

Drupal\field_redirection\Plugin\Field\FieldFormatter

Code

public function settingsSummary() {
  $summary = [];
  $settings = $this
    ->getSettings();

  // Display a "hair on fire" warning message for any view mode other than
  // "full".
  if ($this->viewMode != 'full') {
    $this
      ->messenger()
      ->addWarning($this
      ->t('Danger! The Redirect formatter should not be used with any view mode other than "Full content".'));
  }
  if (!empty($settings['code'])) {
    $summary[] = $this
      ->t('HTTP status code: @code', [
      '@code' => $this->httpCodes[$settings['code']],
    ]);
  }
  if ($settings['404_if_empty']) {
    $summary[] = $this
      ->t('Will return 404 (page not found) if field is empty.');
  }
  if (!empty($settings['page_restrictions'])) {
    $page_restrictions = $this->pageRestrictionOptions;
    $summary[] = $this
      ->t('Page restriction options: @pagerestriction', [
      '@pagerestriction' => $page_restrictions[$settings['page_restrictions']],
    ]);
  }
  return $summary;
}