[!!!][TASK] Deprecate FormEngine::$renderReadonly 00/35500/9
authorFrank Nägler <typo3@naegler.net>
Mon, 15 Dec 2014 21:56:25 +0000 (22:56 +0100)
committerAlexander Opitz <opitz.alexander@googlemail.com>
Fri, 19 Dec 2014 07:26:39 +0000 (08:26 +0100)
This patch deprecates FormEngine::$renderReadonly
and removes the dependency from all form element classes.

Resolves: #63847
Releases: master
Change-Id: I4c998c53a3d206586ce6c464696c6e6a4b2f99af
Reviewed-on: http://review.typo3.org/35500
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Alexander Opitz <opitz.alexander@googlemail.com>
Tested-by: Alexander Opitz <opitz.alexander@googlemail.com>
typo3/sysext/backend/Classes/Form/Element/AbstractFormElement.php
typo3/sysext/backend/Classes/Form/Element/CheckboxElement.php
typo3/sysext/backend/Classes/Form/Element/GroupElement.php
typo3/sysext/backend/Classes/Form/Element/InputElement.php
typo3/sysext/backend/Classes/Form/Element/RadioElement.php
typo3/sysext/backend/Classes/Form/Element/SelectElement.php
typo3/sysext/backend/Classes/Form/Element/TextElement.php
typo3/sysext/backend/Classes/Form/Element/TreeElement.php
typo3/sysext/backend/Classes/Form/FormEngine.php
typo3/sysext/core/Documentation/Changelog/master/Deprecation-63847-FormEngine-renderReadonly.rst [new file with mode: 0644]

