ras/flash-alert-bundle

FlashAlertBundle provides a simplified way to handle (add/display) Symfony flash messages. Client side scripts are written in pure JavaScript.

Installs: 22 984

Dependents: 1

Suggesters: 1

Security: 0

Stars: 23

Watchers: 4

Forks: 8

Type:symfony-bundle

2.1.1 2016-01-03 21:38 UTC

This package is not auto-updated.

Last update: 2024-11-09 17:19:31 UTC


README

Join the chat at https://gitter.im/rasanga/FlashAlertBundle FlashAlertBundle is an open source Bundle which simplifies displaying flash alerts such as success, error, info and warning

Build Status Scrutinizer Code Quality

Demo screenshot

Table of Contents

  1. Installation
  2. Download the FlashAlertBundle
  3. Enable the bundle
  4. Configure the bundle
  5. Usage
  6. Report flash alerts
  7. Display flash alerts
  8. Configuration
  9. Override view template
  10. Add custom styles
  11. Changelog
  12. License

Installation

Step 1: Download the FlashAlertBundle

Using Composer Add the following to the "require" section of your composer.json file:

    "ras/flash-alert-bundle": "dev-master"

And update your dependencies

    php composer.phar update

Using submodules Execute the following command on your project root:

$ git submodule add git@github.com:rasanga/FlashAlertBundle.git vendor/bundles/Ras/FlashAlertBundle
$ git submodule update --init

Step 2: Enable the bundle

Registers the bundle in your app/AppKernel.php:

<?php
...
public function registerBundles()
{
    $bundles = array(
        ...
        new Ras\Bundle\FlashAlertBundle\RasFlashAlertBundle(),
        ...
    );
...

Step Optional, if you are not using composer: Configure the Autoloader

Add the following to your autoload.php:

<?php
...
'Ras' => __DIR__.'/../vendor/bundles',

Usage

Report flash alerts

Add the following PHP code to report an alert message:

    $this->get('ras_flash_alert.alert_reporter')->addError("Access denied");

Note: You can choose one of the following functions to call from $this->get('ras_flash_alert.alert_reporter')

    addSuccess()
    addError()
    addWarning()
    addInfo()

Display flash alerts

Add the following twig code where you want to display alert messages:

    {{ render_flash_alerts() }}

Note 1: The parent twig template would be the best place for displaying flash alerts

Configuration

The following parameters can be overriden in your config.yml or similar:

ras_flash_alert:
    template: '::flashAlerts.html.twig'     # defaults to 'RasFlashAlertBundle::layout.html.twig'
    isAddStyles: false                      # defaults to true
    isAddJsAlertClose: false                # defaults to true

These can also be passed as parameters in the view when rendering alerts - for example:

    {{ render_flash_alerts({ 'template': '::flashAlerts.html.twig', 'isAddStyles': false }) }}

Override view template

  1. Create template in the /Resources/views/ or in your bundle
  2. Retrieve alerts into your template with {{ get_alert_publisher() }}
  3. Include template blocks in FlashAlertBundle/Resources/views/FlashAlert directory or define your own blocks (follow FlashAlertBundle/Resources/views/FlashAlert/flashAlerts.html.twig to see how you can define your own template)

Add custom styles

The bundle default template has styles defined by default. However, you can turn off default styles by configuring isAddStyles variable to false as shown in below.

    {{ render_flash_alerts({ 'isAddStyles': false }) }}

Then you can define your own styles to match alert classes such as alert, alert-close, alert-success, alert-error, alert-warning and alert-info

CHANGELOG

2.0

Add twig method for rendering alerts: `{{ render_flash_alerts() }}`
Add twig method for retrieving alerts: `{{ get_alert_publisher() }}`
Deprecated controller view render 

LICENSE

FlashAlertBundle is licensed under the MIT Open Source license.

Bitdeli Badge