fsi/admin-positionable-bundle

FSi admin positionable bundle.

Installs: 10 012

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 6

Forks: 7

Open Issues: 2

Type:symfony-bundle

2.1.0 2019-08-06 12:35 UTC

This package is auto-updated.

Last update: 2022-01-10 12:21:25 UTC


README

This bundle provides way to change position of item on the list gradually. This mean that position will be changed by 1.

FSiAdminPositionableBundle works with conjunction with Sortable behavior extension for Doctrine2

Usage

Add to AppKernel.php:

new FSi\Bundle\AdminPositionableBundle\FSiAdminPositionableBundle(),

Add routes to /app/config/routing.yml:

_fsi_positionable:
    resource: "@FSiAdminPositionableBundle/Resources/config/routing/positionable.xml"
    prefix:   /admin

Sample entity:

Note: @Gedmo\Mapping\Annotation\SortablePosition points column to store position index

use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use FSi\Bundle\AdminPositionableBundle\Model\PositionableInterface;

class Promotion implements PositionableInterface
{
    /**
     * @Gedmo\SortablePosition
     * @ORM\Column(type="integer")
     */
    protected $position;

    /**
     * {@inheritdoc}
     */
    public function increasePosition()
    {
        $this->position++;
    }

    /**
     * {@inheritdoc}
     */
    public function decreasePosition()
    {
        $this->position--;
    }
}

Note: that PositionableInterface implementation is required

Sample datagrid definition:

columns:
  title:
    type: text
    options:
      display_order: 1
      label: "backend.promotions.datagrid.title.label"
  actions:
    type: action
    options:
      display_order: 2
      label: "backend.promotions.datagrid.actions.label"
      field_mapping: [ id ]
      actions:
        move_up:
          route_name: "fsi_admin_positionable_decrease_position"
          additional_parameters: { element: "promotions" }
          parameters_field_mapping: { id: id }
          content: <span class="glyphicon glyphicon-arrow-up icon-white"></span>
          url_attr: { class: "btn btn-warning btn-sm" }
        move_down:
          route_name: "fsi_admin_positionable_increase_position"
          additional_parameters: { element: "promotions" }
          parameters_field_mapping: { id: id }
          content: <span class="glyphicon glyphicon-arrow-down icon-white"></span>
          url_attr: { class: "btn btn-warning btn-sm" }