You are here

function _insert_retrieve_styles in Insert 8.2

Parameters

array $styleSetting:

string|null $defaultStyleName:

string $insertType:

Return value

array The styles to consider for inserting items.

1 call to _insert_retrieve_styles()
_insert_field_process in ./insert.module
Form API callback: Processes a file field element.

File

./insert.module, line 266

Code

function _insert_retrieve_styles(array $styleSetting, $defaultStyleName, $insertType) {
  $allStyles = \Drupal::moduleHandler()
    ->invokeAll('insert_styles', [
    $insertType,
  ]);
  $defaultStyleName = _insert_evaluate_default_style($defaultStyleName, $insertType);
  if ($insertType === INSERT_TYPE_FILE) {

    // Filter out styles disabled per widget setting.
    $selectedStyles = array_filter($styleSetting);
  }
  else {

    // 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;
}