Skip to content

Commit

Permalink
Merge branch '2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
rande committed Mar 27, 2013
2 parents 72a0cea + 1b57a1c commit 4bacd4d
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
9 changes: 8 additions & 1 deletion Admin/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1993,7 +1993,10 @@ public function buildBreadcrumbs($action, MenuItemInterface $menu = null)
$this->trans($this->getLabelTranslatorStrategy()->getLabel(sprintf('%s_%s', $this->getClassnameLabel(), $action), 'breadcrumb', 'link'))
);
}

} elseif ($action != 'list' && $this->hasSubject()) {
$breadcrumbs = $child->getBreadcrumbsArray(
$this->toString($this->getSubject())
);
} elseif ($action != 'list') {
$breadcrumbs = $child->getBreadcrumbsArray(
// $this->trans($this->getLabelTranslatorStrategy()->getLabel(sprintf('%s_%s', $this->getClassnameLabel(), $action), 'breadcrumb', 'link'))
Expand Down Expand Up @@ -2531,6 +2534,10 @@ public function getRouteBuilder()
*/
public function toString($object)
{
if (!is_object($object)) {
return '';
}

if (method_exists($object, '__toString')) {
return (string) $object;
}
Expand Down
3 changes: 2 additions & 1 deletion Resources/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Reference Guide
reference/advance
reference/console
reference/preview_mode
reference/troubleshooting

Overview
--------
Expand Down Expand Up @@ -65,4 +66,4 @@ Overview
:alt: The modal model edition
:width: 700px

The modal model edition
The modal model edition
1 change: 0 additions & 1 deletion Resources/doc/reference/architecture.rst
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,5 @@ Note that you can use both the Bundle:Controller format or a `service name`_ to
specify what controller to load.



.. _`Django Project Website`: http://www.djangoproject.com/
.. _`service name`: http://symfony.com/doc/2.0/cookbook/controller/service.html
30 changes: 30 additions & 0 deletions Resources/doc/reference/troubleshooting.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Troubleshooting
===============

The toString method
-------------------

Sometimes the bundle needs to display your model objects, in order to do it, objects are converted to string by using the `__toString`_ magic method.
Take care to never return anything else than a string in this method.
For example, if your method looks like that :

.. code-block:: php
public function __toString()
{
return $this->getTitle();
}
You can't be sure your object will *always* have a title when the bundle will want to convert it to a string.
So in order to avoid any fatal error, you must return an empty string (or anything you prefer) for when the title is missing, like this :

.. code-block:: php
public function __toString()
{
return $this->getTitle() ?: '';
}
.. _`__toString`: http://www.php.net/manual/en/language.oop5.magic.php#object.tostring
2 changes: 2 additions & 0 deletions Tests/Admin/BaseAdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,5 +218,7 @@ public function testToString()

$s = new FooTest_Admin;
$this->assertEquals('salut', $admin->toString($s));

$this->assertEquals("", $admin->toString(false));
}
}

0 comments on commit 4bacd4d

Please sign in to comment.