Created
November 5, 2014 23:39
-
-
Save KorvinSzanto/6fa4a710328564ff39fc to your computer and use it in GitHub Desktop.
Sample menu item implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Sample\Menu\Item\SampleItem; | |
\Events::addListener( | |
'on_before_render', | |
function () { | |
\Core::make('helper/concrete/ui/menu')->addMenuItem(new SampleItem); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Sample\Menu\Item; | |
use Concrete\Core\Application\UserInterface\Menu\Item\ControllerInterface; | |
use Concrete\Core\Application\UserInterface\Menu\Item\ItemInterface; | |
use HtmlObject\Element; | |
class SampleController implements ControllerInterface | |
{ | |
/** @var ItemInterface */ | |
protected $item; | |
/** | |
* Determine whether item should be displayed | |
* | |
* @return bool | |
*/ | |
public function displayItem() | |
{ | |
return true; | |
} | |
/** | |
* We don't have any assets | |
* | |
* @return void | |
*/ | |
public function registerViewAssets() | |
{ | |
} | |
/** | |
* @return \HtmlObject\Traits\Tag | |
*/ | |
public function getMenuItemLinkElement() | |
{ | |
return new Element('div', date(DATE_ATOM)); | |
} | |
/** | |
* @param ItemInterface $item | |
* @return void | |
*/ | |
public function setMenuItem(ItemInterface $item) | |
{ | |
$this->item = $item; | |
} | |
/** | |
* @return ItemInterface | |
*/ | |
public function getMenuItem() | |
{ | |
return $this->item; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Sample\Menu\Item; | |
use Concrete\Core\Application\UserInterface\Menu\Item\ControllerInterface; | |
use Concrete\Core\Application\UserInterface\Menu\Item\ItemInterface; | |
class SampleItem implements ItemInterface | |
{ | |
/** @var ControllerInterface */ | |
protected $controller; | |
/** @var string [right|left] */ | |
protected $position = 'left'; | |
public function __construct() | |
{ | |
$this->setController(new SampleController); | |
} | |
/** | |
* @return ControllerInterface | |
*/ | |
public function getController() | |
{ | |
return $this->controller; | |
} | |
/** | |
* @param ControllerInterface $controller | |
* @return void | |
*/ | |
public function setController(ControllerInterface $controller) | |
{ | |
$this->controller = $controller; | |
} | |
/** | |
* @return bool | |
*/ | |
public function getPosition() | |
{ | |
return $this->position; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment