You are here

protected function InsertFileWidgetUtility::retrieveInsertStyles in Insert 8

Parameters

array $styleSetting:

string $defaultStyleName:

Return value

array The styles to consider for inserting items.

1 call to InsertFileWidgetUtility::retrieveInsertStyles()
InsertFileWidgetUtility::process in src/Utility/InsertFileWidgetUtility.php
Form API callback: Processes a file field element.
1 method overrides InsertFileWidgetUtility::retrieveInsertStyles()
InsertImageWidgetUtility::retrieveInsertStyles in src/Utility/InsertImageWidgetUtility.php
@inheritdoc

File

src/Utility/InsertFileWidgetUtility.php, line 320

Class

InsertFileWidgetUtility

Namespace

Drupal\insert\Utility

Code

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

  // Filter out styles disabled per widget setting.
  $selectedStyles = 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;
}