[!!!][FEATURE] FormEngine element level refactoring
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / Classes / Form / Resolver / RichTextNodeResolver.php
index 5cea2c7..71402b5 100644 (file)
@@ -14,79 +14,66 @@ namespace TYPO3\CMS\Rtehtmlarea\Form\Resolver;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Backend\Form\NodeFactory;
 use TYPO3\CMS\Backend\Form\NodeResolverInterface;
-use TYPO3\CMS\Rtehtmlarea\Form\Element\RichTextElement;
 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
-use TYPO3\CMS\Backend\Utility\BackendUtility;
-use TYPO3\CMS\Backend\Form\NodeFactory;
+use TYPO3\CMS\Rtehtmlarea\Form\Element\RichTextElement;
 
 /**
  * This resolver will return the RichTextElement render class of ext:rtehtmlarea if RTE is enabled for this field.
  */
-class RichTextNodeResolver implements NodeResolverInterface {
-
-       /**
-        * Global options from NodeFactory
-        *
-        * @var array
-        */
-       protected $data;
-
-       /**
-        * Default constructor receives full data array
-        *
-        * @param NodeFactory $nodeFactory
-        * @param array $data
-        */
-       public function __construct(NodeFactory $nodeFactory, array $data) {
-               $this->data = $data;
-       }
-
-       /**
-        * Returns RichTextElement as class name if RTE widget should be rendered.
-        *
-        * @return string|void New class name or void if this resolver does not change current class name.
-        */
-       public function resolve() {
-               $table = $this->data['tableName'];
-               $fieldName = $this->data['fieldName'];
-               $row = $this->data['databaseRow'];
-               $parameterArray = $this->data['parameterArray'];
-               $backendUser = $this->getBackendUserAuthentication();
+class RichTextNodeResolver implements NodeResolverInterface
+{
+    /**
+     * Global options from NodeFactory
+     *
+     * @var array
+     */
+    protected $data;
 
-               if (// This field is not read only
-                       !$parameterArray['fieldConf']['config']['readOnly']
-                       // If RTE is generally enabled by user settings and RTE object registry can return something valid
-                       && $backendUser->isRTE()
-               ) {
-                       // @todo: Most of this stuff is prepared by data providers within $this->data already
-                       $specialConfiguration = BackendUtility::getSpecConfParts($parameterArray['fieldConf']['defaultExtras']);
-                       // If "richtext" is within defaultExtras
-                       if (isset($specialConfiguration['richtext'])) {
-                               // Operates by reference on $row! 'pid' is changed ...
-                               BackendUtility::fixVersioningPid($table, $row);
-                               list($recordPid, $tsConfigPid) = BackendUtility::getTSCpidCached($table, $row['uid'], $row['pid']);
-                               // If the pid-value is not negative (that is, a pid could NOT be fetched)
-                               if ($tsConfigPid >= 0) {
-                                       // Fetch page ts config and do some magic with it to find out if RTE is disabled on TS level.
-                                       $rteSetup = $backendUser->getTSConfig('RTE', BackendUtility::getPagesTSconfig($recordPid));
-                                       $rteTcaTypeValue = $this->data['recordTypeValue'];
-                                       $rteSetupConfiguration = BackendUtility::RTEsetup($rteSetup['properties'], $table, $fieldName, $rteTcaTypeValue);
-                                       if (!$rteSetupConfiguration['disabled']) {
-                                               // Finally, we're sure the editor should really be rendered ...
-                                               return RichtextElement::class;
-                                       }
-                               }
-                       }
-               }
-               return NULL;
-       }
+    /**
+     * Default constructor receives full data array
+     *
+     * @param NodeFactory $nodeFactory
+     * @param array $data
+     */
+    public function __construct(NodeFactory $nodeFactory, array $data)
+    {
+        $this->data = $data;
+    }
 
-       /**
-        * @return BackendUserAuthentication
-        */
-       protected function getBackendUserAuthentication() {
-               return $GLOBALS['BE_USER'];
-       }
+    /**
+     * Returns RichTextElement as class name if RTE widget should be rendered.
+     *
+     * @return string|void New class name or void if this resolver does not change current class name.
+     */
+    public function resolve()
+    {
+        $parameterArray = $this->data['parameterArray'];
+        $backendUser = $this->getBackendUserAuthentication();
+        if (// This field is not read only
+            !$parameterArray['fieldConf']['config']['readOnly']
+            // If RTE is generally enabled by user settings and RTE object registry can return something valid
+            && $backendUser->isRTE()
+            // If RTE is enabled for field
+            && isset($parameterArray['fieldConf']['config']['enableRichtext'])
+            && (bool)$parameterArray['fieldConf']['config']['enableRichtext'] === true
+            // If RTE config is found (prepared by TcaText data provider)
+            && isset($parameterArray['fieldConf']['config']['richtextConfiguration'])
+            && is_array($parameterArray['fieldConf']['config']['richtextConfiguration'])
+            // If RTE is not disabled on configuration level
+            && !$parameterArray['fieldConf']['config']['richtextConfiguration']['disabled']
+        ) {
+            return RichTextElement::class;
+        }
+        return null;
+    }
 
+    /**
+     * @return BackendUserAuthentication
+     */
+    protected function getBackendUserAuthentication()
+    {
+        return $GLOBALS['BE_USER'];
+    }
 }