2017 © Pedro Peláez
 

symfony-bundle widget-bundle

Provides re-usable widgets in templating

image

symedit/widget-bundle

Provides re-usable widgets in templating

  • Wednesday, February 1, 2017
  • by isometriks
  • Repository
  • 1 Watchers
  • 0 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 21 Versions
  • 0 % Grown

The README.md

SymEdit Widget Bundle

Configuration, (*1)

symedit_widget:
    driver:               doctrine/orm

    # Fragment stategy to use
    fragment:
        strategy:             inline
    classes:
        widget:
            model:                SymEdit\Bundle\WidgetBundle\Model\Widget
            controller:           SymEdit\Bundle\WidgetBundle\Controller\WidgetController
            respository:          ~
            form:                 SymEdit\Bundle\WidgetBundle\Form\Type\WidgetType
        widget_area:
            model:                SymEdit\Bundle\WidgetBundle\Model\WidgetArea
            repository:           ~
            form:                 SymEdit\Bundle\WidgetBundle\Form\Type\WidgetAreaType

Creating a Strategy

Build your strategy class:, (*2)

namespace SymEdit\Bundle\WidgetBundle\Widget\Strategy;

use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class MyStrategy extends AbstractWidgetStrategy
{
    public function execute(WidgetInterface $widget)
    {
        return $this->render($widget, array(
            'number' => $widget->getOption('number'),
        ));
    }

    public function getDefaultOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'template' => 'MyBundle:Widget:mywidget.html.twig',
            'number' => 5,
        ));
    }

    /**
     * Return array of options to pass to Response::setCache,
     * if it should not be cached return array('private' => true)
     */
    public function getCacheOptions(WidgetInterface $widget)
    {
        return array(
            'public' => true,
            'last_modified' => $widget->getUpdatedAt(),
        );
    }

    public function buildForm(FormBuilderInterface $builder)
    {
        $builder
            ->add('number', 'integer')
        ;
    }

    public function getName()
    {
        return 'number';
    }

    public function getDescription()
    {
        return 'widget.number'; // Translated
    }
}

Add it to your services:, (*3)

<service id="mywidget.number" class="%mywidget.number.class%">
    <tag name="symedit_widget.widget_strategy" alias="number" />
</service>

Rendering Widgets

This renders a widget area:, (*4)

{{ symedit_widget_area_render('footer') }}

In your widget area templates you should use:, (*5)

{% for widget in widgets %}
    {{ symedit_widget_render(widget) }}
{% endfor %}

This is a passthrough for the fragment renderer so if you turn on ESI then you can cache the rest of your page except for the widgets., (*6)

The Versions

01/02 2017

dev-master

9999999-dev

Provides re-usable widgets in templating

  Sources   Download

06/11 2015

v0.11

0.11.0.0

Provides re-usable widgets in templating

  Sources   Download

19/05 2015

v0.10.0

0.10.0.0

Provides re-usable widgets in templating

  Sources   Download

06/11 2014

v0.9.2

0.9.2.0

Provides re-usable widgets in templating

  Sources   Download

06/11 2014

v0.9.3

0.9.3.0

Provides re-usable widgets in templating

  Sources   Download

29/10 2014

v0.9

0.9.0.0

Provides re-usable widgets in templating

  Sources   Download

29/10 2014

v0.9.1

0.9.1.0

Provides re-usable widgets in templating

  Sources   Download

11/06 2014

v0.5.1

0.5.1.0

Provides re-usable widgets in templating

  Sources   Download

11/06 2014

v0.6

0.6.0.0

Provides re-usable widgets in templating

  Sources   Download

11/06 2014

v0.6.1

0.6.1.0

Provides re-usable widgets in templating

  Sources   Download

11/06 2014

v0.7

0.7.0.0

Provides re-usable widgets in templating

  Sources   Download

11/06 2014

v0.8

0.8.0.0

Provides re-usable widgets in templating

  Sources   Download

22/05 2014

v0.4.0

0.4.0.0

Provides re-usable widgets in templating

  Sources   Download

22/05 2014

v0.5.0

0.5.0.0

Provides re-usable widgets in templating

  Sources   Download

19/05 2014

v0.3.3

0.3.3.0

Provides re-usable widgets in templating

  Sources   Download

19/05 2014

v0.3.4

0.3.4.0

Provides re-usable widgets in templating

  Sources   Download

15/05 2014

v0.3.0

0.3.0.0

Provides re-usable widgets in templating

  Sources   Download

15/05 2014

v0.3.1

0.3.1.0

Provides re-usable widgets in templating

  Sources   Download

15/05 2014

v0.3.2

0.3.2.0

Provides re-usable widgets in templating

  Sources   Download

18/04 2014

v0.2

0.2.0.0

Provides re-usable widgets in templating

  Sources   Download

18/04 2014

v0.2.1

0.2.1.0

Provides re-usable widgets in templating

  Sources   Download