Tabs are currently generated only partially through the forms api. It would be better to generate them fully through the forms api, so that developers could use tabs seamlessly in forms.

Attached patch does this. It will necessitate changes in how tabs are generated. Old way:


  $tabs = array(
    '#name' => 'example1',
  );
  $tabs[] = array(
    '#title' => t('One'),
    '#content' => t('First tab content.'),
  );
  $tabs[] = array(
    '#title' => t('Two'),
    '#content' => t('Second tab content.'),
  );
  $tabs[] = array(
    '#title' => t('Three'),
    '#content' => t('Third tab content.'),
  );
  
  return theme('tabs_tabset', $tabs);

New way:


  $form = array();

  $form['example1'] = array(
    '#type' => 'tabset',
  );
  $form['example1']['tab1'] = array(
    '#type' => 'tabpage',
    '#title' => t('One'),
    '#content' => t('First tab content.'),
  );
  $form['example1']['tab2'] = array(
    '#type' => 'tabpage',
    '#title' => t('Two'),
    '#content' => t('Second tab content.'),
  );
  $form['example1']['tab3'] = array(
    '#type' => 'tabpage',
    '#title' => t('Three'),
    '#content' => t('Third tab content.'),
  );

The patch also includes an example module implementing tabs.

CommentFileSizeAuthor
tabs-forms-api.patch6.29 KBnedjo

Comments

zigma’s picture

This seems interesting.

Just wondering on its impact. I guess it will not constrain building tabs for pages that has nothing to do with forms while making it much easier to deal with forms.

nedjo’s picture

Yep, that's the idea.

nedjo’s picture

Status: Needs review » Fixed

I've applied the patch. This means that all modules using tabs module will need to be updated.

zigma’s picture

tabs_render($form) in tabs.module breaks on php 5.0.5 and higher version. It could be just me. So you may want to validate it.

Breaking the call to render form in two statements makes it work.
//return drupal_render(form_builder('tabset', $form));
$built_form = form_builder('tabset', $form);
return drupal_render($built_form);

Anonymous’s picture

Status: Fixed » Closed (fixed)