1 | <?php |
||
2 | |||
3 | namespace ApacheSolrForTypo3\Solr\Controller\Backend; |
||
4 | |||
5 | /*************************************************************** |
||
6 | * Copyright notice |
||
7 | * |
||
8 | * (c) 2012-2015 Ingo Renner <[email protected]> |
||
9 | * All rights reserved |
||
10 | * |
||
11 | * This script is part of the TYPO3 project. The TYPO3 project is |
||
12 | * free software; you can redistribute it and/or modify |
||
13 | * it under the terms of the GNU General Public License as published by |
||
14 | * the Free Software Foundation; either version 3 of the License, or |
||
15 | * (at your option) any later version. |
||
16 | * |
||
17 | * The GNU General Public License can be found at |
||
18 | * http://www.gnu.org/copyleft/gpl.html. |
||
19 | * |
||
20 | * This script is distributed in the hope that it will be useful, |
||
21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
23 | * GNU General Public License for more details. |
||
24 | * |
||
25 | * This copyright notice MUST APPEAR in all copies of the script! |
||
26 | ***************************************************************/ |
||
27 | |||
28 | use TYPO3\CMS\Backend\Utility\BackendUtility; |
||
29 | use TYPO3\CMS\Core\Utility\GeneralUtility; |
||
30 | use TYPO3\CMS\Extbase\Reflection\ObjectAccess; |
||
31 | use TYPO3\CMS\Fluid\View\StandaloneView; |
||
32 | use TYPO3\CMS\Core\Localization\LanguageService; |
||
33 | use TYPO3\CMS\Backend\View\PageLayoutView; |
||
34 | |||
35 | /** |
||
36 | * Summary to display flexform settings in the page layout backend module. |
||
37 | * |
||
38 | * @author Ingo Renner <[email protected]> |
||
39 | * @author Timo Hund <[email protected]> |
||
40 | */ |
||
41 | class PageModuleSummary |
||
42 | { |
||
43 | /** |
||
44 | * PageLayoutView |
||
45 | * |
||
46 | * @var PageLayoutView |
||
47 | */ |
||
48 | protected $pageLayoutView; |
||
49 | |||
50 | /** |
||
51 | * @var array |
||
52 | */ |
||
53 | protected $pluginContentElement = []; |
||
54 | |||
55 | /** |
||
56 | * @var array |
||
57 | */ |
||
58 | protected $flexformData = []; |
||
59 | |||
60 | /** |
||
61 | * @var array |
||
62 | 1 | */ |
|
63 | protected $settings = []; |
||
64 | 1 | ||
65 | /** |
||
66 | 1 | * Returns information about a plugin's flexform configuration |
|
67 | 1 | * |
|
68 | 1 | * @param array $parameters Parameters to the hook |
|
69 | 1 | * @return string Plugin configuration information |
|
70 | 1 | */ |
|
71 | 1 | public function getSummary(array $parameters) |
|
72 | 1 | { |
|
73 | 1 | $this->initialize($parameters['row'], $parameters['pObj']); |
|
74 | 1 | ||
75 | $this->addTargetPage(); |
||
76 | $this->addSettingFromFlexForm('Filter', 'search.query.filter'); |
||
77 | $this->addSettingFromFlexForm('Sorting', 'search.query.sortBy'); |
||
78 | $this->addSettingFromFlexForm('Results per Page', 'search.results.resultsPerPage'); |
||
79 | $this->addSettingFromFlexForm('Boost Function', 'search.query.boostFunction'); |
||
80 | 1 | $this->addSettingFromFlexForm('Boost Query', 'search.query.boostQuery'); |
|
81 | $this->addSettingFromFlexForm('Tie Breaker', 'search.query.tieParameter'); |
||
82 | $this->addSettingFromFlexForm('Template', 'view.templateFiles.results'); |
||
83 | 1 | return $this->render(); |
|
84 | 1 | } |
|
85 | 1 | ||
86 | 1 | /** |
|
87 | * @param array $contentElement |
||
88 | * @param PageLayoutView $pObj |
||
89 | */ |
||
90 | protected function initialize(array $contentElement, PageLayoutView $pObj) |
||
91 | 1 | { |
|
92 | $this->pageLayoutView = $pObj; |
||
93 | 1 | ||
94 | 1 | /** @var $service \TYPO3\CMS\Core\Service\FlexFormService::class */ |
|
95 | 1 | $service = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Service\FlexFormService::class); |
|
96 | 1 | $this->flexformData = $service->convertFlexFormContentToArray($contentElement['pi_flexform']); |
|
97 | $this->pluginContentElement = $contentElement; |
||
98 | 1 | } |
|
99 | |||
100 | /** |
||
101 | * Adds the target page to the settings. |
||
102 | */ |
||
103 | protected function addTargetPage() |
||
104 | 1 | { |
|
105 | $targetPageId = $this->getFieldFromFlexform('search.targetPage'); |
||
106 | 1 | if (!empty($targetPageId)) { |
|
107 | $page = BackendUtility::getRecord('pages', $targetPageId, 'title'); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
108 | 1 | $this->settings['Target Page'] = '[' . (int)$targetPageId . '] ' . $page['title']; |
|
109 | 1 | } |
|
110 | } |
||
111 | 1 | ||
112 | 1 | /** |
|
113 | * @param string $settingName |
||
114 | * @param string $flexFormField |
||
115 | */ |
||
116 | protected function addSettingFromFlexForm($settingName, $flexFormField) |
||
117 | { |
||
118 | $value = $this->getFieldFromFlexform($flexFormField); |
||
119 | 1 | ||
120 | if (is_array($value)) { |
||
0 ignored issues
–
show
|
|||
121 | 1 | $value = $this->addSettingFromFlexFormArray($settingName, $value); |
|
122 | 1 | } |
|
123 | $this->addSettingIfNotEmpty($settingName, (string)$value); |
||
124 | } |
||
125 | 1 | ||
126 | /** |
||
127 | 1 | * @param string $settingName |
|
128 | 1 | * @param array $values |
|
129 | 1 | * @return bool |
|
130 | 1 | */ |
|
131 | protected function addSettingFromFlexFormArray($settingName, $values) |
||
132 | 1 | { |
|
133 | foreach ($values as $item) { |
||
134 | if (!isset($item['field'])) { |
||
135 | continue; |
||
136 | } |
||
137 | $field = $item['field']; |
||
138 | 1 | ||
139 | $label = $settingName . ' '; |
||
140 | 1 | $label .= isset($field['field']) ? $field['field'] : ''; |
|
141 | 1 | $fieldValue = isset($field['value']) ? $field['value'] : ''; |
|
142 | $this->addSettingIfNotEmpty($label, (string)$fieldValue); |
||
143 | 1 | } |
|
144 | } |
||
145 | |||
146 | /** |
||
147 | * @param string $settingName |
||
148 | * @param string $value |
||
149 | */ |
||
150 | protected function addSettingIfNotEmpty($settingName, $value) |
||
151 | { |
||
152 | 1 | if (!empty($value)) { |
|
153 | $this->settings[$settingName] = $value; |
||
154 | 1 | } |
|
155 | } |
||
156 | |||
157 | /** |
||
158 | * Gets a field's value from flexform configuration, will check if |
||
159 | * flexform configuration is available. |
||
160 | 1 | * |
|
161 | * @param string $path name of the field |
||
162 | * @return string if nothing found, value if found |
||
163 | 1 | */ |
|
164 | 1 | protected function getFieldFromFlexform($path) |
|
165 | 1 | { |
|
166 | return ObjectAccess::getPropertyPath($this->flexformData, $path); |
||
0 ignored issues
–
show
|
|||
167 | 1 | } |
|
168 | 1 | ||
169 | 1 | /** |
|
170 | * @return string |
||
171 | */ |
||
172 | 1 | protected function render() |
|
173 | { |
||
174 | /** @var $standaloneView StandaloneView */ |
||
175 | $standaloneView = GeneralUtility::makeInstance(StandaloneView::class); |
||
176 | $standaloneView->setTemplatePathAndFilename( |
||
177 | GeneralUtility::getFileAbsFileName('EXT:solr/Resources/Private/Templates/Backend/PageModule/Summary.html') |
||
178 | ); |
||
179 | |||
180 | $standaloneView->assignMultiple([ |
||
181 | 'pluginLabel' => $this->getPluginLabel(), |
||
182 | 'hidden' => $this->pluginContentElement['hidden'], |
||
183 | 'settings' => $this->settings, |
||
184 | ]); |
||
185 | return $standaloneView->render(); |
||
186 | } |
||
187 | |||
188 | /** |
||
189 | * Returns the plugin label |
||
190 | * |
||
191 | * @return string |
||
192 | */ |
||
193 | protected function getPluginLabel() |
||
194 | { |
||
195 | $label = BackendUtility::getLabelFromItemListMerged($this->pluginContentElement['pid'], 'tt_content', 'list_type', $this->pluginContentElement['list_type']); |
||
196 | if (!empty($label)) { |
||
197 | $label = $this->getLanguageService()->sL($label); |
||
198 | } else { |
||
199 | $label = sprintf($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.noMatchingValue'), $this->pluginContentElement['list_type']); |
||
200 | } |
||
201 | |||
202 | return $this->pageLayoutView->linkEditContent(htmlspecialchars($label), $this->pluginContentElement); |
||
203 | } |
||
204 | |||
205 | /** |
||
206 | * Returns the language service |
||
207 | * |
||
208 | * @return LanguageService |
||
209 | */ |
||
210 | protected function getLanguageService(): LanguageService |
||
211 | { |
||
212 | return $GLOBALS['LANG']; |
||
213 | } |
||
214 | } |
||
215 |