You are here

public function BlazyAdminFormatterBase::getExcludedSettingsSummary in Blazy 8

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

Exclude the field formatter settings summary as required.

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

File

src/Form/BlazyAdminFormatterBase.php, line 152

Class

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

Namespace

Drupal\blazy\Form

Code

public function getExcludedSettingsSummary(array &$definition = []) {
  $settings =& $definition['settings'];
  $excludes = empty($definition['excludes']) ? [] : $definition['excludes'];
  $plugin_id = isset($definition['plugin_id']) ? $definition['plugin_id'] : '';
  $blazy = $plugin_id && strpos($plugin_id, 'blazy') !== FALSE;
  $image_styles = function_exists('image_style_options') ? image_style_options(TRUE) : [];
  $media_switch = empty($settings['media_switch']) ? '' : $settings['media_switch'];
  unset($image_styles['']);
  $excludes['current_view_mode'] = TRUE;
  if ($blazy) {
    $excludes['optionset'] = TRUE;
  }
  if ($media_switch != 'media') {
    $excludes['iframe_lazy'] = TRUE;
  }
  if (!empty($settings['responsive_image_style'])) {
    foreach ([
      'ratio',
      'breakpoints',
      'background',
      'sizes',
    ] as $key) {
      $excludes[$key] = TRUE;
    }
  }
  if (empty($settings['grid'])) {
    foreach ([
      'grid',
      'grid_medium',
      'grid_small',
      'visible_items',
    ] as $key) {
      $excludes[$key] = TRUE;
    }
  }

  // Remove exluded settings.
  foreach ($excludes as $key => $value) {
    if (isset($settings[$key])) {
      unset($settings[$key]);
    }
  }
  foreach ($settings as $key => $setting) {
    if ($key == 'style' || $key == 'responsive_image_style' || empty($settings[$key])) {
      continue;
    }
    if (strpos($key, 'style') !== FALSE && isset($image_styles[$settings[$key]])) {
      $settings[$key] = $image_styles[$settings[$key]];
    }
  }
}