{"id":20499816,"url":"https://github.com/sherlockode/sonatasortablebundle","last_synced_at":"2026-04-24T03:33:27.658Z","repository":{"id":64377065,"uuid":"574857685","full_name":"sherlockode/SonataSortableBundle","owner":"sherlockode","description":null,"archived":false,"fork":false,"pushed_at":"2023-04-13T08:07:44.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-01-16T06:58:14.448Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sherlockode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-06T08:20:54.000Z","updated_at":"2022-12-07T09:48:01.000Z","dependencies_parsed_at":"2024-11-15T18:18:51.580Z","dependency_job_id":"855bb97e-2e79-4463-908c-59d1dbf6cd71","html_url":"https://github.com/sherlockode/SonataSortableBundle","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sherlockode%2FSonataSortableBundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sherlockode%2FSonataSortableBundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sherlockode%2FSonataSortableBundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sherlockode%2FSonataSortableBundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sherlockode","download_url":"https://codeload.github.com/sherlockode/SonataSortableBundle/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242090359,"owners_count":20070138,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-15T18:18:35.121Z","updated_at":"2026-04-24T03:33:27.617Z","avatar_url":"https://github.com/sherlockode.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Installation\n============\n\nMake sure Composer is installed globally, as explained in the\n[installation chapter](https://getcomposer.org/doc/00-intro.md)\nof the Composer documentation.\n\nApplications that use Symfony Flex\n----------------------------------\n\nOpen a command console, enter your project directory and execute:\n\n```console\n$ composer require sherlockode/sonata-sortable-bundle\n```\n\nApplications that don't use Symfony Flex\n----------------------------------------\n\n### Step 1: Download the Bundle\n\nOpen a command console, enter your project directory and execute the\nfollowing command to download the latest stable version of this bundle:\n\n```console\n$ composer require sherlockode/sonata-sortable-bundle\n```\n\n### Step 2: Enable the Bundle\n\nThen, enable the bundle by adding it to the list of registered bundles\nin the `config/bundles.php` file of your project:\n\n```php\n// config/bundles.php\n\nreturn [\n    // ...\n    Sherlockode\\SonataSortableBundle\\SherlockodeSonataSortableBundle::class =\u003e ['all' =\u003e true],\n];\n```\n\nSortable behavior in admin listing\n==================================\n\nPre-requisites\n--------------\n\nYou need to have a working Sonata admin and to have installed and configured `gedmo/doctrine-extensions` (check `stof/doctrine-extensions-bundle` for easy integration).\n\nThe recipe\n----------\n\nFirst of all, add a position property in your entity\n\n```php\n// src/Entity/Category.php\n\nnamespace App\\Entity;\n\nuse Doctrine\\ORM\\Mapping as ORM;\nuse Gedmo\\Mapping\\Annotation as Gedmo;\n\n/**\n * @ORM\\Table(name=\"category\")\n * @ORM\\Entity\n */\nclass Category\n{\n    /**\n     * @var int\n     * \n     * @Gedmo\\SortablePosition\n     * @ORM\\Column(name=\"position\", type=\"integer\")\n     */\n    private $position;\n}\n```\n\nTo change this position with Sonata, we need to add a new route in our admin:\n\n```php\n// src/Admin/CategoryAdmin.php\n\nnamespace App\\Admin;\n\nuse Sonata\\AdminBundle\\Admin\\AbstractAdmin;\nuse Sonata\\AdminBundle\\Route\\RouteCollectionInterface;\n\nclass CategoryAdmin extends AbstractAdmin\n{\n    // ...\n    \n    /**\n     * @param RouteCollectionInterface $collection\n     *\n     * @return void\n     */\n    protected function configureRoutes(RouteCollectionInterface $collection): void\n    {\n        $collection-\u003eadd('move', $this-\u003egetRouterIdParameter().'/move/{direction}');\n    }\n}\n```\n\nUpdate the admin configuration to use our custom controller\n\n```yaml\nservices:\n    admin.category:\n        class: 'App\\Admin\\CategoryAdmin'\n        arguments: [ ~, App\\Entity\\Category, 'Sherlockode\\SonataSortableBundle\\Controller\\SortableController' ]\n        tags:\n            - { name: sonata.admin, manager_type: orm, label: Categories }\n```\n\nThen, add default sort by position in the admin:\n\n```php\n// src/Admin/CategoryAdmin.php\n\nnamespace App\\Admin;\n\nuse Sonata\\AdminBundle\\Admin\\AbstractAdmin;\nuse Sonata\\AdminBundle\\Datagrid\\DatagridInterface;\n\nclass CategoryAdmin extends AbstractAdmin\n{\n    // ...\n    \n    protected function configureDefaultSortValues(array \u0026$sortValues): void\n    {\n        $sortValues[DatagridInterface::PAGE] = 1;\n        $sortValues[DatagridInterface::SORT_ORDER] = 'ASC';\n        $sortValues[DatagridInterface::SORT_BY] = 'position';\n    }\n}\n```\n\nAdd controls to allow the user to change the position of items:\n\n```php\n// src/Admin/CategoryAdmin.php\n\nnamespace App\\Admin;\n\nuse Sonata\\AdminBundle\\Admin\\AbstractAdmin;\nuse Sonata\\AdminBundle\\Datagrid\\ListMapper;\n\nclass CategoryAdmin extends AbstractAdmin\n{\n    // ...\n    \n    /**\n     * @inheritDoc\n     */\n    protected function configureListFields(ListMapper $list): void\n    {\n        $list\n            // your other fields\n            -\u003eadd(ListMapper::NAME_ACTIONS, null, [\n                'actions' =\u003e [\n                    'move' =\u003e [\n                        'template' =\u003e '@SherlockodeSonataSortable/list__action_move.html.twig',\n                    ],\n                ],\n            ])\n        ;\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsherlockode%2Fsonatasortablebundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsherlockode%2Fsonatasortablebundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsherlockode%2Fsonatasortablebundle/lists"}