1 <?php
2
3 /*
4 * This file is part of the Icybee 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 Icybee\Element;
13
14 use Brickrouge\Element;
15
16 /**
17 * A toolbar of the action bar.
18 *
19 * The `alter_buttons` event is fired to alter buttons before the inner HTML of the toolbar is
20 * rendered.
21 */
22 class ActionbarToolbar extends Element
23 {
24 public function __construct(array $attributes=array())
25 {
26 parent::__construct('div', $attributes + array('class' => 'actionbar-toolbar btn-toolbar'));
27 }
28
29 protected function render_inner_html()
30 {
31 $buttons = $this->collect();
32
33 new ActionbarToolbar\CollectEvent($this, array('buttons' => &$buttons));
34
35 if (empty($buttons))
36 {
37 throw new \Brickrouge\ElementIsEmpty;
38 }
39
40 return implode($buttons);
41 }
42
43 protected function collect()
44 {
45 return array();
46 }
47 }
48
49 namespace Icybee\Element\ActionbarToolbar;
50
51 /**
52 * Event class for the `Icybee\Element\ActionbarToolbar::collect` event.
53 */
54 class CollectEvent extends \ICanBoogie\Event
55 {
56 /**
57 * Reference to the button array to alter.
58 *
59 * @var array
60 */
61 public $buttons;
62
63 /**
64 * The event is constructed with the type `collect`.
65 *
66 * @param \Icybee\Element\ActionbarToolbar $target
67 * @param array $payload
68 */
69 public function __construct(\Icybee\Element\ActionbarToolbar $target, array $payload)
70 {
71 parent::__construct($target, 'collect', $payload);
72 }
73 }