You are here

public static function Ds::getClasses in Display Suite 8.4

Same name and namespace in other branches
  1. 8.2 src/Ds.php \Drupal\ds\Ds::getClasses()
  2. 8.3 src/Ds.php \Drupal\ds\Ds::getClasses()

Utility function to return CSS classes.

2 calls to Ds::getClasses()
DsFieldTemplateBase::alterForm in src/Plugin/DsFieldTemplate/DsFieldTemplateBase.php
Lets you add you add additional form element for your layout.
DsLayout::buildConfigurationForm in src/Plugin/DsLayout.php
Form constructor.

File

src/Ds.php, line 201

Class

Ds
Helper class that holds all the main Display Suite helper functions.

Namespace

Drupal\ds

Code

public static function getClasses($name = 'region') {
  static $classes = [];
  if (!isset($classes[$name])) {
    $classes[$name] = [];
    $custom_classes = \Drupal::config('ds.settings')
      ->get('classes.' . $name);
    if (!empty($custom_classes)) {
      $classes[$name][''] = t('None');
      foreach ($custom_classes as $value) {
        $classes_splitted = explode("|", $value);
        $key = trim($classes_splitted[0]);
        $friendly_name = isset($classes_splitted[1]) ? trim($classes_splitted[1]) : $key;
        $classes[$name][Html::escape($key)] = $friendly_name;
      }
    }

    // Prevent the name from being changed.
    $name_clone = $name;
    \Drupal::moduleHandler()
      ->alter('ds_classes', $classes[$name], $name_clone);
  }
  return $classes[$name];
}