You are here

public function BlazyAdminFormatterBase::getSettingsSummary in Blazy 8

Same name and namespace in other branches
  1. 8.2 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 70

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 = []) {
  $summary = [];
  if (empty($definition['settings'])) {
    return $summary;
  }
  $this
    ->getExcludedSettingsSummary($definition);
  $enforced = [
    'optionset',
    'cache',
    'skin',
    'view_mode',
    'override',
    'overridables',
    'style',
    'vanilla',
  ];
  $enforced = isset($definition['enforced']) ? $definition['enforced'] : $enforced;
  $settings = array_filter($definition['settings']);
  $breakpoints = isset($settings['breakpoints']) && is_array($settings['breakpoints']) ? array_filter($settings['breakpoints']) : [];
  foreach ($definition['settings'] as $key => $setting) {
    $title = Unicode::ucfirst(str_replace('_', ' ', $key));
    $vanilla = !empty($settings['vanilla']);
    if ($key == 'breakpoints') {
      $widths = [];
      if ($breakpoints) {
        foreach ($breakpoints as $breakpoint) {
          if (!empty($breakpoint['width'])) {
            $widths[] = $breakpoint['width'];
          }
        }
      }
      $title = 'Breakpoints';
      $setting = $widths ? implode(', ', $widths) : 'none';
    }
    else {
      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;
}