krafthaus / bauhaus

Laravel 4 Admin Generator
http://bauhaus.krafthaus.nl/
GNU General Public License v2.0
1 stars 0 forks source link

Overwrite Menu Entries #40

Closed noxify closed 10 years ago

noxify commented 10 years ago

Hi,

I have extended the bauhaususer and would now use my own admin classes in the backend. I'm using also laravel-modules (which work very well.. anyway).

By default, the bauhaususer packages has a config file, where the menu entries

'menu' => [
        'title' => trans('bauhaususer::admin.menu'),
        'children' => [
            [
                'title' => trans('bauhaususer::admin.users.menu'),
                'class' => 'KraftHaus\BauhausUser\User'
            ], [
                'title' => trans('bauhaususer::admin.groups.menu'),
                'class' => 'KraftHaus\BauhausUser\Group'
            ], [
                'title' => trans('bauhaususer::admin.permissions.menu'),
                'class' => 'KraftHaus\BauhausUser\Permission'
            ]
        ]
    ]

are defined.

My structure is the following:

app
- modules
-- users
--- admin
---- PermissionAdmin.php
--- models
---- Permission.php
--- migrations
---- 2014_10_05_132835_add_permission_group.php
--- menu.php

The PermissionAdmin.php

<?php

#namespace KraftHaus\BauhausUser;

/**
 * This file is part of the KraftHaus BauhausUser package.
 *
 * (c) KraftHaus <hello@krafthaus.nl>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

use KraftHaus\Bauhaus\Admin;

/**
 * Class PermissionAdmin
 * @package KraftHaus\BauhausUser
 */
class PermissionAdmin extends KraftHaus\BauhausUser\PermissionAdmin
{

    /**
     * Public constructor override to set translatable names (singular, plural).
     *
     * @access public
     * @return void
     */
    public function __construct()
    {
        Debugbar::info('own Permission admin - from modules');

        parent::__construct();
    }

    /**
     * Configure the PermissionAdmin list.
     *
     * @param \KraftHaus\Bauhaus\Mapper\ListMapper $mapper
     *
     * @access public
     * @return void
     */
    public function configureList($mapper) {

        $mapper->identifier('group')
            ->label(trans('bauhaususer::admin.permissions.list.group'));

        parent::configureList($mapper);
    }

    /**
     * Configure the UserAdmin form.
     *
     * @param  \KraftHaus\Bauhaus\Mapper\FormMapper $mapper
     *
     * @access public
     * @return void
     */
    public function configureForm($mapper) {

        $mapper->text('group')
            ->label(trans('bauhaususer::admin.permissions.form.group.label'))
            ->placeholder(trans('bauhaususer::admin.permissions.form.group.placeholder'));

        parent::configureForm($mapper);
    }

    /**
     * Configure the PermissionAdmin filters.
     * @param  \KraftHaus\Bauhaus\Mapper\FilterMapper $mapper
     *
     * @access public
     * @return void
     */
    public function configureFilters($mapper) {

        $mapper->text('group')
            ->label(trans('bauhaususer::admin.permissions.filter.group'));

        parent::configureFilters($mapper);
    }
}

Permission.php

<?php

/**
 * Class Permission
 * @package KraftHaus\BauhausUser
 */
class Permission extends KraftHaus\BauhausUser\Permission
{
    function __construct() {
        parent::__construct();
    }
}

2014_10_05_132835_add_permission_group.php

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddPermissionGroup extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('permissions', function($table) {
            $table->string('group');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('permissions', function($table) {
            $table->dropColumn('group');
        });
    }
}

menu.php (in this file, I store the addMenu() function - can be executed whereever you want)

app('krafthaus.bauhaus.menu')->addMenu('left', [
    'title' => trans('bauhaususer::admin.menu'),
        'children' => [
            [
                'title' => trans('bauhaususer::admin.permissions.menu'),
                'class' => 'Permission'
            ]
        ]
]);

The Result in HTML is:

<li class="dropdown">
    <a href="#" class="dropdown-toggle" data-toggle="dropdown">Users<b class="caret"></b></a>
    <ul class="dropdown-menu">
        <li>
            <a href="/admin/KraftHaus%255CBauhausUser%255CUser">Overview</a>
        </li>
        <li>
            <a href="/admin/KraftHaus%255CBauhausUser%255CGroup">Groups</a>
        </li>
        <li>
            <a href="/admin/KraftHaus%255CBauhausUser%255CPermission">Permissions</a>
        </li>
    </ul>
</li>

<li class="dropdown">
    <a href="#" class="dropdown-toggle" data-toggle="dropdown">Users<b class="caret"></b></a>
    <ul class="dropdown-menu">
        <li>
            <a href="/admin/Permission">Permissions</a>
        </li>
    </ul>
</li>

My problem is now, that i can't overwrite the existing records, because the menu builder will add the entries from the addMenu() into an array.

What I need, is the following:

<li class="dropdown">
    <a href="#" class="dropdown-toggle" data-toggle="dropdown">Users<b class="caret"></b></a>
    <ul class="dropdown-menu">
        <li>
            <a href="/admin/KraftHaus%255CBauhausUser%255CUser">Overview</a>
        </li>
        <li>
            <a href="/admin/KraftHaus%255CBauhausUser%255CGroup">Groups</a>
        </li>
        <!--Replaced 
        <li>
            <a href="/admin/KraftHaus%255CBauhausUser%255CPermission">Permissions</a>
        </li>
        -->
        <li>
            <a href="/admin/Permission">Permissions</a>
        </li>
    </ul>
</li>

Any idea?

Thanks!

noxify commented 10 years ago

Got the solution :)

Here is my menu example: https://github.com/noxify/Bauhaus-Menu-Overwrite

Known Issues: The defined menus, which exists in the Bauhaus and Bauhaus User Package are not shown.