77use TYPO3 \CMS \Backend \Routing \UriBuilder ;
88use TYPO3 \CMS \Backend \Utility \BackendUtility ;
99use TYPO3 \CMS \Core \Authentication \BackendUserAuthentication ;
10+ use TYPO3 \CMS \Core \Configuration \ExtensionConfiguration ;
1011use TYPO3 \CMS \Core \Core \Bootstrap ;
1112use TYPO3 \CMS \Core \EventDispatcher \EventDispatcher ;
1213use TYPO3 \CMS \Core \Imaging \Icon ;
1314use TYPO3 \CMS \Core \Imaging \IconFactory ;
1415use TYPO3 \CMS \Core \Utility \GeneralUtility ;
16+ use Xima \XimaTypo3FrontendEdit \Configuration ;
1517use Xima \XimaTypo3FrontendEdit \Enumerations \ButtonType ;
1618use Xima \XimaTypo3FrontendEdit \Event \FrontendEditDropdownModifyEvent ;
1719use Xima \XimaTypo3FrontendEdit \Template \Component \Button ;
@@ -21,11 +23,16 @@ final class MenuGenerator
2123{
2224 protected array $ configuration = [];
2325
24- public function __construct (protected readonly IconFactory $ iconFactory , protected readonly EventDispatcher $ eventDispatcher , protected readonly SettingsService $ settingsService )
25- {
26+ public function __construct (
27+ protected readonly IconFactory $ iconFactory ,
28+ protected readonly EventDispatcher $ eventDispatcher ,
29+ protected readonly SettingsService $ settingsService ,
30+ protected readonly ExtensionConfiguration $ extensionConfiguration
31+ ) {
32+ $ this ->configuration = $ this ->extensionConfiguration ->get (Configuration::EXT_KEY );
2633 }
2734
28- public function getDropdown (int $ pid , string $ returnUrl , int $ languageUid , array $ data = [], bool $ linkTargetBlank = false ): array
35+ public function getDropdown (int $ pid , string $ returnUrl , int $ languageUid , array $ data = []): array
2936 {
3037 $ ignoredPids = $ this ->settingsService ->getIgnoredPids ();
3138 foreach ($ ignoredPids as $ ignoredPid ) {
@@ -72,141 +79,158 @@ public function getDropdown(int $pid, string $returnUrl, int $languageUid, array
7279 $ contentElementConfig = ContentUtility::getContentElementConfig ($ contentElement ['CType ' ], $ contentElement ['list_type ' ]);
7380 $ returnUrlAnchor = $ returnUrl . '#c ' . $ contentElement ['uid ' ];
7481
75- $ menuButton = new Button (
76- 'LLL:EXT:xima_typo3_frontend_edit/Resources/Private/Language/locallang.xlf:edit_menu ' ,
77- ButtonType::Menu,
78- icon: $ this ->iconFactory ->getIcon ('actions-open ' , Icon::SIZE_SMALL )
79- );
82+ $ simpleMode = (array_key_exists ('simpleMode ' , $ this ->configuration ) && $ this ->configuration ['simpleMode ' ]) || $ this ->settingsService ->checkSimpleModeMenuStructure ();
8083
81- /*
82- * Info
83- */
84- $ this ->processNewButton ($ menuButton , 'div_info ' , ButtonType::Divider);
84+ if ($ simpleMode ) {
85+ $ menuButton = new Button (
86+ 'LLL:EXT:xima_typo3_frontend_edit/Resources/Private/Language/locallang.xlf:edit_menu ' ,
87+ ButtonType::Link,
88+ url: GeneralUtility::makeInstance (UriBuilder::class)->buildUriFromRoute (
89+ 'record_edit ' ,
90+ [
91+ 'edit ' => [
92+ 'tt_content ' => [
93+ $ contentElement ['uid ' ] => 'edit ' ,
94+ ],
95+ 'language ' => $ languageUid ,
96+ ],
97+ 'returnUrl ' => $ returnUrlAnchor ,
98+ ]
99+ )->__toString (),
100+ icon: $ this ->iconFactory ->getIcon ('actions-open ' , Icon::SIZE_SMALL ),
101+ targetBlank: array_key_exists ('linkTargetBlank ' , $ this ->configuration ) && $ this ->configuration ['linkTargetBlank ' ]
102+ );
103+ } else {
104+ $ menuButton = new Button (
105+ 'LLL:EXT:xima_typo3_frontend_edit/Resources/Private/Language/locallang.xlf:edit_menu ' ,
106+ ButtonType::Menu,
107+ icon: $ this ->iconFactory ->getIcon ('actions-open ' , Icon::SIZE_SMALL )
108+ );
85109
86- $ additionalUid = $ GLOBALS ['BE_USER ' ]->isAdmin () ? ' <code>[ ' . $ contentElement ['uid ' ] . ']</code> ' : '' ;
87- $ this ->processNewButton (
88- $ menuButton ,
89- 'header ' ,
90- ButtonType::Info,
91- label: $ GLOBALS ['LANG ' ]->sL ($ contentElementConfig ['label ' ]) . '<p><small> ' . ($ contentElement ['header ' ] ? ContentUtility::shortenString ($ contentElement ['header ' ]) : '' ) . $ additionalUid . '</small></p> ' ,
92- icon: $ contentElementConfig ['icon ' ]
93- );
110+ /*
111+ * Info
112+ */
113+ $ this ->processNewButton ($ menuButton , 'div_info ' , ButtonType::Divider);
94114
95- /*
96- * Edit
97- */
98- $ this ->processNewButton ($ menuButton , 'div_edit ' , ButtonType::Divider);
99- $ this ->processNewButton (
100- $ menuButton ,
101- 'edit ' ,
102- ButtonType::Link,
103- label: $ contentElement ['CType ' ] === 'list ' ? 'LLL:EXT:xima_typo3_frontend_edit/Resources/Private/Language/locallang.xlf:edit_plugin ' : 'LLL:EXT:xima_typo3_frontend_edit/Resources/Private/Language/locallang.xlf:edit_content_element ' ,
104- url: GeneralUtility::makeInstance (UriBuilder::class)->buildUriFromRoute (
105- 'record_edit ' ,
106- [
107- 'edit ' => [
108- 'tt_content ' => [
109- $ contentElement ['uid ' ] => 'edit ' ,
115+ $ additionalUid = $ GLOBALS ['BE_USER ' ]->isAdmin () ? ' <code>[ ' . $ contentElement ['uid ' ] . ']</code> ' : '' ;
116+ $ this ->processNewButton (
117+ $ menuButton ,
118+ 'header ' ,
119+ ButtonType::Info,
120+ label: $ GLOBALS ['LANG ' ]->sL ($ contentElementConfig ['label ' ]) . '<p><small> ' . ($ contentElement ['header ' ] ? ContentUtility::shortenString ($ contentElement ['header ' ]) : '' ) . $ additionalUid . '</small></p> ' ,
121+ icon: $ contentElementConfig ['icon ' ]
122+ );
123+
124+ /*
125+ * Edit
126+ */
127+ $ this ->processNewButton ($ menuButton , 'div_edit ' , ButtonType::Divider);
128+ $ this ->processNewButton (
129+ $ menuButton ,
130+ 'edit ' ,
131+ ButtonType::Link,
132+ label: $ contentElement ['CType ' ] === 'list ' ? 'LLL:EXT:xima_typo3_frontend_edit/Resources/Private/Language/locallang.xlf:edit_plugin ' : 'LLL:EXT:xima_typo3_frontend_edit/Resources/Private/Language/locallang.xlf:edit_content_element ' ,
133+ url: GeneralUtility::makeInstance (UriBuilder::class)->buildUriFromRoute (
134+ 'record_edit ' ,
135+ [
136+ 'edit ' => [
137+ 'tt_content ' => [
138+ $ contentElement ['uid ' ] => 'edit ' ,
139+ ],
140+ 'language ' => $ languageUid ,
110141 ],
142+ 'returnUrl ' => $ returnUrlAnchor ,
143+ ]
144+ )->__toString ()
145+ . '&tx_ximatypo3frontendedit ' , // add custom parameter to identify the request and render the save and close button in the edit form
146+ icon: $ contentElement ['CType ' ] === 'list ' ? 'content-plugin ' : 'content-textpic '
147+ );
148+ $ this ->processNewButton (
149+ $ menuButton ,
150+ 'edit_page ' ,
151+ ButtonType::Link,
152+ url: GeneralUtility::makeInstance (UriBuilder::class)->buildUriFromRoute (
153+ 'web_layout ' ,
154+ [
155+ 'id ' => $ pid ,
111156 'language ' => $ languageUid ,
157+ 'returnUrl ' => $ returnUrlAnchor ,
112158 ],
113- 'returnUrl ' => $ returnUrlAnchor ,
114- ]
115- )->__toString ()
116- . '&tx_ximatypo3frontendedit ' , // add custom parameter to identify the request and render the save and close button in the edit form
117- icon: $ contentElement ['CType ' ] === 'list ' ? 'content-plugin ' : 'content-textpic ' ,
118- linkTargetBlank: $ linkTargetBlank
119- );
120- $ this ->processNewButton (
121- $ menuButton ,
122- 'edit_page ' ,
123- ButtonType::Link,
124- url: GeneralUtility::makeInstance (UriBuilder::class)->buildUriFromRoute (
125- 'web_layout ' ,
126- [
127- 'id ' => $ pid ,
128- 'language ' => $ languageUid ,
129- 'returnUrl ' => $ returnUrlAnchor ,
130- ],
131- )->__toString (),
132- icon: 'apps-pagetree-page-default ' ,
133- linkTargetBlank: $ linkTargetBlank
134- );
159+ )->__toString (),
160+ icon: 'apps-pagetree-page-default '
161+ );
135162
136- /*
137- * Action
138- */
139- $ this ->processNewButton ($ menuButton , 'div_action ' , ButtonType::Divider);
140- $ this ->processNewButton (
141- $ menuButton ,
142- 'hide ' ,
143- ButtonType::Link,
144- url: GeneralUtility::makeInstance (UriBuilder::class)->buildUriFromRoute (
145- 'tce_db ' ,
146- [
147- 'data ' => [
148- 'tt_content ' => [
149- $ contentElement ['uid ' ] => [
150- 'hidden ' => 1 ,
163+ /*
164+ * Action
165+ */
166+ $ this ->processNewButton ($ menuButton , 'div_action ' , ButtonType::Divider);
167+ $ this ->processNewButton (
168+ $ menuButton ,
169+ 'hide ' ,
170+ ButtonType::Link,
171+ url: GeneralUtility::makeInstance (UriBuilder::class)->buildUriFromRoute (
172+ 'tce_db ' ,
173+ [
174+ 'data ' => [
175+ 'tt_content ' => [
176+ $ contentElement ['uid ' ] => [
177+ 'hidden ' => 1 ,
178+ ],
151179 ],
152180 ],
181+ 'redirect ' => $ returnUrlAnchor ,
153182 ],
154- 'redirect ' => $ returnUrlAnchor ,
155- ],
156- )->__toString (),
157- icon: 'actions-toggle-on '
158- );
159- $ this ->processNewButton (
160- $ menuButton ,
161- 'info ' ,
162- ButtonType::Link,
163- url: GeneralUtility::makeInstance (UriBuilder::class)->buildUriFromRoute (
164- 'show_item ' ,
165- [
166- 'uid ' => $ contentElement ['uid ' ],
167- 'table ' => 'tt_content ' ,
168- 'returnUrl ' => $ returnUrlAnchor ,
169- ],
170- )->__toString (),
171- icon: 'actions-info ' ,
172- linkTargetBlank: $ linkTargetBlank
173- );
174- $ this ->processNewButton (
175- $ menuButton ,
176- 'move ' ,
177- ButtonType::Link,
178- url: GeneralUtility::makeInstance (UriBuilder::class)->buildUriFromRoute (
179- 'move_element ' ,
180- [
181- 'uid ' => $ contentElement ['uid ' ],
182- 'table ' => 'tt_content ' ,
183- 'expandPage ' => $ pid ,
184- 'returnUrl ' => $ returnUrlAnchor ,
185- ],
186- )->__toString (),
187- icon: 'actions-move ' ,
188- linkTargetBlank: $ linkTargetBlank
189- );
190- $ this ->processNewButton (
191- $ menuButton ,
192- 'history ' ,
193- ButtonType::Link,
194- url: GeneralUtility::makeInstance (UriBuilder::class)->buildUriFromRoute (
195- 'record_history ' ,
196- [
197- 'element ' => 'tt_content: ' . $ contentElement ['uid ' ],
198- 'returnUrl ' => $ returnUrlAnchor ,
199- ],
200- )->__toString (),
201- icon: 'actions-history ' ,
202- linkTargetBlank: $ linkTargetBlank
203- );
204-
205- /*
206- * Data
207- */
208- $ this ->handleAdditionalData ($ menuButton , $ contentElement , $ contentElementConfig , $ data , $ backendUser , $ languageUid , $ returnUrlAnchor );
183+ )->__toString (),
184+ icon: 'actions-toggle-on '
185+ );
186+ $ this ->processNewButton (
187+ $ menuButton ,
188+ 'info ' ,
189+ ButtonType::Link,
190+ url: GeneralUtility::makeInstance (UriBuilder::class)->buildUriFromRoute (
191+ 'show_item ' ,
192+ [
193+ 'uid ' => $ contentElement ['uid ' ],
194+ 'table ' => 'tt_content ' ,
195+ 'returnUrl ' => $ returnUrlAnchor ,
196+ ],
197+ )->__toString (),
198+ icon: 'actions-info '
199+ );
200+ $ this ->processNewButton (
201+ $ menuButton ,
202+ 'move ' ,
203+ ButtonType::Link,
204+ url: GeneralUtility::makeInstance (UriBuilder::class)->buildUriFromRoute (
205+ 'move_element ' ,
206+ [
207+ 'uid ' => $ contentElement ['uid ' ],
208+ 'table ' => 'tt_content ' ,
209+ 'expandPage ' => $ pid ,
210+ 'returnUrl ' => $ returnUrlAnchor ,
211+ ],
212+ )->__toString (),
213+ icon: 'actions-move '
214+ );
215+ $ this ->processNewButton (
216+ $ menuButton ,
217+ 'history ' ,
218+ ButtonType::Link,
219+ url: GeneralUtility::makeInstance (UriBuilder::class)->buildUriFromRoute (
220+ 'record_history ' ,
221+ [
222+ 'element ' => 'tt_content: ' . $ contentElement ['uid ' ],
223+ 'returnUrl ' => $ returnUrlAnchor ,
224+ ],
225+ )->__toString (),
226+ icon: 'actions-history '
227+ );
209228
229+ /*
230+ * Data
231+ */
232+ $ this ->handleAdditionalData ($ menuButton , $ contentElement , $ contentElementConfig , $ data , $ backendUser , $ languageUid , $ returnUrlAnchor );
233+ }
210234 /*
211235 * Event
212236 */
@@ -223,7 +247,7 @@ public function getDropdown(int $pid, string $returnUrl, int $languageUid, array
223247 return $ result ;
224248 }
225249
226- private function processNewButton (Button &$ button , string $ identifier , ButtonType $ type , ?string $ label = null , ?string $ url = null , ?string $ icon = null , bool $ linkTargetBlank = false ): void
250+ private function processNewButton (Button &$ button , string $ identifier , ButtonType $ type , ?string $ label = null , ?string $ url = null , ?string $ icon = null ): void
227251 {
228252 if (!$ this ->settingsService ->checkDefaultMenuStructure ($ identifier )) {
229253 return ;
@@ -234,14 +258,14 @@ private function processNewButton(Button &$button, string $identifier, ButtonTyp
234258 $ type ,
235259 $ url ,
236260 $ icon ? $ this ->iconFactory ->getIcon ($ icon , Icon::SIZE_SMALL ) : null ,
237- $ linkTargetBlank
261+ array_key_exists ( ' linkTargetBlank ' , $ this -> configuration ) && $ this -> configuration [ ' linkTargetBlank ' ]
238262 ), $ identifier );
239263 }
240264
241265 private function handleAdditionalData (Button $ button , array $ contentElement , array $ contentElementConfig , array $ data , BackendUserAuthentication $ backendUser , int $ languageUid , string $ returnUrlAnchor ): void
242266 {
243267 if ((array_key_exists ($ contentElement ['uid ' ], $ data ) && ($ uid = $ contentElement ['uid ' ]) && !empty ($ data [$ uid ])) ||
244- (array_key_exists ('l10n_source ' , $ contentElement ) && array_key_exists ($ contentElement ['l10n_source ' ], $ data ) && ($ uid = $ contentElement ['l10n_source ' ])&& !empty ($ data [$ uid ]))
268+ (array_key_exists ('l10n_source ' , $ contentElement ) && array_key_exists ($ contentElement ['l10n_source ' ], $ data ) && ($ uid = $ contentElement ['l10n_source ' ]) && !empty ($ data [$ uid ]))
245269 ) {
246270 $ button ->appendChild (new Button (
247271 'LLL:EXT:xima_typo3_frontend_edit/Resources/Private/Language/locallang.xlf:div_data ' ,
0 commit comments