Skip to content

Commit 99731ec

Browse files
committed
Make Icon configuration optional with text fallback
- Conditionally load Icon helper only when Icon.sets is configured - Add icon element with text fallback for when icons are not configured - Update templates to use the icon element The backend UI now works without Icon.sets configured, showing text labels like [View], [Edit], [Del] instead of icons.
1 parent e447805 commit 99731ec

File tree

5 files changed

+43
-12
lines changed

5 files changed

+43
-12
lines changed

src/Controller/Admin/LoadHelperTrait.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace Queue\Controller\Admin;
55

6+
use Cake\Core\Configure;
67
use Templating\View\Helper\IconHelper;
78
use Templating\View\Helper\IconSnippetHelper;
89
use Templating\View\Helper\TemplatingHelper;
@@ -18,8 +19,10 @@ protected function loadHelpers(): void {
1819
'Tools.Format',
1920
'Tools.Text',
2021
'Tools.Time',
21-
class_exists(IconHelper::class) ? 'Templating.Icon' : 'Tools.Icon',
2222
];
23+
if (Configure::read('Icon.sets')) {
24+
$helpers[] = class_exists(IconHelper::class) ? 'Templating.Icon' : 'Tools.Icon';
25+
}
2326
if (class_exists(IconSnippetHelper::class)) {
2427
$helpers[] = 'Templating.IconSnippet';
2528
}

templates/Admin/QueueProcesses/index.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<td>
3939
<?= $this->Time->nice($queueProcess->created) ?>
4040
<?php if (!$queueProcess->created->addSeconds(Config::workermaxruntime())->isFuture()) {
41-
echo $this->Icon->render('exclamation-triangle', [], ['title' => 'Long running (!)']);
41+
echo $this->element('Queue.icon', ['name' => 'exclamation-triangle', 'attributes' => ['title' => 'Long running (!)']]);
4242
} ?>
4343
</td>
4444
<td>
@@ -53,9 +53,9 @@
5353
<td><?= $this->element('Queue.yes_no', ['value' => !$queueProcess->terminate]) ?></td>
5454
<td><?= h($queueProcess->server) ?></td>
5555
<td class="actions">
56-
<?= $this->Html->link($this->Icon->render('view'), ['action' => 'view', $queueProcess->id], ['escapeTitle' => false]); ?>
56+
<?= $this->Html->link($this->element('Queue.icon', ['name' => 'view']), ['action' => 'view', $queueProcess->id], ['escapeTitle' => false]); ?>
5757
<?php if (!$queueProcess->terminate) { ?>
58-
<?= $this->Form->postLink($this->Icon->render('times', [], ['title' => __d('queue', 'Terminate')]), ['action' => 'terminate', $queueProcess->id], ['escapeTitle' => false, 'confirm' => __d('queue', 'Are you sure you want to terminate # {0}?', $queueProcess->id)]); ?>
58+
<?= $this->Form->postLink($this->element('Queue.icon', ['name' => 'times', 'attributes' => ['title' => __d('queue', 'Terminate')]]), ['action' => 'terminate', $queueProcess->id], ['escapeTitle' => false, 'confirm' => __d('queue', 'Are you sure you want to terminate # {0}?', $queueProcess->id)]); ?>
5959
<?php } ?>
6060

6161
</td>

templates/Admin/QueueProcesses/view.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
<nav class="actions large-3 medium-4 columns col-sm-4 col-12" id="actions-sidebar">
99
<ul class="side-nav nav nav-pills flex-column">
1010
<li class="nav-item heading"><?= __d('queue', 'Actions') ?></li>
11-
<li class="nav-item"><?= $this->Html->link($this->Icon->render('edit') . ' ' . __d('queue', 'Edit Queue Process'), ['action' => 'edit', $queueProcess->id], ['escape' => false]) ?> </li>
11+
<li class="nav-item"><?= $this->Html->link($this->element('Queue.icon', ['name' => 'edit']) . ' ' . __d('queue', 'Edit Queue Process'), ['action' => 'edit', $queueProcess->id], ['escape' => false]) ?> </li>
1212

