[BUGFIX] Replace depcrated PersistenceManager::getBackend() calls
authorKevin Ulrich Moschallski <km@3digit.de>
Sun, 15 Apr 2012 10:02:33 +0000 (12:02 +0200)
committerAlexander Schnitzler <typo3@alexanderschnitzler.de>
Tue, 30 Oct 2012 14:14:39 +0000 (15:14 +0100)
Viewhelper classes uses deprecated calls of persistenceManager for
getting the backend singleton. Replace it with calls on
persistenceManager and dependency injection.

Change-Id: Ie4466d8d171a4015ef63c63c6d8baa3ac204474e
Fixes: #35961
Fixes: #36080
Releases: 6.0
Reviewed-on: http://review.typo3.org/10481
Reviewed-by: Alexander Schnitzler
Tested-by: Alexander Schnitzler
typo3/sysext/fluid/Classes/ViewHelpers/Form/AbstractFormFieldViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/Form/SelectViewHelper.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Form/SelectViewHelperTest.php

index fe0d550..748aba1 100644 (file)
@@ -91,7 +91,8 @@ abstract class AbstractFormFieldViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\
                        $name = $this->arguments['name'];
                }
                if ($this->hasArgument('value') && is_object($this->arguments['value'])) {
-                       if (NULL !== $this->persistenceManager->getIdentifierByObject($this->arguments['value']) && !$this->persistenceManager->getBackend()->isNewObject($this->arguments['value'])) {
+                       // TODO: Use  $this->persistenceManager->isNewObject() once it is implemented
+                       if (NULL !== $this->persistenceManager->getIdentifierByObject($this->arguments['value'])) {
                                $name .= '[__identity]';
                        }
                }
index 0db302e..2b061eb 100644 (file)
@@ -155,8 +155,9 @@ class SelectViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFie
                                                        throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception('Identifying value for object of class "' . get_class($value) . '" was an object.', 1247827428);
                                                }
                                        }
-                               } elseif ($this->persistenceManager->getBackend()->getIdentifierByObject($value) !== NULL) {
-                                       $key = $this->persistenceManager->getBackend()->getIdentifierByObject($value);
+                               // TODO: use $this->persistenceManager->isNewObject() once it is implemented
+                               } elseif ($this->persistenceManager->getIdentifierByObject($value) !== NULL) {
+                                       $key = $this->persistenceManager->getIdentifierByObject($value);
                                } elseif (method_exists($value, '__toString')) {
                                        $key = (string) $value;
                                } else {
@@ -172,9 +173,10 @@ class SelectViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFie
                                                }
                                        }
                                } elseif (method_exists($value, '__toString')) {
-                                       $value = (string) $value;
-                               } elseif ($this->persistenceManager->getBackend()->getIdentifierByObject($value) !== NULL) {
-                                       $value = $this->persistenceManager->getBackend()->getIdentifierByObject($value);
+                                       $value = (string)$value;
+                               // TODO: use $this->persistenceManager->isNewObject() once it is implemented
+                               } elseif ($this->persistenceManager->getIdentifierByObject($value) !== NULL) {
+                                       $value = $this->persistenceManager->getIdentifierByObject($value);
                                }
                        }
                        $options[$key] = $value;
@@ -234,8 +236,9 @@ class SelectViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFie
                        if ($this->hasArgument('optionValueField')) {
                                return \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyPath($valueElement, $this->arguments['optionValueField']);
                        } else {
-                               if ($this->persistenceManager->getBackend()->getIdentifierByObject($valueElement) !== NULL) {
-                                       return $this->persistenceManager->getBackend()->getIdentifierByObject($valueElement);
+                               // TODO: use $this->persistenceManager->isNewObject() once it is implemented
+                               if ($this->persistenceManager->getIdentifierByObject($valueElement) !== NULL) {
+                                       return $this->persistenceManager->getIdentifierByObject($valueElement);
                                } else {
                                        return (string) $valueElement;
                                }
index da3d767..4330ee5 100644 (file)
@@ -199,12 +199,11 @@ class SelectViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\
         * @author Johannes K√ľnsebeck <jk@hdnet.de>
         */
        public function multipleSelectOnDomainObjectsCreatesExpectedOptionsWithoutOptionValueField() {
-               $mockPersistenceManager = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\ManagerInterface');
-               $mockBackend = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Backend', array('getIdentifierByObject'), array(), '', FALSE);
-               $mockBackend->expects($this->any())->method('getIdentifierByObject')->will($this->returnCallback(function ($object) {
+               /** @var $mockPersistenceManager \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface */
+               $mockPersistenceManager = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\PersistenceManagerInterface');
+               $mockPersistenceManager->expects($this->any())->method('getIdentifierByObject')->will($this->returnCallback(function ($object) {
                        return $object->getId();
                }));
-               $mockPersistenceManager->expects($this->any())->method('getBackend')->will($this->returnValue($mockBackend));
                $this->viewHelper->injectPersistenceManager($mockPersistenceManager);
                $this->tagBuilder = new \TYPO3\CMS\Fluid\Core\ViewHelper\TagBuilder();
                $this->viewHelper->expects($this->exactly(3))->method('registerFieldNameForFormTokenGeneration')->with('myName[]');