You are here

function command_buttons_get_button_class in Command Buttons 7

Parse the class list out the field settings on a fieldable panels pane.

Return value

array an array of classes, keyed for both items and wrappers.

1 call to command_buttons_get_button_class()
command_buttons_entity_view in ./command_buttons.module
Implements hook_entity_view().

File

./command_buttons.module, line 770

Code

function command_buttons_get_button_class($entity, $type, $view_mode, $langcode) {
  $return_classes = array(
    'item_class' => array(
      'oa-button',
    ),
    'wrapper_class' => array(
      'oa-buttons',
    ),
  );
  $style = field_get_items($type, $entity, 'field_button_style', $langcode);
  if (!empty($style[0]['value']) && $style[0]['value'] != 'other') {
    $classes[] = $style[0]['value'];
  }
  else {

    // Grab a class if it's been set on the fieldable panels pane.
    $class = field_get_items($type, $entity, 'field_css_class', $langcode);
    if (!empty($class[0]['safe_value'])) {
      $classes[] = $class[0]['safe_value'];
    }
  }
  $size = field_get_items($type, $entity, 'field_button_size', $langcode);
  if (!empty($size[0]['value']) && $style[0]['value'] != 'default') {
    $classes[] = $size[0]['value'];
  }
  $block = field_get_items($type, $entity, 'field_block_buttons', $langcode);
  if (!empty($block[0]['value'])) {
    $classes[] = 'btn-block';
  }
  $use_dropdowns = field_get_items($type, $entity, 'field_use_dropdowns', $langcode);
  if (!empty($use_dropdowns[0]['value'])) {
    $return_classes['wrapper_class'] = array_merge($classes, $return_classes['wrapper_class']);
  }
  else {
    $return_classes['item_class'] = array_merge($classes, $return_classes['item_class']);
  }
  return $return_classes;
}