Skip to content

Commit

Permalink
Use new templating plugin where possible. (#416)
Browse files Browse the repository at this point in the history
* Use new templating plugin where possible.

* Fix CS

* Update yes_no.php
  • Loading branch information
dereuromark authored Mar 11, 2024
1 parent 3a587de commit 0ee9d56
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 9 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"cakephp/bake": "^3.0.1",
"cakephp/migrations": "^4.0.1",
"dereuromark/cakephp-ide-helper": "^2.0.0",
"dereuromark/cakephp-templating": "^0.2.1",
"dereuromark/cakephp-tools": "^3.0.0",
"dereuromark/cakephp-dto": "^2.1.0",
"fig-r/psr2r-sniffer": "dev-next",
Expand Down
2 changes: 1 addition & 1 deletion config/app.example.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* To modify these parameters, copy this file into your own CakePHP config directory or copy the array into your existing file.
*/
use Tools\View\Icon\BootstrapIcon;
use Templating\View\Icon\BootstrapIcon;

return [
'Queue' => [
Expand Down
10 changes: 7 additions & 3 deletions src/Controller/Admin/LoadHelperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Queue\Controller\Admin;

use Templating\View\Helper\IconHelper;
use Templating\View\Helper\IconSnippetHelper;

trait LoadHelperTrait {

Expand All @@ -12,12 +13,15 @@ trait LoadHelperTrait {
*/
protected function loadHelpers(): void {
$helpers = [
'Tools.Time',
'Shim.Configure',
'Tools.Format',
class_exists(IconHelper::class) ? 'Templating.Icon' : 'Tools.Icon',
'Tools.Text',
'Shim.Configure',
'Tools.Time',
class_exists(IconHelper::class) ? 'Templating.Icon' : 'Tools.Icon',
];
if (class_exists(IconSnippetHelper::class)) {
$helpers[] = 'Templating.IconSnippet';
}

$this->viewBuilder()->addHelpers($helpers);
}
Expand Down
4 changes: 2 additions & 2 deletions templates/Admin/Queue/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
$time = $status['time'];
$running = $time->addMinutes(1)->isFuture();
?>
<?php echo $this->Format->yesNo($running); ?> <?php echo $running ? __d('queue', 'Running') : __d('queue', 'Not running'); ?> (<?php echo __d('queue', 'last {0}', $this->Time->relLengthOfTime($status['time']))?>)
<?php echo $this->element('Queue.yes_no', ['value' => $running]); ?> <?php echo $running ? __d('queue', 'Running') : __d('queue', 'Not running'); ?> (<?php echo __d('queue', 'last {0}', $this->Time->relLengthOfTime($status['time']))?>)

<?php
echo '<div><small>Currently ' . $this->Html->link($status['workers'] . ' worker(s)', ['action' => 'processes']) . ' total.</small></div>';
Expand Down Expand Up @@ -136,7 +136,7 @@
Server:
<ul>
<li>
<code>posix</code> extension enabled (optional, recommended): <?php echo $this->Format->yesNo(function_exists('posix_kill')); ?>
<code>posix</code> extension enabled (optional, recommended): <?php echo $this->element('Queue.yes_no', ['value' => function_exists('posix_kill')]); ?>
</li>
</ul>

Expand Down
2 changes: 1 addition & 1 deletion templates/Admin/QueueProcesses/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
echo $modified;
?>
</td>
<td><?= $this->Format->yesNo(!$queueProcess->terminate) ?></td>
<td><?= $this->element('Queue.yes_no', ['value' => !$queueProcess->terminate]) ?></td>
<td><?= h($queueProcess->server) ?></td>
<td class="actions">
<?= $this->Html->link($this->Icon->render('view'), ['action' => 'view', $queueProcess->id], ['escapeTitle' => false]); ?>
Expand Down
5 changes: 4 additions & 1 deletion templates/Admin/QueueProcesses/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
</tr>
<tr>
<th><?= __d('queue', 'Active') ?></th>
<td><?= $this->Format->yesNo(!$queueProcess->terminate) ?></td>
<td>
<?= $this->element('Queue.yes_no', ['value' => !$queueProcess->terminate]) ?>
<?php echo !$queueProcess->terminate ? 'Yes' : 'No' ?>
</td>
</tr>
<tr>
<th><?= __d('queue', 'Server') ?></th>
Expand Down
17 changes: 17 additions & 0 deletions templates/element/yes_no.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* Overwrite this element snippet locally to customize if needed.
*
* @var \App\View\AppView $this
* @var bool $value
*/
?>
<?php
if ($this->helpers()->has('IconSnippet')) {
echo $this->IconSnippet->yesNo($value);
} elseif ($this->helpers()->has('Format')) {
echo $this->Format->yesNo($value);
} else {
echo $value ? '<span class="yes-no yes-no-yes">Yes</span>' : '<span class="yes-no yes-no-no">No</span>';
}
?>
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
use Foo\FooPlugin;
use Queue\QueuePlugin;
use Shim\Filesystem\Folder;
use Templating\View\Icon\BootstrapIcon;
use TestApp\Controller\AppController;
use TestApp\View\AppView;
use Tools\View\Icon\BootstrapIcon;

if (!defined('DS')) {
define('DS', DIRECTORY_SEPARATOR);
Expand Down
2 changes: 2 additions & 0 deletions tests/test_app/src/View/AppView.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* Fake AppView for IDE autocomplete it templates
*
* @property \Tools\View\Helper\FormatHelper $Format
* @property \Templating\View\Helper\IconHelper $Icon
* @property \Templating\View\Helper\IconSnippetHelper $IconSnippet
* @property \Tools\View\Helper\TimeHelper $Time
* @property \Queue\View\Helper\QueueHelper $Queue
* @property \Queue\View\Helper\QueueProgressHelper $QueueProgress
Expand Down

0 comments on commit 0ee9d56

Please sign in to comment.