2017 © Pedro Peláez
 

symfony-bundle front-bundle

Symfony Front Twig Extension Bundle

image

tangoman/front-bundle

Symfony Front Twig Extension Bundle

  • Sunday, April 8, 2018
  • by Tangoman
  • Repository
  • 0 Watchers
  • 0 Stars
  • 95 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 5 Versions
  • 1 % Grown

The README.md

TangoMan Front Bundle

TangoMan Front Bundle provides an easy way to add front elements to your pages. TangoMan Front Bundle makes building back-office for your app a brease., (*1)

Features

  • Navigation bar
    • Dropdown
  • Menus
  • Tabs
  • Buttons
  • Search forms
    • Inputs
    • Selects
    • Options
      • Optgroups
    • Checkboxes
    • Radio buttons
    • Reset button
    • Submit button

All elements can :, (*2)

  • Own class
  • Own id

Links, buttons, menu items, tabs can :, (*3)

  • Own icons
  • Own translatable labels
  • Own badges
  • Own parameters
  • Being disabled
  • Being displayed on specific pages
  • Being firewalled
  • Trigger callbacks
  • Show tooltips
  • Toggle popovers
  • Toggle modals
  • Toggle dropdowns
  • Toggle accordion

And buttons can :, (*4)

  • Submit form on change

You can easily create your own template as well., (*5)

Installation

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:, (*6)

$ composer require tangoman/front-bundle

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation., (*7)

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:, (*8)

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    // ...

    public function registerBundles()
    {
        $bundles = array(
            // ...
            new TangoMan\FrontBundle\TangoManFrontBundle(),
            new TangoMan\CallbackBundle\TangoManCallbackBundle(),
        );

        // ...
    }
}

Since TangoMan Front Bundle requires TangoMan Callback Bundle enable it in the app/AppKernel.php as well., (*9)

Usage

Front Assets

Assets should copy automatically, if for whatever reason you need to reinstall them manually type following command :, (*10)

$ php bin/console assets:install TangoManFrontBundle

In order for elements to display properly include the following <link> tag in your ::base.html.twig Wich will enable TangoMan Front Bundle custom css. (You can use your own css is you want to.), (*11)

{% block stylesheet %}
    {{ parent() }}
    <link rel="stylesheet" href="{{ asset('bundles/tangomanfront/css/tangoman-front-bundle.css') }}">
{% endblock %}

In order for forms to behave like expected include the following <script> tags inside your javascript block., (*12)

{% block javascript %}
    {{ parent() }}
    <script src="{{ asset('bundles/tangomanfront/js/tangoman-front-bundle.js') }}"></script>
{% endblock %}

If you're using default navbar template, name your routes like the following:, (*13)

  • 'app_login'
  • 'app_check'
  • 'app_logout'
  • 'app_user_profile'
  • 'app_user_edit'
  • 'app_admin_index'
  • 'homepage'

Search / filter form component

Place use statement in the controller

use TangoMan\FrontBundle\Model\Button;
use TangoMan\FrontBundle\Model\ButtonGroup;
use TangoMan\FrontBundle\Model\Item;
use TangoMan\FrontBundle\Model\Menu;
use TangoMan\FrontBundle\Model\Modal;
use TangoMan\FrontBundle\Model\SearchForm;
use TangoMan\FrontBundle\Model\SearchInput;
use TangoMan\FrontBundle\Model\SearchOption;
use TangoMan\FrontBundle\Model\Th;
use TangoMan\FrontBundle\Model\Thead;

Build object in the controller

<?php
// AppBundle/Controller/DefaultController.php
namespace AppBundle\Controller;

// ...

