You are here

public function BlazyAdminFormatterBase::getSettingsSummary in Blazy 8.2

Same name and namespace in other branches
  1. 8 src/Form/BlazyAdminFormatterBase.php \Drupal\blazy\Form\BlazyAdminFormatterBase::getSettingsSummary()
  2. 7 src/Form/BlazyAdminFormatterBase.php \Drupal\blazy\Form\BlazyAdminFormatterBase::getSettingsSummary()

Return the field formatter settings summary.

1 call to BlazyAdminFormatterBase::getSettingsSummary()
BlazyAdminFormatterBase::settingsSummary in src/Form/BlazyAdminFormatterBase.php
Return the field formatter settings summary.

File

src/Form/BlazyAdminFormatterBase.php, line 76

Class

BlazyAdminFormatterBase
A base for field formatter admin to have re-usable methods in one place.

Namespace

Drupal\blazy\Form

Code

public function getSettingsSummary($definition = []) {
  if (empty($definition['settings'])) {
    return [];
  }
  $this
    ->getExcludedSettingsSummary($definition);
  $enforced = [
    'optionset',
    'cache',
    'skin',
    'view_mode',
    'override',
    'overridables',
    'style',
    'vanilla',
  ];
  $summary = [];
  $enforced = isset($definition['enforced']) ? $definition['enforced'] : $enforced;
  $settings = array_filter($definition['settings']);
  foreach ($definition['settings'] as $key => $setting) {
    $title = Unicode::ucfirst(str_replace('_', ' ', $key));
    $vanilla = !empty($settings['vanilla']);

    // @todo remove deprecated breakpoints anytime before 3.x.
    if ($key == 'breakpoints') {
      continue;
    }
    if ($vanilla && !in_array($key, $enforced)) {
      continue;
    }
    if ($key == 'override' && empty($setting)) {
      unset($settings['overridables']);
    }
    if (is_bool($setting) && $setting) {
      $setting = 'yes';
    }
    elseif (is_array($setting)) {
      $setting = array_filter($setting);
      if (!empty($setting)) {
        $setting = implode(', ', $setting);
      }
    }
    if ($key == 'cache') {
      $setting = $this
        ->getCacheOptions()[$setting];
    }
    if (empty($setting)) {
      continue;
    }
    if (isset($settings[$key]) && is_string($setting)) {
      $summary[] = $this
        ->t('@title: <strong>@setting</strong>', [
        '@title' => $title,
        '@setting' => $setting,
      ]);
    }
  }
  return $summary;
}