[BUGFIX] Fallback of FAL properties does not work
authorOliver Hader <oliver@typo3.org>
Tue, 20 Nov 2012 19:59:34 +0000 (20:59 +0100)
committerOliver Hader <oliver.hader@typo3.org>
Tue, 20 Nov 2012 22:09:41 +0000 (23:09 +0100)
The fields title, description and alternative are available
in file references and files. If those in file references
are not defined, those of files shall be used.

Besides that, some fields are not configured yet to be shown
as placeholder element in the backend.

The flaws are fixed by adding accordant TCA configuration and
adding the fallback behaviour for the FileReference object.

Change-Id: I28fa94faeb88958ce6c6cb942ba9a88bd555acdf
Fixes: #43173
Releases: 6.0
Reviewed-on: http://review.typo3.org/16635
Reviewed-by: Oliver Hader
Tested-by: Oliver Hader
t3lib/stddb/tca_sys_file_reference.php
typo3/sysext/core/Classes/Resource/AbstractFile.php
typo3/sysext/core/Classes/Resource/FileReference.php

index 66fef4d..de757d1 100644 (file)
@@ -135,7 +135,7 @@ $TCA['sys_file_reference'] = array(
                                'type' => 'input',
                                'eval' => 'null',
                                'size' => '22',
                                'type' => 'input',
                                'eval' => 'null',
                                'size' => '22',
-                               'placeholder' => '__row|uid_local|title'
+                               'placeholder' => '__row|uid_local|title',
                        )
                ),
                'link' => array(
                        )
                ),
                'link' => array(
@@ -166,7 +166,8 @@ $TCA['sys_file_reference'] = array(
                                'type' => 'text',
                                'eval' => 'null',
                                'cols' => '24',
                                'type' => 'text',
                                'eval' => 'null',
                                'cols' => '24',
-                               'rows' => '5'
+                               'rows' => '5',
+                               'placeholder' => '__row|uid_local|description',
                        )
                ),
                'alternative' => array(
                        )
                ),
                'alternative' => array(
@@ -177,7 +178,7 @@ $TCA['sys_file_reference'] = array(
                                'type' => 'input',
                                'eval' => 'null',
                                'size' => '22',
                                'type' => 'input',
                                'eval' => 'null',
                                'size' => '22',
-                               'placeholder' => '__row|uid_local|alternative'
+                               'placeholder' => '__row|uid_local|alternative',
                        ),
                ),
        ),
                        ),
                ),
        ),
index 70b1e7e..2ae1f73 100644 (file)
@@ -108,7 +108,7 @@ abstract class AbstractFile implements \TYPO3\CMS\Core\Resource\FileInterface {
         * @return boolean
         */
        public function hasProperty($key) {
         * @return boolean
         */
        public function hasProperty($key) {
-               return isset($this->properties[$key]);
+               return array_key_exists($key, $this->properties);
        }
 
        /**
        }
 
        /**
index 38894e4..ac238cd 100644 (file)
@@ -82,6 +82,19 @@ class FileReference implements \TYPO3\CMS\Core\Resource\FileInterface {
        protected $originalFile;
 
        /**
        protected $originalFile;
 
        /**
+        * Defines properties that are merged with the parent object (File) if
+        * the value is not defined (NULL). Thus, FileReference properties act
+        * as overlays for the defined File properties.
+        *
+        * @var array
+        */
+       protected $parentFallbackProperties = array(
+               'title' => 'title',
+               'description' => 'description',
+               'alternative' => 'alternative',
+       );
+
+       /**
         * Constructor for a file in use object. Should normally not be used
         * directly, use the corresponding factory methods instead.
         *
         * Constructor for a file in use object. Should normally not be used
         * directly, use the corresponding factory methods instead.
         *
@@ -119,13 +132,29 @@ class FileReference implements \TYPO3\CMS\Core\Resource\FileInterface {
        }
 
        /**
        }
 
        /**
+        * Gets a property, falling back to values of the parent.
+        *
+        * @param string $key The property to be looked up
+        * @return mixed
+        */
+       public function getProperty($key) {
+               $value = $this->getReferenceProperty($key);
+
+               if ($value === NULL && !empty($this->parentFallbackProperties[$key])) {
+                       $value = $this->originalFile->getProperty($key);
+               }
+
+               return $value;
+       }
+
+       /**
         * Gets a property.
         *
         * @param string $key The property to be looked up
         * @return mixed
         * @throws \InvalidArgumentException
         */
         * Gets a property.
         *
         * @param string $key The property to be looked up
         * @return mixed
         * @throws \InvalidArgumentException
         */
-       public function getProperty($key) {
+       public function getReferenceProperty($key) {
                if (!$this->hasProperty($key)) {
                        throw new \InvalidArgumentException('Property "' . $key . '" was not found.', 1314226805);
                }
                if (!$this->hasProperty($key)) {
                        throw new \InvalidArgumentException('Property "' . $key . '" was not found.', 1314226805);
                }
@@ -133,12 +162,31 @@ class FileReference implements \TYPO3\CMS\Core\Resource\FileInterface {
        }
 
        /**
        }
 
        /**
-        * Gets all properties.
+        * Gets all properties, falling back to values of the parent.
         *
         * @return array
         */
        public function getProperties() {
         *
         * @return array
         */
        public function getProperties() {
-               return \TYPO3\CMS\Core\Utility\GeneralUtility::array_merge_recursive_overrule($this->originalFile->getProperties(), $this->propertiesOfFileReference);
+               $properties = $this->getReferenceProperties();
+               $keys = array_keys($properties);
+
+               foreach ($this->parentFallbackProperties as $localKey => $parentKey) {
+                       if (array_key_exists($localKey, $keys) && $properties[$localKey] === NULL) {
+                               $properties[$localKey] = $this->originalFile->getProperty($parentKey);
+                       }
+               }
+       }
+
+       /**
+        * Gets all properties.
+        *
+        * @return array
+        */
+       public function getReferenceProperties() {
+               return \TYPO3\CMS\Core\Utility\GeneralUtility::array_merge_recursive_overrule(
+                       $this->originalFile->getProperties(),
+                       $this->propertiesOfFileReference
+               );
        }
 
        /**
        }
 
        /**
@@ -158,7 +206,7 @@ class FileReference implements \TYPO3\CMS\Core\Resource\FileInterface {
         * @return string
         */
        public function getTitle() {
         * @return string
         */
        public function getTitle() {
-               return $this->propertiesOfFileReference['title'] ? $this->propertiesOfFileReference['title'] : $this->originalFile->getName();
+               return $this->getProperty('title');
        }
 
        /**
        }
 
        /**
@@ -169,7 +217,7 @@ class FileReference implements \TYPO3\CMS\Core\Resource\FileInterface {
         * @return string
         */
        public function getAlternative() {
         * @return string
         */
        public function getAlternative() {
-               return $this->propertiesOfFileReference['alternative'] ? $this->propertiesOfFileReference['alternative'] : $this->originalFile->getName();
+               return $this->getProperty('alternative');
        }
 
        /**
        }
 
        /**
@@ -180,7 +228,7 @@ class FileReference implements \TYPO3\CMS\Core\Resource\FileInterface {
         * @return string
         */
        public function getDescription() {
         * @return string
         */
        public function getDescription() {
-               return $this->propertiesOfFileReference['description'];
+               return $this->getProperty('description');
        }
 
        /**
        }
 
        /**