[TASK] Fluidification of SuggestWizard 61/50361/6
authorMarc Willmann <mw@f7.de>
Tue, 25 Oct 2016 10:11:03 +0000 (12:11 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Wed, 26 Oct 2016 17:52:20 +0000 (19:52 +0200)
Resolves: #78420
Releases: master
Change-Id: I2d3ea1c0f3bda176f68da62f5d379e4af0647494
Reviewed-on: https://review.typo3.org/50361
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/backend/Classes/Form/Wizard/SuggestWizard.php
typo3/sysext/backend/Resources/Private/Templates/Wizards/SuggestWizard.html [new file with mode: 0644]

index a5096a6..631c973 100644 (file)
@@ -18,12 +18,11 @@ use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\ServerRequestInterface;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Database\ConnectionPool;
-use TYPO3\CMS\Core\Imaging\Icon;
-use TYPO3\CMS\Core\Imaging\IconFactory;
 use TYPO3\CMS\Core\Utility\ArrayUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;
 use TYPO3\CMS\Core\Utility\StringUtility;
+use TYPO3\CMS\Fluid\View\StandaloneView;
 use TYPO3\CMS\Lang\LanguageService;
 
 /**
@@ -31,6 +30,20 @@ use TYPO3\CMS\Lang\LanguageService;
  */
 class SuggestWizard
 {
+
+    /**
+     * @var StandaloneView
+     */
+    protected $view;
+
+    /**
+     * Construct
+     */
+    public function __construct()
+    {
+        $this->view = $this->getFluidTemplateObject('SuggestWizard.html');
+    }
+
     /**
      * Renders an ajax-enabled text field. Also adds required JS
      *
@@ -43,9 +56,6 @@ class SuggestWizard
      */
     public function renderSuggestSelector($fieldname, $table, $field, array $row, array $config)
     {
-        /** @var $iconFactory IconFactory */
-        $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
-        $languageService = $this->getLanguageService();
         $isFlexFormField = $GLOBALS['TCA'][$table]['columns'][$field]['config']['type'] === 'flex';
         if ($isFlexFormField) {
             $fieldPattern = 'data[' . $table . '][' . $row['uid'] . '][';
@@ -79,25 +89,20 @@ class SuggestWizard
             $jsRow = serialize($row);
         }
 
-        $selector = '
-               <div class="autocomplete t3-form-suggest-container">
-                       <div class="input-group">
-                               <span class="input-group-addon">' . $iconFactory->getIcon('actions-search', Icon::SIZE_SMALL)->render() . '</span>
-                               <input type="search" class="t3-form-suggest form-control"
-                                       placeholder="' . htmlspecialchars($languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.findRecord')) . '"
-                                       data-fieldname="' . htmlspecialchars($fieldname) . '"
-                                       data-table="' . htmlspecialchars($table) . '"
-                                       data-field="' . htmlspecialchars($field) . '"
-                                       data-uid="' . htmlspecialchars($row['uid']) . '"
-                                       data-pid="' . (int)$row['pid'] . '"
-                                       data-fieldtype="' . htmlspecialchars($type) . '"
-                                       data-minchars="' . (int)$minChars . '"
-                                       data-recorddata="' . htmlspecialchars($jsRow) . '"
-                               />
-                       </div>
-               </div>';
-
-        return $selector;
+        $this->view->assignMultiple([
+                'placeholder' => 'LLL:EXT:lang/locallang_core.xlf:labels.findRecord',
+                'fieldname' => $fieldname,
+                'table' => $table,
+                'field' => $field,
+                'uid' => $row['uid'],
+                'pid' => (int)$row['pid'],
+                'fieldtype' => $type,
+                'minchars' => (int)$minChars,
+                'recorddata' => $jsRow
+            ]
+        );
+
+        return $this->view->render();
     }
 
     /**
@@ -510,4 +515,29 @@ class SuggestWizard
     {
         return $GLOBALS['LANG'];
     }
+
+    /**
+     * Returns a new standalone view, shorthand function
+     *
+     * @param string $filename Which templateFile should be used.
+     *
+     * @return StandaloneView
+     */
+    protected function getFluidTemplateObject(string $filename = null):StandaloneView
+    {
+        /** @var StandaloneView $view */
+        $view = GeneralUtility::makeInstance(StandaloneView::class);
+        $view->setLayoutRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Layouts')]);
+        $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Partials')]);
+        $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates')]);
+
+        if ($filename === null) {
+            $filename = 'SuggestWizard.html';
+        }
+
+        $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/Wizards/' . $filename));
+
+        $view->getRequest()->setControllerExtensionName('Backend');
+        return $view;
+    }
 }
diff --git a/typo3/sysext/backend/Resources/Private/Templates/Wizards/SuggestWizard.html b/typo3/sysext/backend/Resources/Private/Templates/Wizards/SuggestWizard.html
new file mode 100644 (file)
index 0000000..4bfb8d4
--- /dev/null
@@ -0,0 +1,21 @@
+{namespace core = TYPO3\CMS\Core\ViewHelpers}
+
+<div class="autocomplete t3-form-suggest-container">
+    <div class="input-group">
+        <span class="input-group-addon">
+            <core:icon identifier="actions-search" size="small" />
+        </span>
+        <input type="search" class="t3-form-suggest form-control"
+               placeholder="{f:translate(key: placeholder, htmlEscape: 'TRUE')}"
+               data-fieldname="{fieldname -> f:format.htmlspecialchars()}"
+               data-table="{table -> f:format.htmlspecialchars()}"
+               data-field="{field -> f:format.htmlspecialchars()}"
+               data-uid="{uid}"
+               data-pid="{pid}"
+               data-fieldtype="{fieldtype -> f:format.htmlspecialchars()}"
+               data-minchars="{minchars}"
+               data-recorddata="{recorddata -> f:format.htmlspecialchars()}"
+        />
+    </div>
+</div>
+