1313
<?php if (!$queueProcess->terminate) { ?>
14-
<li class="nav-item"><?= $this->Form->postLink($this->Icon->render('times', [], ['title' => __d('queue', 'Terminate')]). ' ' . __d('queue', 'Terminate (clean remove)'), ['action' => 'terminate', $queueProcess->id], ['escapeTitle' => false, 'confirm' => __d('queue', 'Are you sure you want to terminate # {0}?', $queueProcess->id)]); ?></li>
14+
<li class="nav-item"><?= $this->Form->postLink($this->element('Queue.icon', ['name' => 'times', 'attributes' => ['title' => __d('queue', 'Terminate')]]) . ' ' . __d('queue', 'Terminate (clean remove)'), ['action' => 'terminate', $queueProcess->id], ['escapeTitle' => false, 'confirm' => __d('queue', 'Are you sure you want to terminate # {0}?', $queueProcess->id)]); ?></li>
1515
<?php } else { ?>
16-
<li class="nav-item"><?php echo $this->Form->postLink($this->Icon->render('delete'). ' ' . __d('queue', 'Delete (not advised)'), ['action' => 'delete', $queueProcess->id], ['escapeTitle' => false, 'confirm' => __d('queue', 'Are you sure you want to delete # {0}?', $queueProcess->id)]); ?></li>
16+
<li class="nav-item"><?php echo $this->Form->postLink($this->element('Queue.icon', ['name' => 'delete']) . ' ' . __d('queue', 'Delete (not advised)'), ['action' => 'delete', $queueProcess->id], ['escapeTitle' => false, 'confirm' => __d('queue', 'Are you sure you want to delete # {0}?', $queueProcess->id)]); ?></li>
1717
<?php } ?>
1818

1919
<li class="nav-item"><?= $this->Html->link(__d('queue', 'List {0}', __d('queue', 'Queue Processes')), ['action' => 'index']) ?> </li>
@@ -27,7 +27,7 @@
2727
<td>
2828
<?= $this->Time->nice($queueProcess->created) ?>
2929
<?php if (!$queueProcess->created->addSeconds(Config::defaultworkertimeout())->isFuture()) {
30-
echo $this->Icon->render('exclamation-triangle', [], ['title' => 'Long running (!)']);
30+
echo $this->element('Queue.icon', ['name' => 'exclamation-triangle', 'attributes' => ['title' => 'Long running (!)']]);
3131
} ?>
3232
</td>
3333
</tr>

templates/Admin/QueuedJobs/index.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
$data = json_decode($queuedJob->data, true);
6565
}
6666
$data = VarExporter::export($data, VarExporter::TRAILING_COMMA_IN_ARRAY);
67-
echo $this->Icon->render('cubes', [], ['title' => $this->Text->truncate($data, 1000)]);
67+
echo $this->element('Queue.icon', ['name' => 'cubes', 'attributes' => ['title' => $this->Text->truncate($data, 1000)]]);
6868
}
6969
?>
7070
</td>
@@ -132,12 +132,12 @@
132132
</td>
133133
<td><?= $this->Number->format($queuedJob->priority) ?></td>
134134
<td class="actions">
135-
<?= $this->Html->link($this->Icon->render('view'), ['action' => 'view', $queuedJob->id], ['escapeTitle' => false]); ?>
135+
<?= $this->Html->link($this->element('Queue.icon', ['name' => 'view']), ['action' => 'view', $queuedJob->id], ['escapeTitle' => false]); ?>
136136

137137
<?php if (!$queuedJob->completed) { ?>
138-
<?= $this->Html->link($this->Icon->render('edit'), ['action' => 'edit', $queuedJob->id], ['escapeTitle' => false]); ?>
138+
<?= $this->Html->link($this->element('Queue.icon', ['name' => 'edit']), ['action' => 'edit', $queuedJob->id], ['escapeTitle' => false]); ?>
139139
<?php } ?>
140-
<?= $this->Form->postLink($this->Icon->render('delete'), ['action' => 'delete', $queuedJob->id], ['escapeTitle' => false, 'confirm' => __d('queue', 'Are you sure you want to delete # {0}?', $queuedJob->id)]); ?>
140+
<?= $this->Form->postLink($this->element('Queue.icon', ['name' => 'delete']), ['action' => 'delete', $queuedJob->id], ['escapeTitle' => false, 'confirm' => __d('queue', 'Are you sure you want to delete # {0}?', $queuedJob->id)]); ?>
141141
</td>
142142
</tr>
143143
<?php endforeach; ?>

templates/element/icon.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* Icon element with text fallback when Icon helper is not available.
4+
*
5+
* @var \App\View\AppView $this
6+
* @var string $name Icon name
7+
* @var array<string, mixed> $options Icon options
8+
* @var array<string, mixed> $attributes Icon attributes
9+
*/
10+
11+
$options ??= [];
12+
$attributes ??= [];
13+
14+
$fallbackMap = [
15+
'view' => 'View',
16+
'edit' => 'Edit',
17+
'delete' => 'Del',
18+
'times' => 'X',
19+
'exclamation-triangle' => '(!)',
20+
'cubes' => 'Data',
21+
];
22+
23+
if ($this->helpers()->has('Icon')) {
24+
echo $this->Icon->render($name, $options, $attributes);
25+
} else {
26+
$title = $attributes['title'] ?? $fallbackMap[$name] ?? ucfirst($name);
27+
echo '<span title="' . h($title) . '">[' . h($fallbackMap[$name] ?? ucfirst($name)) . ']</span>';
28+
}

0 commit comments

Comments
 (0)