Autodoc
  • Namespace
  • Class
  • Tree

Namespaces

  • BlueTihi
    • Context
  • Brickrouge
    • Element
      • Nodes
    • Renderer
    • Widget
  • ICanBoogie
    • ActiveRecord
    • AutoConfig
    • CLDR
    • Composer
    • Core
    • Event
    • Exception
    • HTTP
      • Dispatcher
      • Request
    • I18n
      • Translator
    • Mailer
    • Modules
      • Taxonomy
        • Support
      • Thumbnailer
        • Versions
    • Object
    • Operation
      • Dispatcher
    • Prototype
    • Routes
    • Routing
      • Dispatcher
    • Session
  • Icybee
    • ActiveRecord
      • Model
    • ConfigOperation
    • Document
    • EditBlock
    • Element
      • ActionbarContextual
      • ActionbarSearch
      • ActionbarToolbar
    • FormBlock
    • Installer
    • ManageBlock
    • Modules
      • Articles
      • Cache
        • Collection
        • ManageBlock
      • Comments
        • ManageBlock
      • Contents
        • ManageBlock
      • Dashboard
      • Editor
        • Collection
      • Files
        • File
        • ManageBlock
      • Forms
        • Form
        • ManageBlock
      • I18n
      • Images
        • ManageBlock
      • Members
      • Modules
        • ManageBlock
      • Nodes
        • ManageBlock
        • Module
      • Pages
        • BreadcrumbElement
        • LanguagesElement
        • ManageBlock
        • NavigationBranchElement
        • NavigationElement
        • Page
        • PageController
      • Registry
      • Search
      • Seo
      • Sites
        • ManageBlock
      • Taxonomy
        • Terms
          • ManageBlock
        • Vocabulary
          • ManageBlock
      • Users
        • ManageBlock
        • NonceLogin
        • Roles
      • Views
        • ActiveRecordProvider
        • Collection
        • View
    • Operation
      • ActiveRecord
      • Constructor
      • Module
      • Widget
    • Rendering
  • None
  • Patron
  • PHP

Classes

  • A
  • Actions
  • Alert
  • AlterCSSClassNamesEvent
  • AssetsCollector
  • Button
  • CSSCollector
  • Dataset
  • Date
  • DateRange
  • DateTime
  • Decorator
  • Document
  • DropdownMenu
  • Element
  • File
  • Form
  • Group
  • Helpers
  • HTMLString
  • Iterator
  • JSCollector
  • ListView
  • ListViewColumn
  • Modal
  • Pager
  • Popover
  • PopoverWidget
  • Ranger
  • RecursiveIterator
  • Salutation
  • Searchbox
  • Section
  • SplitButton
  • Text
  • Widget

Interfaces

  • CSSClassNames
  • DecoratorInterface
  • HTMLStringInterface
  • Validator

Traits

  • CSSClassNamesProperty

Exceptions

  • ElementIsEmpty