class DefaultController extends Controller
{
    /**
     * @Route("/user/index")
     */
    public function indexAction()
    {
        // ...

        $form = new SearchForm();

        // Number
        $input = new SearchInput();
        $input->setLabel('Id')
            ->setName('e-id')
            ->setType('number');
        $form->addInput($input);

        // Text
        $input = new SearchInput();
        $input->setLabel('User')
            ->setName('user-username')
            ->setType('text');
        $form->addInput($input);

        // Select
        $input = new SearchInput();
        $input->setLabel('Role')
            ->setName('roles-type')
            ->setPlaceholder('All')
            ->setType('select');

        $option = new SearchOption();
        $option->setName('Administrator')
            ->setValue('ROLE_ADMIN');
        $input->addOption($option);

        $option = new SearchOption();
        $option->setName('User')
            ->setValue('ROLE_USER');
        $input->addOption($option);
        $form->addInput($input);

        // Submit
        $input = new SearchInput();
        $input->setLabel('Filter')
            ->setType('submit')
            ->setIcon('glyphicon glyphicon-search');
        $form->addInput($input);

        return $this->render(
            'user/index.html.twig',
            [
                'form' => $form,
                'users' => $users,
            ]
        );
    }
}

Integrate in Twig

<div id="search-form" class="jumbotron">
    {{ searchForm(form) }}
</div>

Ordered list component

<table class="table table-striped">
    {{ thead(thead) }}
    <tbody>
    {% for user in users %}
        <tr>
            <td>
            ...

Inputs

Attribute Status Default value
class optional form-control
disabled optional null
icon optional null
id optional tango-input-{{ input.name }}
label optional null
name mandatory null
pages optional []
placeholder optional null
roles optional ['IS_AUTHENTICATED_ANONYMOUSLY']
submit optional false
type optional text
value auto app.request.get(input.name)

Selects

Attribute Status Default value
class optional 'form-control'
disabled optional null
icon optional null
id optional tango-select-{{ input.name }}
label optional null
name mandatory null
options optional null
pages optional []
placeholder optional null
roles optional ['IS_AUTHENTICATED_ANONYMOUSLY']
submit optional false
type optional 'text'

Buttons

Attribute Status Default value
attributes optional null
badge optional null
class optional 'btn btn-primary'
data optional null
disabled optional null
href optional null
icon optional null
id optional null
label optional null
pages optional []
parameters optional null
roles optional ['IS_AUTHENTICATED_ANONYMOUSLY']
route mandatory null
Attribute Status Default value
attributes optional null
badge optional null
class optional null
data optional null
disabled optional null
href optional null
icon optional null
id optional null
label optional null
pages optional []
parameters optional null
roles optional ['IS_AUTHENTICATED_ANONYMOUSLY']
route mandatory null

Options

Attribute Status Default value
disabled optional null
id optional null
name mandatory null
pages optional []
roles optional ['IS_AUTHENTICATED_ANONYMOUSLY']
value mandatory null

Examples

Inputs

"inputs": [
    {
        "type": "text",
        "icon": "glyphicon glyphicon-user",
        "name": "user-username",
        "label": "User"
    },
    {
        "type": "email",
        "icon": "glyphicon glyphicon-envelope",
        "name": "user-email",
        "label": "Email"
    }
]

Selects

"inputs": [
    {
        "type": "select",
        "name": "roles-type",
        "label": "Role",
        "icon": "glyphicon glyphicon-king",
        "placeholder": "All roles",
        "options": [
            {
                "name": "Super Admin",
                "value": "ROLE_SUPER_ADMIN"
            },
            {
                "name": "Admin",
                "value": "ROLE_ADMIN"
            },
            {
                "name": "Super User",
                "value": "ROLE_SUPER_USER"
            },
            {
                "name": "User",
                "value": "ROLE_USER"
            }
        ]
    }
]

Optgroups

"inputs": [
    {
        "type": "select",
        "name": "foo",
        "label": "Test",
        "icon": "fa fa-facebook",
        "placeholder": "Test",
        "optgroups": [
            {
                "label": "FooGroup",
                "options": [
                    {
                        "name": "Foo 1",
                        "value": "foo1"
                    },
                    {
                        "name": "Foo 2",
                        "value": "foo2"
                    }
                ]
            },
            {
                "label": "BarGroup",
                "disabled": true,
                "options": [
                    {
                        "name": "Bar 1",
                        "value": "bar1"
                    },
                    {
                        "name": "Bar 2",
                        "value": "bar2"
                    }
                ]
            }
        ]
    }
]

Buttons

