TYPO3 CMS  TYPO3_8-7
SuggestWizard.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
19 
27 {
28 
32  protected $view;
33 
40  public function __construct(StandaloneView $view = null)
41  {
43  $this->view = $view ?: $this->getFluidTemplateObject('SuggestWizard.html');
44  }
45 
53  public function renderSuggestSelector(array $data)
54  {
55  $fieldName = $data['fieldName'];
56  $dataStructureIdentifier = '';
57  $flexFormSheetName = '';
58  $flexFormFieldName = '';
59  $flexFormContainerName = '';
60  $flexFormContainerFieldName = '';
61  if ($data['processedTca']['columns'][$fieldName]['config']['type'] === 'flex') {
62  $flexFormConfig = $data['processedTca']['columns'][$fieldName];
63  $dataStructureIdentifier = $flexFormConfig['config']['dataStructureIdentifier'];
64  if (!isset($flexFormConfig['config']['dataStructureIdentifier'])) {
65  throw new \RuntimeException(
66  'A data structure identifier must be set in [\'config\'] part of a flex form.'
67  . ' This is usually added by TcaFlexPrepare data processor',
68  1478604742
69  );
70  }
71  if (isset($data['flexFormSheetName'])) {
72  $flexFormSheetName = $data['flexFormSheetName'];
73  }
74  if (isset($data['flexFormFieldName'])) {
75  $flexFormFieldName = $data['flexFormFieldName'];
76  }
77  if (isset($data['flexFormContainerName'])) {
78  $flexFormContainerName = $data['flexFormContainerName'];
79  }
80  if (isset($data['flexFormContainerFieldName'])) {
81  $flexFormContainerFieldName = $data['flexFormContainerFieldName'];
82  }
83  }
84 
85  // Get minimumCharacters from TCA
86  $minChars = 0;
87  $fieldTca = $data['parameterArray']['fieldConf'];
88  if (isset($fieldTca['config']['wizards']['suggest']['default']['minimumCharacters'])) {
89  $minChars = (int)$fieldTca['config']['wizards']['suggest']['default']['minimumCharacters'];
90  }
91  // Overwrite it with minimumCharacters from TSConfig if given
92  $fieldTsConfig = $data['parameterArray']['fieldTSConfig'];
93  if (isset($fieldTsConfig['suggest.']['default.']['minimumCharacters'])) {
94  $minChars = (int)$fieldTsConfig['suggest.']['default.']['minimumCharacters'];
95  }
96  $minChars = $minChars > 0 ? $minChars : 2;
97 
98  $this->view->assignMultiple([
99  'placeholder' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.findRecord',
100  'fieldName' => $data['fieldName'],
101  'tableName' => $data['tableName'],
102  'field' => $data['parameterArray']['itemFormElName'],
103  'uid' => $data['databaseRow']['uid'],
104  'pid' => (int)$data['effectivePid'],
105  'dataStructureIdentifier' => $dataStructureIdentifier,
106  'flexFormSheetName' => $flexFormSheetName,
107  'flexFormFieldName' => $flexFormFieldName,
108  'flexFormContainerName' => $flexFormContainerName,
109  'flexFormContainerFieldName' => $flexFormContainerFieldName,
110  'fieldtype' => $fieldTca['config']['type'],
111  'minchars' => (int)$minChars,
112  ]);
113 
114  return $this->view->render();
115  }
116 
124  protected function getFluidTemplateObject(string $filename = null): StandaloneView
125  {
127  $view = GeneralUtility::makeInstance(StandaloneView::class);
128  $view->setLayoutRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Layouts')]);
129  $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Partials')]);
130  $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates')]);
131 
132  if ($filename === null) {
133  $filename = 'SuggestWizard.html';
134  }
135 
136  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/Wizards/' . $filename));
137 
138  $view->getRequest()->setControllerExtensionName('Backend');
139  return $view;
140  }
141 }
static getFileAbsFileName($filename, $_=null, $_2=null)
__construct(StandaloneView $view=null)
static makeInstance($className,... $constructorArguments)