index 12c5d97..ca5576b 100644 (file)
@@ -36,6 +36,11 @@ abstract class AbstractFormElement {
        protected $formEngine;
 
        /**
+        * @var bool If TRUE, the element will not be editable
+        */
+       protected $renderReadonly = FALSE;
+
+       /**
         * Constructor function, setting the FormEngine
         *
         * @param FormEngine $formEngine
@@ -45,6 +50,24 @@ abstract class AbstractFormElement {
        }
 
        /**
+        * @return bool TRUE if field is set to read only
+        */
+       public function isRenderReadonly() {
+               return $this->renderReadonly;
+       }
+
+       /**
+        * Set render read only state
+        *
+        * @param bool $renderReadonly
+        * @return AbstractFormElement
+        */
+       public function setRenderReadonly($renderReadonly) {
+               $this->renderReadonly = (bool)$renderReadonly;
+               return $this;
+       }
+
+       /**
         * Handler for Flex Forms
         *
         * @param string $table The table name of the record
index 47b2df5..c8e89f1 100644 (file)
@@ -32,7 +32,7 @@ class CheckboxElement extends AbstractFormElement {
                $config = $additionalInformation['fieldConf']['config'];
                $item = '';
                $disabled = FALSE;
-               if ($this->formEngine->renderReadonly || $config['readOnly']) {
+               if ($this->isRenderReadonly() || $config['readOnly']) {
                        $disabled = TRUE;
                }
                // Traversing the array of items
index 24c1245..1b71abf 100644 (file)
@@ -50,7 +50,7 @@ class GroupElement extends AbstractFormElement {
                $disallowed = trim($config['disallowed']);
                $item = '';
                $disabled = '';
-               if ($this->formEngine->renderReadonly || $config['readOnly']) {
+               if ($this->isRenderReadonly() || $config['readOnly']) {
                        $disabled = ' disabled="disabled"';
                }
                $item .= '<input type="hidden" name="' . $additionalInformation['itemFormElName'] . '_mul" value="' . ($config['multiple'] ? 1 : 0) . '"' . $disabled . ' />';
index 37dbb93..ef8e5c1 100644 (file)
@@ -14,8 +14,8 @@ namespace TYPO3\CMS\Backend\Form\Element;
  * The TYPO3 project - inspiring people to share!
  */
 
-use TYPO3\CMS\Backend\Utility\IconUtility;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Backend\Utility\IconUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;
 
@@ -98,7 +98,7 @@ class InputElement extends AbstractFormElement {
                        $cssClasses[] = 'tceforms-textfield tceforms-colorfield';
                }
                $inputId = str_replace('.', '', $inputId);
-               if ($this->formEngine->renderReadonly || $config['readOnly']) {
+               if ($this->isRenderReadonly() || $config['readOnly']) {
                        $itemFormElValue = $additionalInformation['itemFormElValue'];
                        if (in_array('date', $evalList)) {
                                $config['format'] = 'date';
index 4f25cf8..c280868 100644 (file)
@@ -32,7 +32,7 @@ class RadioElement extends AbstractFormElement {
                $config = $additionalInformation['fieldConf']['config'];
                $item = '';
                $disabled = '';
-               if ($this->formEngine->renderReadonly || $config['readOnly']) {
+               if ($this->isRenderReadonly() || $config['readOnly']) {
                        $disabled = ' disabled';
                }
 
index 727a3d7..ee5e93c 100644 (file)
@@ -69,7 +69,7 @@ class SelectElement extends AbstractFormElement {
                // Field configuration from TCA:
                $config = $additionalInformation['fieldConf']['config'];
                $disabled = '';
-               if ($this->formEngine->renderReadonly || $config['readOnly']) {
+               if ($this->isRenderReadonly() || $config['readOnly']) {
                        $disabled = ' disabled="disabled"';
                }
                // "Extra" configuration; Returns configuration for the field based on settings found in the "types" fieldlist.
@@ -128,7 +128,7 @@ class SelectElement extends AbstractFormElement {
                $languageService = $this->getLanguageService();
                $item = '';
                $disabled = '';
-               if ($this->formEngine->renderReadonly || $config['readOnly']) {
+               if ($this->isRenderReadonly() || $config['readOnly']) {
                        $disabled = ' disabled="disabled"';
                }
                // Setting this hidden field (as a flag that JavaScript can read out)
@@ -397,7 +397,7 @@ class SelectElement extends AbstractFormElement {
                $selectedStyle = '';
                $item = '';
                $disabled = '';
-               if ($this->formEngine->renderReadonly || $config['readOnly']) {
+               if ($this->isRenderReadonly() || $config['readOnly']) {
                        $disabled = ' disabled="disabled"';
                        $onlySelectedIconShown = 1;
                }
@@ -556,7 +556,7 @@ class SelectElement extends AbstractFormElement {
                $itemArray = array_flip($this->formEngine->extractValuesOnlyFromValueLabelList($PA['itemFormElValue']));
                $item = '';
                $disabled = '';
-               if ($this->formEngine->renderReadonly || $config['readOnly']) {
+               if ($this->isRenderReadonly() || $config['readOnly']) {
                        $disabled = ' disabled="disabled"';
                }
                // Traverse the Array of selector box items:
@@ -699,7 +699,7 @@ class SelectElement extends AbstractFormElement {
                $itemArray = array_flip($this->formEngine->extractValuesOnlyFromValueLabelList($PA['itemFormElValue']));
                $item = '';
                $disabled = '';
-               if ($this->formEngine->renderReadonly || $config['readOnly']) {
+               if ($this->isRenderReadonly() || $config['readOnly']) {
                        $disabled = ' disabled="disabled"';
                }
                // Traverse the Array of selector box items:
index b2a8e6e..52ef003 100644 (file)
@@ -59,7 +59,7 @@ class TextElement extends AbstractFormElement {
 
                // must be called after the cols and rows calculation, so the parameters are applied
                // to read-only fields as well.
-               if ($this->formEngine->renderReadonly || $config['readOnly']) {
+               if ($this->isRenderReadonly() || $config['readOnly']) {
                        $config['cols'] = $cols;
                        $config['rows'] = $rows;
                        return $this->formEngine->getSingleField_typeNone_render($config, $additionalInformation['itemFormElValue']);
index 516956b..7e9fcff 100644 (file)
@@ -175,7 +175,7 @@ class TreeElement extends AbstractFormElement {
                                tcaExclusiveKeys: "' . ($PA['fieldConf']['config']['exclusiveKeys'] ? $PA['fieldConf']['config']['exclusiveKeys'] : '') . '",
                                ucId: "' . md5(($table . '|' . $field)) . '",
                                selModel: TYPO3.Components.Tree.EmptySelectionModel,
-                               disabled: ' . ($PA['fieldConf']['config']['readOnly'] || $this->formEngine->renderReadonly ? 'true' : 'false') . '
+                               disabled: ' . ($PA['fieldConf']['config']['readOnly'] || $this->isRenderReadonly() ? 'true' : 'false') . '
                        });' . LF .
                                ($autoSizeMax
                                        ? 'tree' . $id . '.bodyStyle = "max-height: ' . $autoSizeMax . 'px;min-height: ' . $height . 'px;";'
index 2f6f96c..b4fd7f2 100644 (file)
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Backend\Form;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Backend\Form\Element\AbstractFormElement;
 use TYPO3\CMS\Backend\Form\Element\InlineElement;
 use TYPO3\CMS\Backend\Template\DocumentTemplate;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
@@ -233,7 +234,7 @@ class FormEngine {
         *
         * @var bool
         */
-       public $renderReadonly = FALSE;
+       protected $renderReadonly = FALSE;
 
        /**
         * Form field width compensation: Factor of "size=12" to "style="width: 12*9.58px"
@@ -639,6 +640,19 @@ class FormEngine {
        protected $suggest;
 
        /**
+        * protected properties which were public
+        * use old property name as key and new property name as value
+        * e.g. 'foo_BarName' => 'fooBarName'
+        *
+        * For each property a getter and setter method must be implemented!
+        * @see __set() and __get()
+        * @var array
+        */
+       protected $protectedProperties = array(
+               'renderReadonly' => 'renderReadonly'
+       );
+
+       /**
         * Constructor function, setting internal variables, loading the styles used.
         *
         */
@@ -683,6 +697,59 @@ class FormEngine {
        }
 
        /**
+        * Fallback method to protect public properties
+        * This is only a temporary solution and will be removed in TYPO3 CMS 8
+        *
+        * @param string $name name of the property
+        * @param mixed $value value of the property
+        * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
+        */
+       public function __set($name, $value) {
+               if (array_key_exists($name, $this->protectedProperties)) {
+                       $method = 'set' . ucfirst($this->protectedProperties[$name]);
+                       if (is_callable(array($this, $method))) {
+                               GeneralUtility::deprecationLog('direct access to "FormEngine::$' . $name . '" is deprecated, use "FormEngine::' . $method . '()" instead.');
+                               call_user_func_array(array($this, $method), array($value));
+                       }
+               }
+       }
+
+       /**
+        * Fallback method to protect public properties
+        * This is only a temporary solution and will be removed in TYPO3 CMS 8
+        *
+        * @param string $name name of the property
+        * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
+        */
+       public function __get($name) {
+               if (array_key_exists($name, $this->protectedProperties)) {
+                       $method = 'get' . ucfirst($this->protectedProperties[$name]);
+                       if (is_callable(array($this, $method))) {
+                               GeneralUtility::deprecationLog('direct access to "FormEngine::$' . $name . '" is deprecated, use "FormEngine::' . $method . '()" instead.');
+                               call_user_func(array($this, $method));
+                       }
+               }
+       }
+
+       /**
+        * Set render read only flag
+        *
+        * @param bool $value
+        */
+       public function setRenderReadonly($value) {
+               $this->renderReadonly = (bool)$value;
+       }
+
+       /**
+        * Get render readonly flag
+        *
+        * @return bool
+        */
+       public function getRenderReadonly() {
+               return $this->renderReadonly;
+       }
+
+       /**
         * Initialize various internal variables.
         *
         * @return void
@@ -1285,8 +1352,11 @@ class FormEngine {
                        if (!isset($typeClassNameMapping[$type])) {
                                $type = 'unknown';
                        }
-                       $item = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Form\\Element\\' . $typeClassNameMapping[$type], $this)
-                               ->render($table, $field, $row, $PA);
+                       $formElement = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Form\\Element\\' . $typeClassNameMapping[$type], $this);
+                       if ($formElement instanceof AbstractFormElement) {
+                               $formElement->setRenderReadonly($this->getRenderReadonly());
+                       }
+                       $item = $formElement->render($table, $field, $row, $PA);
                }
                return $item;
        }
@@ -1383,6 +1453,7 @@ class FormEngine {
        public function getSingleField_typeText($table, $field, $row, &$PA) {
                GeneralUtility::logDeprecatedFunction();
                return $item = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Form\Element\TextElement::class, $this)
+                       ->setRenderReadonly($this->getRenderReadonly())
                        ->render($table, $field, $row, $PA);
        }
 
@@ -1400,6 +1471,7 @@ class FormEngine {
        public function getSingleField_typeCheck($table, $field, $row, &$PA) {
                GeneralUtility::logDeprecatedFunction();
                return $item = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Form\Element\CheckboxElement::class, $this)
+                       ->setRenderReadonly($this->getRenderReadonly())
                        ->render($table, $field, $row, $PA);
        }
 
@@ -1417,6 +1489,7 @@ class FormEngine {
        public function getSingleField_typeRadio($table, $field, $row, &$PA) {
                GeneralUtility::logDeprecatedFunction();
                return $item = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Form\Element\RadioElement::class, $this)
+                       ->setRenderReadonly($this->getRenderReadonly())
                        ->render($table, $field, $row, $PA);
        }
 
@@ -1435,6 +1508,7 @@ class FormEngine {
        public function getSingleField_typeSelect($table, $field, $row, &$PA) {
                GeneralUtility::logDeprecatedFunction();
                return $item = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Form\Element\SelectElement::class, $this)
+                       ->setRenderReadonly($this->getRenderReadonly())
                        ->render($table, $field, $row, $PA);
        }
 
@@ -1452,6 +1526,7 @@ class FormEngine {
        public function getSingleField_typeGroup($table, $field, $row, &$PA) {
                GeneralUtility::logDeprecatedFunction();
                return $item = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Form\Element\GroupElement::class, $this)
+                       ->setRenderReadonly($this->getRenderReadonly())
                        ->render($table, $field, $row, $PA);
        }
 
@@ -1469,6 +1544,7 @@ class FormEngine {
        public function getSingleField_typeNone($table, $field, $row, &$PA) {
                GeneralUtility::logDeprecatedFunction();
                return $item = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Form\Element\NoneElement::class, $this)
+                       ->setRenderReadonly($this->getRenderReadonly())
                        ->render($table, $field, $row, $PA);
        }
 
@@ -1521,6 +1597,7 @@ class FormEngine {
        public function getSingleField_typeFlex($table, $field, $row, &$PA) {
                GeneralUtility::logDeprecatedFunction();
                return $item = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Form\Element\FlexElement::class, $this)
+                       ->setRenderReadonly($this->getRenderReadonly())
                        ->render($table, $field, $row, $PA);
        }
 
@@ -1591,6 +1668,7 @@ class FormEngine {
        public function getSingleField_typeUnknown($table, $field, $row, &$PA) {
                GeneralUtility::logDeprecatedFunction();
                return $item = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Form\Element\UnknownElement::class, $this)
+                       ->setRenderReadonly($this->getRenderReadonly())
                        ->render($table, $field, $row, $PA);
        }
 
@@ -1607,6 +1685,7 @@ class FormEngine {
        public function getSingleField_typeUser($table, $field, $row, &$PA) {
                GeneralUtility::logDeprecatedFunction();
                return $item = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Form\Element\UserElement::class, $this)
+                       ->setRenderReadonly($this->getRenderReadonly())
                        ->render($table, $field, $row, $PA);
        }
 
@@ -2238,7 +2317,7 @@ class FormEngine {
        public function dbFileIcons($fName, $mode, $allowed, $itemArray, $selector = '', $params = array(), $onFocus = '', $table = '', $field = '', $uid = '', $config = array()) {
                $languageService = $this->getLanguageService();
                $disabled = '';
-               if ($this->renderReadonly || $params['readOnly']) {
+               if ($this->getRenderReadonly() || $params['readOnly']) {
                        $disabled = ' disabled="disabled"';
                }
                // Sets a flag which means some JavaScript is included on the page to support this element.
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-63847-FormEngine-renderReadonly.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-63847-FormEngine-renderReadonly.rst
new file mode 100644 (file)
index 0000000..a1f56d0
--- /dev/null
@@ -0,0 +1,27 @@
+===========================================================
+Deprecation: #63847 - Deprecate FormEngine::$renderReadonly
+===========================================================
+
+Description
+===========
+
+The direct access to :php:`FormEngine::$renderReadonly` has been deprecated.
+
+
+Impact
+======
+
+Using :php:`FormEngine::$renderReadonly` of FormEngine class will trigger a deprecation log message.
+
+
+Affected installations
+======================
+
+Instances which use custom form elements, which make use of :php:`FormEngine::$renderReadonly`.
+
+
+Migration
+=========
+
+Use :php:`AbstractFormElement::setRenderReadonly(TRUE)` to force all elements to be rendered as read only fields.
+