Functions

  • _array_flatten_callback
  • array_flatten
  • array_insert
  • check_session
  • dump
  • escape
  • escape_all
  • format
  • format_size
  • get_accessible_file
  • get_document
  • normalize
  • render_css_class
  • render_exception
  • retrieve_form
  • retrieve_form_errors
  • shorten
  • stable_sort
  • store_form
  • store_form_errors
  • strip
  • t
  1 <?php
  2 
  3 /*
  4  * This file is part of the Brickrouge package.
  5  *
  6  * (c) Olivier Laviale <olivier.laviale@gmail.com>
  7  *
  8  * For the full copyright and license information, please view the LICENSE
  9  * file that was distributed with this source code.
 10  */
 11 
 12 namespace Brickrouge;
 13 
 14 /**
 15  * A drop down menu element.
 16  */
 17 class DropdownMenu extends Element
 18 {
 19     public function __construct(array $attributes=array())
 20     {
 21         parent::__construct('ul', $attributes);
 22     }
 23 
 24     protected function render_inner_html()
 25     {
 26         $html = '';
 27         $options = $this[self::OPTIONS];
 28         $value = $this['value'];
 29 
 30         if ($value === null)
 31         {
 32             $value = $this[self::DEFAULT_VALUE];
 33         }
 34 
 35         foreach ($options as $key => $option)
 36         {
 37             if ($option === false)
 38             {
 39                 $html .= '<li class="divider"></li>';
 40 
 41                 continue;
 42             }
 43             else if ($option === null)
 44             {
 45                 continue;
 46             }
 47 
 48             $html .= '<li' . ((string) $key === (string) $value ? ' class="active"' : '') . '>';
 49 
 50             if ($option instanceof Element)
 51             {
 52                 $html .= $option;
 53             }
 54             else
 55             {
 56                 $html .= '<a href="' . escape($key) . '" data-key="' . escape($key) . '">' . (is_string($option) ? escape($option) : $option) . '</a>';
 57             }
 58 
 59             $html .= '</li>';
 60         }
 61 
 62         return $html;
 63     }
 64 
 65     protected function render_class(array $class_names)
 66     {
 67         return parent::render_class($class_names + array('dropdown-menu' => true));
 68     }
 69 }
 70 
 71 /**
 72  * An element made of a button and a drop down menu.
 73  */
 74 class SplitButton extends Element
 75 {
 76     public function __construct($label, array $attributes=array())
 77     {
 78         if (is_string($label))
 79         {
 80             $label = escape(t($label, array(), array('scope' => 'button')));
 81         }
 82 
 83         parent::__construct
 84         (
 85             'div', $attributes + array
 86             (
 87                 self::INNER_HTML => $label
 88             )
 89         );
 90     }
 91 
 92     /**
 93      * Renders the button and drop down trigger button.
 94      *
 95      * The `btn-primary`, `btn-danger`, `btn-success` and `btn-info` class names are forwarded to
 96      * the buttons.
 97      *
 98      * @see Element::render_inner_html()
 99      */
100     protected function render_inner_html()
101     {
102         $label = parent::render_inner_html();
103 
104         $class_names = array_intersect_key
105         (
106             array
107             (
108                 'btn-primary' => true,
109                 'btn-danger' => true,
110                 'btn-success' => true,
111                 'btn-info' => true
112             ),
113 
114             $this->class_names
115         );
116 
117         $class = implode(' ', array_keys(array_filter($class_names)));
118 
119         return $this->render_splitbutton_label($label, $class)
120         . $this->render_splitbutton_toggle($class)
121         . $this->resolve_options($this[self::OPTIONS]);
122     }
123 
124     /**
125      * Renders the button part of the element.
126      *
127      * @param string $label Label of the button. The label is already a HTML string. It doesn't
128      * need to be escaped.
129      * @param string $class Class of the label.
130      *
131      * @return string A HTML string.
132      */
133     protected function render_splitbutton_label($label, $class)
134     {
135         return <<<EOT
136 <a href="javascript:void()" class="btn $class">$label</a>
137 EOT;
138     }
139 
140     /**
141      * Renders the drop down toggle part of the element.
142      *
143      * @param string $class Class of the element.
144      *
145      * @return string A HTML string.
146      */
147     protected function render_splitbutton_toggle($class)
148     {
149         return <<<EOT
150 <a href="javascript:void()" class="btn dropdown-toggle $class" data-toggle="dropdown"><span class="caret"></span></a>
151 EOT;
152     }
153 
154     /**
155      * Removes the `btn-primary`, `btn-danger`, `btn-success` and `btn-info` class names and adds
156      * the `btn-group` class.
157      *
158      * @see Element::render_class()
159      */
160     protected function render_class(array $class_names)
161     {
162         return parent::render_class
163         (
164             array
165             (
166                 'btn-primary' => false,
167                 'btn-danger' => false,
168                 'btn-success' => false,
169                 'btn-info' => false
170             )
171 
172             + $class_names + array('btn-group' => true)
173         );
174     }
175 
176     /**
177      * Resolves the provided options into a {@link DropdownMenu} element.
178      *
179      * @param mixed $options
180      *
181      * @return DropdownMenu
182      *
183      * @throws \UnexpectedValueException If the provided options cannot be resolved into a
184      * {@link DropdownMenu} element.
185      */
186     protected function resolve_options($options)
187     {
188         if (is_array($options))
189         {
190             $options = new DropdownMenu(array(Element::OPTIONS => $options, 'value' => $this['value'] ?: $this[self::DEFAULT_VALUE]));
191         }
192 
193         if (!($options instanceof DropdownMenu))
194         {
195             throw new \UnexpectedValueException(format('OPTIONS should be either an array or a Brickrouge\DropDownMenu instance, %type given.', array('type' => gettype($options))));
196         }
197 
198         return $options;
199     }
200 }
Autodoc API documentation generated by ApiGen 2.8.0