0

How can I stop Bootstrap theme from overriding the them_item_list and replacing the div's class from item-list to panel-body?

I have the following form and it does not render the items

$stages = array(
1 => array('data' => '1. Step 1'),
2 => array('data' => '2. Step 2'),
3 => array('data' => '3. Step 3'),
);

$stages[$current_step]['class'] = array('active');

$stages_list = theme('item_list', array('items' => $stages));

$form['header'] = array(
    '#type' => 'fieldset',
    '#title' => '',
    '#value' => $stages_list,
);

the Above renders a navigation steps menu just fine with Bartik and other themes however, when it comes to Bootstrap it is empty rather having list of items.

I did some googling and found out this issue that might be somewhat relevant but, the solution does not seem to work for me. I tried to override the mytheme_item_list($variables) in template.php with following but, still no sign of the naviagtion.

function bootstrap_subtheme_item_list($variables) {
   $items = $variables['items'];
   $title = $variables['title'];
   $type = $variables['type'];
   $attributes = $variables['attributes'];

   $output = '<div class="item-list">';
   $output .= "<$type" . drupal_attributes($attributes) . '>';


   $count = 1;
   $num_items = count($items);

   foreach ($items as $item) {
      $attributes = array();
      $children = array();
      $data = '';
      $count++;

      if (is_array($item)) {
        foreach ($item as $key => $value) {
          if ($key == 'data') {
            $data = $value;
          }
          elseif ($key == 'children') {
            $children = $value;
          }
          else {
            $attributes[$key] = $value;
          }
        }
      }
      else {
        $data = $item;
      }

      if (count($children) > 0) {
        // Render nested list.
        $data .= theme_item_list(array('items' => $children, 'title' => NULL, 'type' => $type, 'attributes' => $attributes));
      }

      if ($count == 1) {
        $attributes['class'][] = 'first';
      }
      if ($count == $num_items) {
        $attributes['class'][] = 'last';
      }
      $output .= '<li' . drupal_attributes($attributes) . '>' . $data . "</li>\n";
   }
   $output .= "</$type></div>";


   dpm($output);

   return $output;
 }

The dpm above prints the exact thing piece of html that I want, the following but, the same is not rendered in the page.

<div class="item-list"><ul><li class="active">1. Step 1</li>
<li class="last">2. Step 2</li>
<li>3. Step 3</li>
</ul></div>

Not sure what I am doing wrong. Any solution that do not break other theme's would be very much appreciated.

1

1) Default markup. To return default item list markup just do this:

function bootstrap_subtheme_item_list($variables) {
  return theme_item_list($variables);
}

2) But. Your issue is not caused by Bootstrap markup. Try this:

$form['header'] = array(
  '#markup' => $stages_list,
);

You are using fieldset incorrectly, learn Form API Reference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.