Skip to content

Commit f2e0cd0

Browse files
authored
Improve UX for template buttons - replace PR joomla#43592 (joomla#43975)
1 parent ba9d945 commit f2e0cd0

File tree

2 files changed

+41
-35
lines changed

2 files changed

+41
-35
lines changed

administrator/components/com_templates/src/View/Template/HtmlView.php

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -236,39 +236,9 @@ protected function addToolbar()
236236

237237
// User is global SuperUser
238238
$isSuperUser = $user->authorise('core.admin');
239-
$explodeArray = explode('.', $this->fileName);
240-
$ext = end($explodeArray);
241239

242240
ToolbarHelper::title(Text::sprintf('COM_TEMPLATES_MANAGER_VIEW_TEMPLATE', ucfirst($this->template->name)), 'icon-code thememanager');
243241

244-
// Only show file edit buttons for global SuperUser
245-
if ($isSuperUser) {
246-
// Add an Apply and save button
247-
if ($this->type === 'file') {
248-
$toolbar->apply('template.apply');
249-
$toolbar->save('template.save');
250-
} elseif ($this->type === 'image') {
251-
// Add a Crop and Resize button
252-
$toolbar->standardButton('crop', 'COM_TEMPLATES_BUTTON_CROP', 'template.cropImage')
253-
->listCheck(false)
254-
->icon('icon-crop');
255-
ToolbarHelper::modal('resizeModal', 'icon-expand', 'COM_TEMPLATES_BUTTON_RESIZE');
256-
} elseif ($this->type === 'archive') {
257-
// Add an extract button
258-
$toolbar->standardButton('extract', 'COM_TEMPLATES_BUTTON_EXTRACT_ARCHIVE', 'template.extractArchive')
259-
->listCheck(false)
260-
->icon('icon-chevron-down');
261-
} elseif ($this->type === 'home') {
262-
// Add a copy/child template button
263-
if (isset($this->template->xmldata->inheritable) && (string) $this->template->xmldata->inheritable === '1') {
264-
ToolbarHelper::modal('childModal', 'icon-copy', 'COM_TEMPLATES_BUTTON_TEMPLATE_CHILD');
265-
} elseif (empty($this->template->xmldata->parent) && empty($this->template->xmldata->namespace)) {
266-
// We can't copy parent templates nor namespaced templates
267-
ToolbarHelper::modal('copyModal', 'icon-copy', 'COM_TEMPLATES_BUTTON_COPY_TEMPLATE');
268-
}
269-
}
270-
}
271-
272242
// Add a Template preview button
273243
if ($this->type === 'home') {
274244
$client = (int) $this->preview->client_id === 1 ? 'administrator/' : '';
@@ -278,6 +248,44 @@ protected function addToolbar()
278248
->attributes(['target' => '_new']);
279249
}
280250

251+
// Only show file edit buttons for global SuperUser
252+
if ($isSuperUser) {
253+
switch ($this->type) {
254+
case 'file':
255+
$toolbar->apply('template.apply');
256+
$toolbar->save('template.save');
257+
$toolbar->cancel('template.close', 'COM_TEMPLATES_BUTTON_CLOSE_FILE');
258+
break;
259+
260+
case 'image':
261+
// Add a Crop and Resize button
262+
$toolbar->standardButton('crop', 'COM_TEMPLATES_BUTTON_CROP', 'template.cropImage')
263+
->listCheck(false)
264+
->icon('icon-crop');
265+
ToolbarHelper::modal('resizeModal', 'icon-expand', 'COM_TEMPLATES_BUTTON_RESIZE');
266+
$toolbar->cancel('template.close', 'COM_TEMPLATES_BUTTON_CLOSE_FILE');
267+
break;
268+
269+
case 'archive':
270+
// Add an extract button
271+
$toolbar->standardButton('extract', 'COM_TEMPLATES_BUTTON_EXTRACT_ARCHIVE', 'template.extractArchive')
272+
->listCheck(false)
273+
->icon('icon-chevron-down');
274+
break;
275+
276+
case 'home':
277+
// Add a copy/child template button
278+
if (isset($this->template->xmldata->inheritable) && (string) $this->template->xmldata->inheritable === '1') {
279+
ToolbarHelper::modal('childModal', 'icon-copy', 'COM_TEMPLATES_BUTTON_TEMPLATE_CHILD');
280+
} elseif (empty($this->template->xmldata->parent) && empty($this->template->xmldata->namespace)) {
281+
// We can't copy parent templates nor namespaced templates
282+
ToolbarHelper::modal('copyModal', 'icon-copy', 'COM_TEMPLATES_BUTTON_COPY_TEMPLATE');
283+
}
284+
285+
break;
286+
}
287+
}
288+
281289
// Only show file manage buttons for global SuperUser
282290
if ($isSuperUser) {
283291
if ($this->type === 'home') {
@@ -291,7 +299,7 @@ protected function addToolbar()
291299
ToolbarHelper::modal('renameModal', 'icon-sync', 'COM_TEMPLATES_BUTTON_RENAME_FILE');
292300

293301
// Add a Delete file Button
294-
ToolbarHelper::modal('deleteModal', 'icon-times', 'COM_TEMPLATES_BUTTON_DELETE_FILE', 'btn-danger');
302+
ToolbarHelper::modal('deleteModal', 'icon-trash', 'COM_TEMPLATES_BUTTON_DELETE_FILE', 'btn-danger');
295303
}
296304
}
297305

@@ -320,10 +328,8 @@ protected function addToolbar()
320328
->listCheck(true);
321329
}
322330

323-
if ($this->type === 'home') {
331+
if (!\in_array($this->type, ['image', 'file'])) {
324332
$toolbar->cancel('template.cancel');
325-
} else {
326-
$toolbar->cancel('template.close', 'COM_TEMPLATES_BUTTON_CLOSE_FILE');
327333
}
328334

329335
$toolbar->divider();

administrator/language/en-GB/com_templates.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ COM_TEMPLATES_ASSIGNED_1="Assigned to one menu item."
99
COM_TEMPLATES_ASSIGNED_MORE="Assigned to %d menu items."
1010
COM_TEMPLATES_BUTTON_CHECK="Check Overrides"
1111
COM_TEMPLATES_BUTTON_CHECK_LIST_ENTRY="Mark Checked"
12-
COM_TEMPLATES_BUTTON_CLOSE_FILE="Close File"
12+
COM_TEMPLATES_BUTTON_CLOSE_FILE="Close"
1313
COM_TEMPLATES_BUTTON_COPY_FILE="Copy File"
1414
COM_TEMPLATES_BUTTON_COPY_TEMPLATE="Copy Template"
1515
COM_TEMPLATES_BUTTON_CREATE="Create"

0 commit comments

Comments
 (0)