GithubHelp home page GithubHelp logo

rasanga / flashalertbundle Goto Github PK

View Code? Open in Web Editor NEW
23.0 4.0 8.0 63 KB

Simplified way to handle (add/display) Symfony flash messages. Client side scripts are written in pure JavaScript. https://packagist.org/packages/ras/flash-alert-bundle

Home Page: http://rasanga.github.io/FlashAlertBundle

License: MIT License

PHP 82.04% HTML 17.96%

flashalertbundle's Introduction

FlashAlertBundle

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 [email protected]: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

flashalertbundle's People

Contributors

bitdeli-chef avatar bjdelange avatar gitter-badger avatar johnmadrak avatar luiztiago avatar rasanga avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

flashalertbundle's Issues

Twig Deprecation Warning

Just after installing your bundle in my Symfony 3.2 project, I got this deprecation warning:
The Twig_Function_Method class is deprecated since version 1.12 and will be removed in 2.0. Use Twig_SimpleFunction instead.

This is because you use the Twig_function_method class in vendor/ras/flash-alert-bundle/Ras/Bundle/FlashAlertBundle/Twig/FlashAlertsExtension.php:47,50

Are you planning to fix this?
Thanks in advance! :)

Doesn't work with Symfony 3.3

The services.yml files doesn't allow key'd arguments in the latest version of symfony (3.3)

Example:

Broken:
services: ras_flash_alert.alert_reporter: class: Ras\Bundle\FlashAlertBundle\Model\AlertReporter arguments: alertManager: "@ras_flash_alert.alert_manager"

Fixed
services: ras_flash_alert.alert_reporter: class: Ras\Bundle\FlashAlertBundle\Model\AlertReporter arguments: ["@ras_flash_alert.alert_manager"]

Since this repo doesn't seem to be maintained anymore I forked the repo and made the fix there. (Also added fix to twig deprecation error from other issue reported)

https://github.com/edinchev/FlashAlertBundle

Auto hide

Is there a way to auto hide the flash alerts after some seconds?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.