You are here

function _ds_style_parse_variable in Display Suite 6.3

Same name and namespace in other branches
  1. 6 includes/ds.display.inc \_ds_style_parse_variable()
  2. 6.2 includes/ds.display.inc \_ds_style_parse_variable()

Parse style variable value into a keyed array suitable for FAPI options, including the "None" option.

1 call to _ds_style_parse_variable()
ds_styles in includes/ds.display.inc
Return styles.

File

includes/ds.display.inc, line 739
Display overview form.

Code

function _ds_style_parse_variable($variable) {
  static $optgroup_key = '~';
  static $optgroup_label_trim = ' []';
  $styles = array(
    '' => t('None'),
  );
  $var_values = trim(variable_get($variable, ''));
  if (!empty($var_values)) {

    // Prepare loop variables
    $var_styles = explode("\n", $var_values);
    $label = NULL;
    $group =& $styles;
    foreach ($var_styles as $key => $value) {
      $classes = explode('|', trim($value));
      $key = trim($classes[0]);
      $name = isset($classes[1]) ? trim($classes[1]) : $key;

      // Group
      if (preg_match('/^(' . $optgroup_key . ')+$/', $key)) {

        // Accumulate this new group
        $label = trim($name, $optgroup_label_trim);
        $group =& $styles[$label];
      }
      else {
        $group[$key] = $name;
      }
    }
  }
  return $styles;
}