You are here

public static function AlertStyleProvider::alertStyles in Sitewide Alert 8

Gets the available alert styles.

Return value

array Array of all alert style options.

1 call to AlertStyleProvider::alertStyles()
AlertStyleProvider::alertStyleName in src/AlertStyleProvider.php
Given a class get the alert style name.

File

src/AlertStyleProvider.php, line 19

Class

AlertStyleProvider
Class AlertStyleProvider.

Namespace

Drupal\sitewide_alert

Code

public static function alertStyles() : array {
  $styles = [];
  $config = \Drupal::config('sitewide_alert.settings');
  if ($alertStylesString = $config
    ->get('alert_styles')) {
    foreach (explode("\n", strip_tags($alertStylesString)) as $value) {
      if (strpos($value, '|') !== FALSE) {
        [
          $key,
          $title,
        ] = array_pad(array_map('trim', explode('|', $value, 2)), 2, NULL);
        $styles[$key] = $title;
      }
      else {
        $styles[Html::cleanCssIdentifier($value)] = $value;
      }
    }
  }
  return $styles;
}