<?php namespace Orchestra\Control;

use Orchestra\Contracts\Foundation\Foundation;

class ControlMenuHandler
{
    /**
     * ACL instance.
     *
     * @var \Orchestra\Contracts\Authorization\Authorization
     */
    protected $acl;

    /**
     * Menu instance.
     *
     * @var \Orchestra\Widget\Handlers\Menu
     */
    protected $menu;

    /**
     * Construct a new handler.
     *
     * @param  \Orchestra\Contracts\Foundation\Foundation  $foundation
     */
    public function __construct(Foundation $foundation)
    {
        $this->menu = $foundation->menu();
        $this->acl = $foundation->acl();
    }

    /**
     * Create a handler for `orchestra.ready: admin` event.
     *
     * @return void
     */
    public function handle()
    {
        if (! ($this->acl->can('manage roles') || $this->acl->can('manage acl'))) {
            return ;
        }

        $this->menu->add('control', '^:extensions')
            ->title('Control')
            ->link(handles('orchestra::control'));
    }
}

<?php namespace Orchestra\Control;

use Orchestra\Contracts\Foundation\Foundation;

class ControlMenuHandler
{
    /**
     * ACL instance.
     *
     * @var \Orchestra\Contracts\Authorization\Authorization
     */
    protected $acl;

    /**
     * Menu instance.
     *
     * @var \Orchestra\Widget\Handlers\Menu
     */
    protected $menu;

    /**
     * Construct a new handler.
     *
     * @param  \Orchestra\Contracts\Foundation\Foundation  $foundation
     */
    public function __construct(Foundation $foundation)
    {
        $this->menu = $foundation->menu();
        $this->acl = $foundation->acl();
    }

    /**
     * Create a handler for `orchestra.ready: admin` event.
     *
     * @return void
     */
    public function handle()
    {
        if (! ($this->acl->can('manage roles') || $this->acl->can('manage acl'))) {
            return ;
        }

        $parent = $this->menu->has('extensions') ? '^:extensions' : '<:home';

        $this->menu->add('control', $parent)
            ->title('Control')
            ->link(handles('orchestra::control'));
    }
}

Append menu to main menu if extensions doesn't exist.
Append menu to main menu if extensions doesn't exist.

Signed-off-by: crynobone <e1a543840a942eb68427510a8a483282a7bfeddf@gmail.com>
