symfonycontrib / confirm-bundle
Symfony confirmation form bundle.
This package's canonical repository appears to be gone and the package has been frozen as a result.
Installs: 8 207
Dependents: 1
Suggesters: 0
Security: 0
Stars: 6
Watchers: 2
Forks: 2
Open Issues: 0
Requires
- symfony/symfony: ^3.1
This package is not auto-updated.
Last update: 2024-06-19 10:12:58 UTC
README
This code is part of the SymfonyContrib community.
Symfony2 ConfirmBundle
Provides a simple confirmation form & page to confirm an action.
Use Case
If you are going to delete an object and want to confirm with the user that they really do want to delete the object, you will usually send them to a confirmation page for verification.
This is a very common scenario and so is an area where code can easily be duplicated.
Installation
Installation is the same as a normal bundle. http://symfony.com/doc/current/cookbook/bundles/installation.html
- Add bundle to composer
composer require symfonycontrib/confirm-bundle
- Add bundle to AppKernel.php:
new SymfonyContrib\Bundle\ConfirmBundle\ConfirmBundle(),
Usage
Using the ConfirmBundle is very simple. In short, you simply forward your request with some options.
Example:
public function objectDeleteAction($object) { $options = [ 'message' => 'Are you sure you want to DELETE this?', 'warning' => 'This can not be undone!', 'confirmButtonText' => 'Delete', 'confirmAction' => [$this, 'delete'], 'confirmActionArgs' => [ 'object' => $object, ], 'cancelLinkText' => 'Cancel', 'cancelUrl' => $this->generateUrl('acme_home'), ]; return $this->forward('ConfirmBundle:Confirm:confirm', ['options' => $options]); } public function delete($args) { // delete object // set flash message // redirect }
Options
- message: (string) Message displayed to user.
- warning: (Optional) (string) A warning to display to the user.
- confirmButtonText: (string) Text for positive confirmation button.
- confirmAction: (mixed) PHP callable. http://php.net/manual/en/language.types.callable.php
- confirmActionArgs: (Optional) (array) Array of arguments that will be passed to the confirmAction callable as an array argument.
- cancelLinkText: (string) Text for negative cancellation link.
- cancelUrl: (string) URL that will be used for the cancel action link.
Views
There are 3 twig templates provided to override how the form and page looks.
- layout.html.twig: Simple template to override to easily change the base template that is extended.
- confirm-form.html.twig: Template for the confirmation form.
- confirm.html.twig: Template for the wrapper around the confirmation form.