You are here

class views_tabset in Views (for Drupal 7) 6.2

Same name and namespace in other branches
  1. 6.3 includes/tabs.inc \views_tabset

Contain a set of tabs as well as the ability to render them.

There are three 'areas' of a tabset.

  • title: The clickable link to display the tab area. These are always visible.
  • body: The actual HTML body of the tab. Only one body is visible at a time.
  • extra: An optional decorative area around the tabs.

Hierarchy

Expanded class hierarchy of views_tabset

File

includes/tabs.inc, line 16
Classes and theme functions for rendering javascript UI tabs.

View source
class views_tabset {
  var $tabs = array();
  var $extra = '';
  var $selected = NULL;

  /**
   * Add a tab to the tabset.
   *
   * @param $name
   *   The name of the tab; this is the internal identifier and must be
   *   unique within the tabset.
   * @param $title
   *   If given, this will be the visible title of the tab. This can also
   *   be set via $tabset->set(). This will be the link to click on to
   *   view the tab.
   * @param $body
   *   If given, this is the body of the tab itself. It will display
   *   when the tab title is clicked on.
   */
  function add($name, $title = '', $body = '') {
    if (is_object($name) && is_subclass_of($name, 'views_tab')) {
      $this
        ->add_tab($name);
    }
    elseif (is_array($name)) {
      foreach ($name as $real_tab) {
        $this
          ->add($real_tab);
      }
    }
    else {
      $this
        ->add_tab(new views_tab($name, $title, $body));
    }
  }

  /**
   * Add a fully realized tab object to the tabset.
   *
   * @param $tab
   *   A fully populated views_tab object.
   */
  function add_tab($tab) {
    $this->tabs[$tab->name] = $tab;
  }

  /**
   * Set the values of a tab.
   *
   * @param $name
   *   The unique identifier of the tab to set.
   * @param $title
   *   The title of the tab; this will be clickable.
   * @param $body
   *   The HTML body of the tab.
   */
  function set($name, $title, $body = NULL) {
    if (empty($this->tabs[$name])) {
      return $this
        ->add($name, $title, $body);
    }
    $this->tabs[$name]->title = $title;
    if (isset($body)) {
      $this->tabs[$name]->body = $body;
    }
  }

  /**
   * Set the body of a tab.
   */
  function set_body($name, $body) {
    if (empty($this->tabs[$name])) {
      return $this
        ->add($name, '', $body);
    }
    $this->tabs[$name]->body = $body;
  }

  /**
   * Add text to the 'extra' region of the tabset.
   */
  function add_extra($text) {
    $this->extra .= $text;
  }

  /**
   * Remove a tab.
   *
   * @param $tab
   *   May be the name of the tab or a views_tab object.
   */
  function remove($tab) {
    if (is_string($tab)) {
      unset($this->tabs[$tab]);
    }
    else {
      unset($this->tabs[$tab->name]);
    }
  }

  /**
   * Control which tab will be selected when it is rendered.
   */
  function set_selected($name) {
    $this->selected = $name;
  }

  /**
   * Output the HTML for the tabs.
   *
   * @return
   *   HTML representation of the tabs.
   */
  function render() {
    views_add_js('tabs');
    views_add_css('views-tabs');
    if (empty($this->selected)) {
      $keys = array_keys($this->tabs);
      $this->selected = array_shift($keys);
    }
    drupal_alter('views_tabset', $this);
    return theme('views_tabset', $this->tabs, $this->extra, $this->selected);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
views_tabset::$extra property
views_tabset::$selected property
views_tabset::$tabs property
views_tabset::add function Add a tab to the tabset.
views_tabset::add_extra function Add text to the 'extra' region of the tabset.
views_tabset::add_tab function Add a fully realized tab object to the tabset.
views_tabset::remove function Remove a tab.
views_tabset::render function Output the HTML for the tabs.
views_tabset::set function Set the values of a tab.
views_tabset::set_body function Set the body of a tab.
views_tabset::set_selected function Control which tab will be selected when it is rendered.