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 use Brickrouge\ElementIsEmpty;
16 
17 class ActionbarContextual extends Element
18 {
19     public function __construct(array $attributes=array())
20     {
21         parent::__construct('div', $attributes + array('class' => 'actionbar-contextual'));
22     }
23 
24     protected function render_inner_html()
25     {
26         $items = array();
27 
28         new ActionbarContextual\CollectItemsEvent($this, $items);
29 
30         $html = implode($items);
31 
32         if (empty($html))
33         {
34             throw new ElementIsEmpty;
35         }
36 
37         return $html;
38     }
39 }
40 
41 namespace Icybee\Element\ActionbarContextual;
42 
43 /**
44  * Event class for the `Icybee\Element\ActionbarContextual::collect_items` event.
45  */
46 class CollectItemsEvent extends \ICanBoogie\Event
47 {
48     /**
49      * Reference to the rendered inner HTML of the element.
50      *
51      * @var string
52      */
53     public $items;
54 
55     /**
56      * The event is constructed with the type `collect_items`.
57      *
58      * @param \Icybee\Element\ActionbarSearch $target
59      * @param array $payload
60      */
61     public function __construct(\Icybee\Element\ActionbarContextual $target, array &$items)
62     {
63         $this->items = &$items;
64 
65         parent::__construct($target, 'collect_items');
66     }
67 }