A widget should be configured in a page as follow :
ListComments:
title: Comments widget
description: My description goes here
columns: 12
service: AppBundle\Service\Widgets\Comment
Item
Description
Required
Identifier or Name
This is a uniq identifier of the widget on a page.
Yes
title
Title of the widget
No
description
Description of the widget
No
columns
Number of columns the widget should take (max 12)
Yes
service
Path or alias of the service.
Yes
template
Template to use for rendering
No
Service class creation
abstract class AbstractWidget {
public function __construct( RequestStack $requestStack, \Twig_Environment $twig, EntityManager $em )
protected function getDoctrine ()
protected function getCurrentRequest()
protected function render ( $template, $parameters )
public abstract function create ( $configuration, MessageBag $messageBag);
}
Your widget should be located in the namespace :
namespace AppBundle\Service\Widgets;
The class must extend AbstractWidget from "Tellaw\SunshineAdminBundle\Service"
getDoctrine()
This method return an entityManager.
getCurrentRequest()
This method return the current request.
render($template, $parameters)
This method return the rendered template. Merging template and parameters array.
The template name should contains the path, but should not contains extension.
create ( $configuration, MessageBag $messageBag)
This method is called by the page to render your widget. Implement here your business logic.
View creation
The view is a simple Twig template. You can access any parameters you sent to it.
For more informations, please, read Twig documentation.
MessageBag : Send informations to widget
The message bag is a message bus making possible for you to send messages from a page to the widgets.
The messageBag is an attribut you can access from Pages and Widgets.
namespace Tellaw\SunshineAdminBundle\Entity;
class MessageBag {
private $messageBag = array();
public function addMessage ( $key, $message );
public function getMessage ( $key );
}
Use the addMessage method to save a message, and getMessage to read it.
Forms inside a widget
As widgets can access to the request, you can easily create forms. The following syntax is very similar to a basic Symfony Controller