Ticket #162 (new enhancement)
Solar_View_Helper_ActionList
| Reported by: | rodrigo moraes <rodrigo.moraes@…> | Owned by: | pmjones |
|---|---|---|---|
| Priority: | trivial | Component: | code |
| Keywords: | Solar_View_Helper | Cc: |
Description
Long long ago we had something like Solar_View_Helper_ActionList (I don't remember the exact name). Let's bring it back! Here's how it could look like:
<?php /** * * Helper to build a list of action links. * * @category Tipos * * @package Tipos_View * * @author Rodrigo Moraes <rodrigo.moraes@gmail.com> * * @license http://opensource.org/licenses/bsd-license.php BSD * * @version $Id: ListNav.php 98 2007-12-18 11:52:58Z rodrigo.moraes $ * */ class Tipos_View_Helper_ActionList extends Solar_View_Helper { /** * * User-defined configuration values. * * Keys are... * * `list_id` * : (string) The ID attribute for the list. * * `list_class` * :(string) The class attribute for the list. * * `first_class` * : (string) The CSS class for the first item in the list. * * `curr_class` * : (string) The CSS class for the currently active item in the list. * * `last_class` * : (string) The CSS class for the last item in the list. * * @var array * */ protected $_Tipos_View_Helper_ActionList = array( 'list_id' => null, 'list_class' => null, 'first_class' => 'first', 'curr_class' => 'curr', 'last_class' => 'last', ); /** * * Returns a list of action links. * * @param array $items List of items in the form href => content. * * @param string $active The active item in the list. * * @param array $config Additional config options to build the list. * * @return string * */ public function actionList($items, $active = null, $config = null) { if ($config) { $config = array_merge($this->_config, (array) $config); } else { $config = $this->_config; } $html = array(); // start the list $attribs = $this->_view->attribs(array( 'id' => $config['list_id'], 'class' => $config['list_class'], )); $html[] = "<ul$attribs>"; $iter = 1; $total = count($items); foreach ($items as $href => $text) { $attribs = ''; $class = array(); // is this the active item? if ($active && ($href == $active) && $config['curr_class']) { $class[] = $config['curr_class']; } // is this the first or last item? if ($iter == 1 && $config['first_class']) { $class[] = $config['first_class']; } elseif ($iter == $total && $config['last_class']) { $class[] = $config['last_class']; } if (! empty($class)) { $attribs = $this->_view->attribs(array( 'class' => $class, )); } $html[] = "<li$attribs>"; if (is_string($href)) { // action item $html[] = $this->_view->action($href, $text); } else { // no href $html[] = $text; } $html[] = "</li>"; $iter++; } // done. $html[] = "</ul>"; return implode("\n", $html); } }
Attachments
Change History
Note: See
TracTickets for help on using
tickets.
