You are here

public function InsertImageWidgetUtility::retrieveInsertStyles in Insert 8

@inheritdoc

Parameters

array $styleSetting:

string $defaultStyleName:

Return value

array The styles to consider for inserting items. The array may contain plain arrays for pseudo-styles as well as ImageStyle objects.

Overrides InsertFileWidgetUtility::retrieveInsertStyles

File

src/Utility/InsertImageWidgetUtility.php, line 110

Class

InsertImageWidgetUtility

Namespace

Drupal\insert\Utility

Code

public function retrieveInsertStyles($styleSetting, $defaultStyleName) {
  $allStyles = $this
    ->retrieveStyles();

  // When the value is <all>, even styles that have been created since the
  // widget settings have been altered the last time shall be enabled;
  // Consequently, all styles have to be retrieved instead of using any actual
  // setting value.
  $selectedStyles = !empty($styleSetting['<all>']) ? array_combine($allStyles, $allStyles) : array_filter((array) $styleSetting);

  // Ensure default style is available.
  if ($defaultStyleName !== null && !array_key_exists($defaultStyleName, $selectedStyles)) {
    $selectedStyles[$defaultStyleName] = $allStyles[$defaultStyleName];
  }

  // Ensure only styles that are still installed are considered.
  $selectedAndInstalled = [];
  foreach (array_keys($selectedStyles) as $styleName) {
    if (array_key_exists($styleName, $allStyles)) {
      $selectedAndInstalled[$styleName] = $allStyles[$styleName];
    }
  }
  return $selectedAndInstalled;
}