forked from koala-framework/koala-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Events.php
40 lines (35 loc) · 1.59 KB
/
Events.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
class Kwc_Menu_Events extends Kwc_Menu_Abstract_Events
{
protected $_emptyIfSingleEntry;
//overwritten in Kwc_Menu_Trl_Events
protected function _initSettings()
{
parent::_initSettings();
$this->_emptyIfSingleEntry = $menuLevel = Kwc_Abstract::getSetting($this->_class, 'emptyIfSingleEntry');
}
//fire HasContentChanged here because hasContent is implemented in this component
protected function _onMenuChanged(Kwf_Events_Event_Abstract $event, Kwf_Component_Data $menu)
{
parent::_onMenuChanged($event, $menu);
$newCount = count($menu->getComponent()->getMenuData());
if ($event instanceof Kwf_Component_Event_Page_Removed && $event->flag == Kwf_Component_Event_Page_Removed::FLAG_ROW_ADDED_REMOVED) {
//if a row was ->delete()d it the the component is still in the component tree and returned by getMenuData()
//so the newCount must be one less.
//when changing the visibility it is not returned and $newCount is already correct.
$newCount--;
}
if ($this->_emptyIfSingleEntry) $newCount--; //check with one less
$previousCount = $newCount;
if ($event instanceof Kwf_Component_Event_Page_Added) {
$previousCount--;
} else if ($event instanceof Kwf_Component_Event_Page_Removed) {
$previousCount++;
}
if (!$previousCount && $newCount || $previousCount && !$newCount) {
$this->fireEvent(new Kwf_Component_Event_Component_HasContentChanged(
$this->_class, $menu
));
}
}
}