2lenet/dashboard-bundle

Dashboard bundle, widgets

Maintainers

Details

github.com/2lenet/dashboard

Source

Installs: 249

Dependents: 0

Suggesters: 0

Stars: 1

Watchers: 5

Forks: 2

Type:symfony-bundle

1.1.1 2019-03-04 18:15 UTC

README

This bundle provides a dashboard with customizable widgets.

Note that the docs are still in work, and that the bundle will probably be rebranded.

Setting up the bundle

Add this to services.yaml

App\Widgets\:
        resource: '../src/Widgets'
        tags: ['tkuska_dashboard.widget']

Add this to routes.yaml

dashboard_widgets:
    resource: "@TkuskaDashboardBundle/Resources/config/routes.yaml"

You also need to update your database to have widget table.

php bin/console doctrine:schema:update

Making widgets

All your widget classes will lie in src/Widgets/.

They must extend AbstractWidget.

use Tkuska\DashboardBundle\Widgets\AbstractWidget;

Existing methods that can be overriden:

  • __construct: the constructor for usual services injection. You need at least a Twig_Environment ($twig)
  • getName: must return general name of the widget
  • getJsonSchema: must return an array (that will be json encoded) that represents an Json Schema, for the widget configuration. (see also https://github.com/json-editor/json-editor)
  • getConfigForm: makes the configuration form. You shouldn't need to modify it, but it can happen in some cases (ex: bootstrap version)

You must implement the render() method.

This method returns simple HTML. You can use $twig->render("template.html.twig", array(...)). Your templates should extend the base widget template, because it has some interactions. Otherwise, make sure you implement those interactions.

{% extends '@TkuskaDashboard/widget/base_widget.html.twig' %}

If you use the widget configuration (getJsonSchema) you must pass the form to the template with getConfigForm as 'form'.

This method renders the widget that is shown. All your logic should be in there.