You are here

function _insert_evaluate_default_style in Insert 8.2

Returns the default style or a fallback style when the defined default style is not compatible to the $insertType.

Parameters

string|null $styleName:

string $insertType:

Return value

string

1 call to _insert_evaluate_default_style()
_insert_retrieve_styles in ./insert.module

File

./insert.module, line 314

Code

function _insert_evaluate_default_style($styleName, $insertType) {
  if (!in_array($insertType, [
    INSERT_TYPE_FILE,
    INSERT_TYPE_IMAGE,
  ])) {

    // Core Insert module is not responsible for insert types other than file
    // and image.
    return $styleName;
  }
  if ($insertType === INSERT_TYPE_IMAGE) {

    // Image widgets may use all styles.
    return $styleName;
  }

  // Prevent file widgets to use an image style for inserting:
  $allStyles = \Drupal::moduleHandler()
    ->invokeAll('insert_styles', [
    INSERT_TYPE_FILE,
  ]);
  if (array_key_exists($styleName, $allStyles)) {
    return $styleName;
  }
  return INSERT_DEFAULT_SETTINGS['default'];
}