From 732071a8adf506056c0d1fcc9748c556964faa14 Mon Sep 17 00:00:00 2001 From: Erison Silva Date: Wed, 19 Jan 2022 18:37:29 -0300 Subject: [PATCH] Remove list definition (#724) --- docs/index.rst | 1 - docs/reference/list_field_definition.rst | 182 ----------------------- 2 files changed, 183 deletions(-) delete mode 100644 docs/reference/list_field_definition.rst diff --git a/docs/index.rst b/docs/index.rst index 18477f57..0eb88ac3 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -12,7 +12,6 @@ Reference Guide reference/installation reference/configuration - reference/list_field_definition reference/filter_field_definition reference/form_field_definition reference/form_types_and_transformers diff --git a/docs/reference/list_field_definition.rst b/docs/reference/list_field_definition.rst deleted file mode 100644 index 7aee8639..00000000 --- a/docs/reference/list_field_definition.rst +++ /dev/null @@ -1,182 +0,0 @@ -List field definition -===================== - -These fields are used to display the information inside the list table. - -Example -------- - -.. code-block:: php - - namespace Sonata\NewsBundle\Admin; - - use Sonata\AdminBundle\Admin\AbstractAdmin; - use Sonata\AdminBundle\Form\FormMapper; - use Sonata\AdminBundle\Datagrid\DatagridMapper; - use Sonata\AdminBundle\Datagrid\ListMapper; - use Sonata\AdminBundle\Show\ShowMapper; - - final class PostAdmin extends AbstractAdmin - { - protected function configureListFields(ListMapper $listMapper) - { - $listMapper - ->addIdentifier('title') - ->add('author') - ->add('enabled') - ->add('tags') - ->add('commentsEnabled') - - // add custom action links - ->add('_action', 'actions', [ - 'actions' => [ - 'view' => [], - 'edit' => [], - ] - ]); - } - } - -Types available ---------------- - -The most important option for each field is the ``type``: The available -types include: - -* boolean -* datetime -* decimal -* identifier -* integer -* many_to_one : a link will be added to the related edit action -* string -* text -* date -* time -* array - -If no type is set, the ``Admin`` class will use the type defined in the doctrine -mapping definition. - -List Actions ------------- - -You can set actions for the list items by adding an '_action' field in ``configureListFields``:: - - $listMapper - ->add('_action', 'actions', [ - 'actions' => [ - 'view' => [], - 'edit' => [], - ] - ]); - -Edit and delete actions are enabled in the default configuration. You can add -your own! Default template file is: ``@SonataAdmin/CRUD/list__action_[ACTION_NAME].html.twig`` - -You can specify your own by setting up the 'template' option like so:: - - $listMapper - ->add('_action', 'actions', [ - 'actions' => [ - 'view' => [], - 'edit' => [], - 'delete' => ['template' => '@My/MyController/my_partial.html.twig'], - ] - ]); - -Advance Usage -------------- - -Displaying sub entity properties -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -If you need to display only one field from a sub entity in a dedicated column, -you can use the dot-separated notation (note that this only makes sense when -the prefix path is made of entities, not collections):: - - namespace App\Admin; - - use Sonata\AdminBundle\Admin\AbstractAdmin; - use Sonata\AdminBundle\Datagrid\ListMapper; - - final class UserAdmin extends AbstractAdmin - { - protected function configureListFields(ListMapper $listMapper) - { - $listMapper - ->addIdentifier('id') - ->add('firstName') - ->add('lastName') - ->add('address.street') - ->add('address.ZIPCode') - ->add('address.town') - ; - } - } - -Custom template -^^^^^^^^^^^^^^^ - -If you need a specific layout for a row cell, you can define a custom template:: - - namespace Sonata\MediaBundle\Admin; - - use Sonata\AdminBundle\Admin\AbstractAdmin; - use Sonata\AdminBundle\Datagrid\ListMapper; - - final class MediaAdmin extends AbstractAdmin - { - protected function configureListFields(ListMapper $listMapper) - { - $listMapper - ->addIdentifier('id') - ->add('image', 'string', [ - 'template' => '@SonataMedia/MediaAdmin/list_image.html.twig', - ]) - ->add('custom', 'string', [ - 'template' => '@SonataMedia/MediaAdmin/list_custom.html.twig', - ]) - ; - } - } - -The related template : - -.. code-block:: jinja - - {% extends '@SonataAdmin/CRUD/base_list_field.html.twig' %} - - {% block field%} -
- {{ object.name }}
- {{ object.providername}} : {{ object.width }}x{{ object.height }}
-
- {% endblock %} - -Custom link -^^^^^^^^^^^ - -Assuming you have a custom controller for an admin already defined and an action you want link to on the list -other than ``show`` or ``edit``, you have to first define the desired route (for example ``download``) in the admin class:: - - protected function configureRoutes(RouteCollection $collection) - { - $collection - ->add('download', $this->getRouterIdParameter() . '/download'); - } - -To get the route's full name you can examine the router by running ``bin/console debug:router``. -The following example describes a link to the ``download`` action. The link will display the ``filename`` -property and have the object's ``id`` as url parameter:: - - protected function configureListFields(ListMapper $listMapper) - { - $listMapper - ->addIdentifier('filename', 'url', [ - 'route' => [ - 'name' => 'admin_acme_demo_foo_download', - 'identifier_parameter_name' => 'id' - ] - ]); - }