Browse Source

Trigger deprecation notice when using "associated_tostring" option.

Konstantin.Myakshin 9 years ago
parent
commit
fca0393a2b
2 changed files with 17 additions and 14 deletions
  1. 10 13
      Resources/doc/reference/action_list.rst
  2. 7 1
      Twig/Extension/SonataAdminExtension.php

+ 10 - 13
Resources/doc/reference/action_list.rst

@@ -41,7 +41,7 @@ Customizing the fields displayed on the list page
 -------------------------------------------------
 
 You can customize the columns displayed on the list through the ``configureListFields`` method.
-Here is an example:
+Here is an example from Sonata E-Commerce Product Admin:
 
 .. code-block:: php
 
@@ -71,10 +71,13 @@ Here is an example:
                 'currency' => $this->currencyDetector->getCurrency()->getLabel()
             ))
 
-            // Here we specify which property is used to render the label of each entity in the list
+            // here we specify which method is used to render the label
             ->add('productCategories', null, array(
-                'associated_property' => 'name')
-            )
+                'associated_property' => 'category'
+            ))
+            ->add('productCollections', null, array(
+                'associated_property' => 'collection'
+            ))
 
             // you may also use dotted-notation to access
             // specific properties of a relation to the entity
@@ -104,10 +107,8 @@ Options
 - ``template`` (o): the template used to render the field
 - ``label`` (o): the name used for the column's title
 - ``link_parameters`` (o): add link parameter to the related Admin class when the ``Admin::generateUrl`` is called
-- ``code`` (o): the method name to retrieve the related value (for example,
-  if you have an `array` type field, you would like to show info prettier
-  than `[0] => 'Value'`; useful when simple getter is not enough).
-  Notice: works with string-like types (string, text, html)
+- ``code`` (o): the method name to retrieve the related value
+- ``associated_tostring`` (o): (deprecated, use ``associated_property`` option) the method to retrieve the "string" representation of the collection element.
 - ``associated_property`` (o): property path to retrieve the "string" representation of the collection element, or a closure with the element as argument and return a string.
 - ``identifier`` (o): if set to true a link appears on the value to edit the element
 
@@ -151,10 +152,6 @@ Available types and associated options
 +-----------+----------------+-----------------------------------------------------------------------+
 | string    |                | Renders a simple string.                                              |
 +-----------+----------------+-----------------------------------------------------------------------+
-| text      |                | See 'string'                                                          |
-+-----------+----------------+-----------------------------------------------------------------------+
-| html      |                | Renders string as html                                                |
-+-----------+----------------+-----------------------------------------------------------------------+
 | time      |                | Renders a datetime's time with format ``H:i:s``.                      |
 +-----------+----------------+-----------------------------------------------------------------------+
 | trans     | catalogue      | Translates the value with catalogue ``catalogue`` if defined.         |
@@ -513,7 +510,7 @@ To do:
 Visual configuration
 --------------------
 
-You have the possibility to configure your List View to customize the render without overriding to whole template.
+You have the possibility to configure your List View to customize the render without overring to whole template.
 You can :
 
 - `header_style`: Customize the style of header (width, color, background, align...)

+ 7 - 1
Twig/Extension/SonataAdminExtension.php

@@ -274,7 +274,13 @@ class SonataAdminExtension extends \Twig_Extension implements \Twig_Extension_In
 
         if (null === $propertyPath) {
             // For BC kept associated_tostring option behavior
-            $method = $fieldDescription->getOption('associated_tostring', '__toString');
+            $method = $fieldDescription->getOption('associated_tostring');
+
+            if ($method) {
+                @trigger_error('Option "associated_tostring" is deprecated since version 2.3. Use "associated_property" instead.', E_USER_DEPRECATED);
+            } else {
+                $method = '__toString';
+            }
 
             if (!method_exists($element, $method)) {
                 throw new \RuntimeException(sprintf(