2017 © Pedro Peláez
 

symfony-bundle platform-widget-bundle

DigitalState Widget Bundle

image

digitalstate/platform-widget-bundle

DigitalState Widget Bundle

  • Tuesday, February 21, 2017
  • by ds
  • Repository
  • 2 Watchers
  • 0 Stars
  • 155 Installations
  • PHP
  • 6 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Platform-Widget-Bundle

The Widget bundle provides the developers a way to define widgets in the user interface., (*1)

Code Climate Test Coverage, (*2)

Table of Contents

Widget Entity

A widget consists of a title and content meant to be displayed in a template in a specific position. Essentially, it allows the developer to customise templates without directly modifying the template files. Widgets are comparable to ORO Placeholders with two additional features: the capability of adding a title and the context filter., (*3)

Note: Eventually, if possible, we will merge the concept of widgets to ORO Placeholders with our additional features., (*4)

Creating a Widget

Widgets can be created in any bundle. They are defined the same way as any other services in Symfony using the Service Container. The developer will need to tag the service with the ds.widget tag in order for the system to pick it up as a widget. Finally, the developer will need to define a position in a template file, where the widget should be displayed., (*5)

The widget class src/Gov/Bundle/BlogBundle/Widget/LatestPostsWidget.php:, (*6)

<?php

namespace Gov\Bundle\BlogBundle\Widget;

use Ds\Bundle\WidgetBundle\Widget\Widget;

class LatestPostsWidget extends Widget
{
    public function getTitle()
    {
        return 'Latest Posts';
    }

    public function getContent(array $data = [])
    {
        return '<ul><li><a href="">Post 1</a></li><li><a href="">Post 2</a></li></ul>';
    }
}

The widget service src/Acme/Bundle/TestBundle/Resources/config/services.yml:, (*7)

services:
    gov.blog.widget.latest_posts:
        parent: ds.widget.widget.abstract
        class: Gov\Bundle\BlogBundle\Widget\LatestPostsWidget
        tags:
            - { name: ds.widget, position: aside }

The template position:, (*8)

<html>
    <body>
        <aside>
            {% for widget in ds_widgets({ position: 'aside' }) %}
                <h3>{{ widget.title }}</h3>
                {{ widget.content|raw }}
            {% endfor %}
        </aside>
    </body>
</html>

Context Filter

The context filter is an optional parameter allowing the developer to define when a Widget should be rendered., (*9)

Let's use a real world example to explain the concept:, (*10)

The DigitalState-Platform introduces the concept of Government Services through the DsServiceBundle. This bundle provides, at its core, the base actions for creating, editing, and deleting Generic Services. The editing action uses of the Widget concept for displaying the core form fields for the Generic Service., (*11)

The DigitalState-Platform also introduces the concept of BPM Services through the DsServiceBpmBundle. This bundle grafts itself on top of the DsServiceBundle to provide additional BPM-related functionality for when a business user wishes to create a BPM-based Service. A BPM Service is the same as a Generic Service, with additional fields to map the BPM process definition id and other BPM specific configurations. The DsServiceBpmBundle defines an additional Widget for the additional form fields and flags the context of the widget as bpm, meaning this Widget should only be displayed the specific context of BPM., (*12)

The template position with context defined:, (*13)

<html>
    <body>
        <main>
            <form>
                {% for widget in ds_widgets({ position: 'main', context: 'bpm' }) %}
                    <h3>{{ widget.title }}</h3>
                    {{ widget.content|raw }}
                {% endfor %}
            </form>
        </main>
    </body>
</html>

Todo

Introduce custom twig tag for widget positions., (*14)

Example 1:, (*15)

{% position *position_name* with { variable: value } %}

Example 2:, (*16)

{% position *position_name* %}
    {{ widget.title }}
    {{ widget.content|raw }}
{% endposition %}

Enable widgets to be defined as template or callbacks, instead of classes., (*17)

The Versions

21/02 2017

dev-master

9999999-dev https://github.com/DigitalState/Platform-Widget-Bundle.git

DigitalState Widget Bundle

  Sources   Download

MIT

The Requires

 

communication oro

21/02 2017

dev-develop

dev-develop https://github.com/DigitalState/Platform-Widget-Bundle.git

DigitalState Widget Bundle

  Sources   Download

MIT

The Requires

 

communication oro

21/02 2017

0.3.0

0.3.0.0 https://github.com/DigitalState/Platform-Widget-Bundle.git

DigitalState Widget Bundle

  Sources   Download

MIT

The Requires

 

communication oro

09/02 2017

0.2.0

0.2.0.0 https://github.com/DigitalState/Platform-Widget-Bundle.git

DigitalState Widget Bundle

  Sources   Download

MIT

The Requires

 

communication oro

20/01 2017

0.1.2

0.1.2.0 https://github.com/DigitalState/Platform-Widget-Bundle.git

DigitalState Widget Bundle

  Sources   Download

MIT

The Requires

 

communication oro

10/01 2017

0.1.0

0.1.0.0 https://github.com/DigitalState/Platform-Widget-Bundle.git

DigitalState Widget Bundle

  Sources   Download

MIT

The Requires

 

communication oro

10/01 2017

0.1.1

0.1.1.0 https://github.com/DigitalState/Platform-Widget-Bundle.git

DigitalState Widget Bundle

  Sources   Download

MIT

The Requires

 

communication oro