"buttons": [
   {
       "icon": "glyphicon glyphicon-edit",
       "label": "Edit",
       "class": "btn btn-warning btn-sm",
       "route": "app_admin_user_edit",
       "tooltip": "Edit '~user~' profile",
       "parameters": {
           "id": '~user.id~'
       },
       "roles": ["ROLE_ADMIN","ROLE_SUPER_ADMIN"]
   },
   {
       "icon": "glyphicon glyphicon-trash",
       "label": "Delete",
       "class": "btn btn-danger btn-sm",
       "route": "app_admin_user_delete",
       "parameters": {
           "id": '~user.id~'
       },
       "tooltip": "Delete '~user~' profile",
       "modal": ".my-modal",
       "roles": ["ROLE_ADMIN","ROLE_SUPER_ADMIN"]
   }
]

Button Groups

"inputs": [
    {
        "type": "buttonGroup",
        "class": "pull-right",
        "buttons": [
            {
                "type": "submit",
                "label": "Filter",
                "badge": '~users|length~',
                "icon": "glyphicon glyphicon-search"
            },
            {
                "type": "reset",
                "label": "Reset",
                "icon": "glyphicon glyphicon-remove",
                "class": "btn btn-warning"
            }
        ]
    }]

TangoMan Front Bundle classes

  • .tango-actions
  • .tango-btn-group
  • .tango-button-badge
  • .tango-button-icon
  • .tango-form
  • .tango-form-btn
  • .tango-form-checkbox
  • .tango-form-group
  • .tango-link-badge
  • .tango-link-icon
  • .tango-thead
  • .tango-tooltip-wrapper

Error

When you get to see Twig_Error_Runtime Symfony Exception, (*14)

Impossible to access an attribute ("foobar") on a null variable., (*15)

It means your json is invalid. Don't worry you probrably just missed a comma somewhere., (*16)

Bootstrap 3 toggles

Title Toggle Parameters Attributes Link
Button data-toggle="button" buttons-single-toggle
Buttons data-toggle="buttons" buttons
Collapse data-toggle="collapse" data-target data-parent href collapse
Dropdowns data-toggle="dropdown" dropdowns
Modals data-toggle="modal" data-target="..." rel="modal" modals
Popovers data-toggle="popover" data-placement data-trigger data-content title rel="popover" popovers
Togglable pills data-toggle="pill" pills
Togglable tabs data-toggle="tab" tabs
Tooltips data-toggle="tooltip" data-original-title data-placement title tooltips

Note

If you find any bug please report here : Issues, (*17)

License

Copyright (c) 2018 Matthias Morin, (*18)

License Distributed under the MIT license., (*19)

If you like TangoMan Front Bundle please star! And follow me on GitHub: TangoMan75 ... And check my other cool projects., (*20)

Matthias Morin | LinkedIn, (*21)

The Versions

08/04 2018

dev-master

9999999-dev

Symfony Front Twig Extension Bundle

  Sources   Download

The Requires

 

by Matthias Morin

service twig extension bootstrap bundle symfony responsive navbar forms list menus buttons ordered front searchable back office tangoman paginated

08/04 2018

1.1.3

1.1.3.0

Symfony Front Twig Extension Bundle

  Sources   Download

The Requires

 

by Matthias Morin

service twig extension bootstrap bundle symfony responsive navbar forms list menus buttons ordered front searchable back office tangoman paginated

19/03 2018

1.1.2

1.1.2.0

Symfony Front Twig Extension Bundle

  Sources   Download

The Requires

 

by Matthias Morin

service twig extension bootstrap bundle symfony responsive navbar forms list menus buttons ordered front searchable back office tangoman paginated

31/10 2017

1.1.0

1.1.0.0

Symfony Front Twig Extension Bundle

  Sources   Download

The Requires

 

by Matthias Morin

service twig extension bootstrap bundle symfony responsive navbar forms list menus buttons ordered front searchable back office tangoman paginated

24/10 2017

1.0.0

1.0.0.0

Symfony Front Twig Extension Bundle

  Sources   Download

The Requires

 

by Matthias Morin

service twig extension bootstrap bundle symfony responsive navbar forms list menus buttons ordered front searchable back office tangoman paginated