edge5/app-backend-bundle

This package is abandoned and no longer maintained. No replacement package was suggested.

Base project with Admingenerator, FOS user bundle and db-side translations.

Installs: 374

Dependents: 0

Suggesters: 0

Stars: 0

Watchers: 5

Forks: 0

Open Issues: 0

Language:JavaScript

Type:symfony-bundle

dev-master / 1.0.x-dev 2015-04-09 13:04 UTC

README

This project provides a simple predefined backend base, consiting of AdminGeneratorBundle, the FOS User Bundle and a simple component, which loads translations out of the database.

Installation

Add to composer.json:

"require": {
    "edge5/app-backend-bundle": "dev-master",
    "avocode/form-extensions-bundle": "dev-master",
    "jms/security-extra-bundle": "dev-master"
},
...
"config": {
    ...
    "component-dir": "web/components"
},

And change minimum-stability from stable to dev:

"minimum-stability": "dev",

Then run php composer.phar update command.

Configuration

Add to app/AppKernel.php

new WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle(),
new Admingenerator\GeneratorBundle\AdmingeneratorGeneratorBundle(),
new Admingenerator\UserBundle\AdmingeneratorUserBundle(),
new FOS\UserBundle\FOSUserBundle(),
new Knp\Bundle\MenuBundle\KnpMenuBundle(),
new Propel\PropelBundle\PropelBundle(),
new Edge5\AppBackendBundle\Edge5AppBackendBundle(),
new Avocode\FormExtensionsBundle\AvocodeFormExtensionsBundle(),
new JMS\AopBundle\JMSAopBundle(),
new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),

Add to app/config/config.yml:

fos_user:
    service:
        mailer: fos_user.mailer.noop
    db_driver: propel
    user_class: FOS\UserBundle\Propel\User
    firewall_name: main

admingenerator_generator:
    base_admin_template: AdmingeneratorGeneratorBundle::base_admin_assetic_less.html.twig
    use_doctrine_orm: false
    use_doctrine_odm: false
    use_propel: true
    stylesheets:
        - { path: bundles/edge5appbackend/css/custom.css }
    javascripts:
        - { path: bundles/edge5appbackend/js/backend.js }
        - { path: bundles/edge5appbackend/js/tiny_mce/jquery.tinymce.js }
        - { path: bundles/edge5appbackend/js/tiny_mce/tiny_mce.js }

admingenerator_user:
    login_template: Edge5AppBackendBundle::base_admin.html.twig

propel:
    path:       "%kernel.root_dir%/../vendor/propel/propel1"
    phing_path: "%kernel.root_dir%/../vendor/pear-phing"
    dbal:
        driver:               mysql
        user:                 %database_user%
        password:             %database_password%
        dsn:                  mysql:host=%database_host%;dbname=%database_name%;charset=UTF8
        options:              {}
        attributes:           {}

knp_menu:
    twig:
        template: AdmingeneratorGeneratorBundle:KnpMenu:knp_menu_trans.html.twig

jms_security_extra:
    expressions: true

Uncomment in app/config/config.yml:

framework:
    translator:      { fallback: %locale% }

Add to app/config/config.yml:

twig:
    form:
        resources:
            - "Edge5AppBackendBundle::fields.html.twig"
            - "AdmingeneratorGeneratorBundle:Form:fields.html.twig"
            - "AvocodeFormExtensionsBundle:Form:form_widgets.html.twig"
            - "AvocodeFormExtensionsBundle:Form:form_stylesheets.html.twig"
            - "AvocodeFormExtensionsBundle:Form:form_javascripts.html.twig"

Add to app/config/parameters.yml:

parameters:
    locales: [<<locales for i18n>>]
    edge5.menu_builder.class: Edge5\AppBackendBundle\Menu\AdminMenu

Add routes to app/config/routes.yml:

backend_bundle:
    resource: "@Edge5AppBackendBundle/Resources/config/routing/backend.xml"
    prefix: /admin

fos_user_security:
    resource: "@FOSUserBundle/Resources/config/routing/security.xml"

Add to security.yml:

security:
    encoders:
        "FOS\UserBundle\Model\UserInterface": sha512
    providers:
        fos_userbundle:
            id: fos_user.user_provider.username

    firewalls:
        main:
            pattern: ^/
            form_login:
                provider: fos_userbundle
            logout:       true
            anonymous:    true

    access_control:
        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin, role: ROLE_ADMIN }

    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: ROLE_ADMIN

Add to app/config/propel.ini (create if not existing):

propel.behavior.typehintable.class = vendor.TypehintableBehavior.src.TypehintableBehavior

Run following commands:

php app/console propel:build

Extend the backend

Menu

If you want to extend the menu you have to do the following steps.

1: Override AdminMenu

Create a file "AdminMenu.php" in "YourProject/src/YourBundle/Menu/"

Extend DefaultMenuBuilder (Admingenerator\GeneratorBundle\Menu\DefaultMenuBuilder)

Override the "navbarMenu" function as you want

class AdminMenu extends DefaultMenuBuilder
{
    protected $translation_domain = 'Admin';

    public function navbarMenu(FactoryInterface $factory, array $options)
    {
        $menu = $factory->createItem('root');
        $menu->setChildrenAttributes(array('id' => 'main_navigation', 'class' => 'nav'));

        //Your custom Menu
        $users = $this->addDropdown($menu, 'Logins');
        $this->addLinkRoute($users, 'Users', 'Edge5_AppBackendBundle_User_list');
        $this->addLinkRoute($users, 'Groups', 'Edge5_AppBackendBundle_Group_list');

        // Just some examples
        $this->addLinkRoute($menu, 'Customers', 'Edge5_BackendBundle_Customer_list');
        $this->addLinkRoute($menu, 'Products', 'Edge5_BackendBundle_Product_list');

        $this->addLinkRoute($menu, 'Translations', 'Edge5_AppBackendBundle_Translation_list');

        return $menu;
    }
}

In "parameters.yml" set "edge5.set menu_builder.class"

parameters:
    edge5.menu_builder.class: Vendor\YourBundle\Menu\AdminMenu

2: Define Dashboard view

Create a DashboardController (YourBundle/Controller/DashboardController.php)

This Controller returns the view for the dashboard (base_dashboard.html.twig)

class DashboardController extends Controller
{
    public function indexAction()
    {
        return $this->render('YourBundle::base_dashboard.html.twig');
    }
}

Register route for the dashboard and define base_admin_template in "app/config/config.yml"

admingenerator_generator:
    base_admin_template: YourBundle::base_admin.html.twig
    dashboard_welcome_path: dashboard

3: Create Views

In "YourBundle/Resources/views" create

  • base_dashboard.html.twig
  • base_admin.html.twig
  • base_admin_navbar.html.twig

In "base_admin_navbar.html.twig" render the correct Menu (Menu from your custom AdminMenuController)

{% extends 'Edge5AppBackendBundle::base_admin_navbar.html.twig' %}
{% block menu %}
    {{ knp_menu_render('YourBundle:AdminMenu:navbarMenu') }}
{% endblock %}

Include "base_admin_navbar.html.twig" in "base_admin.html.twig" and "base_dashboard.html.twig"

{% extends 'Edge5AppBackendBundle::base_admin.html.twig' %}
{% block navbar %}
    {% include 'Edge5BackendBundle::base_admin_navbar.html.twig' %}
{% endblock navbar %}

4: Clear cache

php app/console cache:clear