Skip to content

Commit adad112

Browse files
authored
Merge pull request #344 from FriendsOfCake/action-group-single-action
Don't generate dropdown if the action group has only 1 action.
2 parents e7aaa42 + 2296b04 commit adad112

File tree

8 files changed

+18
-21
lines changed

8 files changed

+18
-21
lines changed

phpstan-baseline.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ parameters:
1919
path: src/Listener/ViewListener.php
2020

2121
-
22-
message: '#^Parameter \#1 \$field of method CrudView\\Listener\\ViewListener\:\:_deriveFieldFromContext\(\) expects string, list\<string\>\|string\|null given\.$#'
22+
message: '#^Parameter \#1 \$field of method CrudView\\Listener\\ViewListener\:\:_deriveFieldFromContext\(\) expects string, array\<string\>\|string\|null given\.$#'
2323
identifier: argument.type
2424
count: 1
2525
path: src/Listener/ViewListener.php

src/Breadcrumb/ActiveBreadcrumb.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ class ActiveBreadcrumb extends Breadcrumb
99
/**
1010
* // phpcs:ignore
1111
* @inheritDoc
12-
* @psalm-suppress MissingParamType
1312
*/
1413
public function __construct(string|array $title, string|array|null $url = null, array $options = [])
1514
{

src/Listener/ViewListener.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class ViewListener extends BaseListener
4242
*
4343
* @param \Cake\Event\EventInterface $event Event.
4444
* @return void
45-
* @psalm-param \Cake\Event\EventInterface<\Crud\Event\Subject> $event
45+
* @phpstan-param \Cake\Event\EventInterface<\Crud\Event\Subject> $event
4646
*/
4747
public function beforeFind(EventInterface $event): void
4848
{
@@ -63,7 +63,7 @@ public function beforeFind(EventInterface $event): void
6363
*
6464
* @param \Cake\Event\EventInterface $event Event.
6565
* @return void
66-
* @psalm-param \Cake\Event\EventInterface<\Crud\Event\Subject> $event
66+
* @phpstan-param \Cake\Event\EventInterface<\Crud\Event\Subject> $event
6767
*/
6868
public function beforePaginate(EventInterface $event): void
6969
{
@@ -84,7 +84,7 @@ public function beforePaginate(EventInterface $event): void
8484
*
8585
* @param \Cake\Event\EventInterface $event Event.
8686
* @return void
87-
* @psalm-param \Cake\Event\EventInterface<\Crud\Event\Subject> $event
87+
* @phpstan-param \Cake\Event\EventInterface<\Crud\Event\Subject> $event
8888
*/
8989
public function beforeRender(EventInterface $event): void
9090
{
@@ -96,7 +96,6 @@ public function beforeRender(EventInterface $event): void
9696
$this->_entity = $event->getSubject()->entity;
9797
}
9898

99-
/** @psalm-suppress RedundantPropertyInitializationCheck */
10099
if (!isset($this->associations)) {
101100
$this->associations = $this->_associations(array_keys($this->_getRelatedModels()));
102101
}
@@ -134,12 +133,11 @@ public function beforeRender(EventInterface $event): void
134133
*
135134
* @param \Cake\Event\EventInterface $event Event.
136135
* @return void
137-
* @psalm-param \Cake\Event\EventInterface<\Crud\Event\Subject> $event
136+
* @phpstan-param \Cake\Event\EventInterface<\Crud\Event\Subject> $event
138137
*/
139138
public function setFlash(EventInterface $event): void
140139
{
141140
unset($event->getSubject()->params['class']);
142-
/** @psalm-suppress UndefinedPropertyAssignment */
143141
$event->getSubject()->element = ltrim($event->getSubject()->type);
144142
}
145143

@@ -181,11 +179,11 @@ protected function _getPageTitle(): string
181179
$displayFieldValue === null
182180
|| $this->_model()->getDisplayField() === $this->_model()->getPrimaryKey()
183181
) {
184-
/** @psalm-var string $primaryKeyValue */
182+
/** @phpstan-var string $primaryKeyValue */
185183
return sprintf('%s %s #%s', $actionName, $controllerName, $primaryKeyValue);
186184
}
187185

188-
/** @psalm-var string $primaryKeyValue */
186+
/** @phpstan-var string $primaryKeyValue */
189187
return sprintf('%s %s #%s: %s', $actionName, $controllerName, $primaryKeyValue, $displayFieldValue);
190188
}
191189

@@ -410,9 +408,7 @@ protected function _getControllerActions(): array
410408
}
411409

412410
foreach ($actionBlacklist as $actionName) {
413-
/** @psalm-suppress EmptyArrayAccess */
414411
unset($table[$actionName]);
415-
/** @psalm-suppress EmptyArrayAccess */
416412
unset($entity[$actionName]);
417413
}
418414

@@ -440,7 +436,6 @@ protected function _getControllerActionConfiguration(string $actionName, array $
440436
if ($this->_crud()->isActionMapped($realAction)) {
441437
$action = $this->_action($realAction);
442438
$class = get_class($action);
443-
/** @psalm-suppress PossiblyFalseOperand */
444439
$class = substr($class, strrpos($class, '\\') + 1);
445440

446441
if ($class === 'DeleteAction') {
@@ -591,7 +586,6 @@ protected function _primaryKeyValue(): array|string|int|null
591586
*/
592587
protected function _displayFieldValue(): string|int|null
593588
{
594-
/** @psalm-suppress PossiblyInvalidArgument */
595589
return $this->_deriveFieldFromContext($this->_model()->getDisplayField());
596590
}
597591

src/Listener/ViewSearchListener.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ public function fields(): array
144144
$input['class'] = 'autocomplete';
145145
}
146146

147-
/** @psalm-suppress PossiblyUndefinedArrayOffset */
148147
if (
149148
!empty($input['class'])
150149
&& strpos($input['class'], 'autocomplete') !== false
@@ -156,7 +155,6 @@ public function fields(): array
156155
$input['options'][$input['value']] = $input['value'];
157156
}
158157

159-
/** @psalm-suppress PossiblyInvalidOperand */
160158
$input += [
161159
'data-input-type' => 'text',
162160
'data-tags' => 'true',

src/View/Cell/TablesListCell.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public function display(?array $tables = null, ?array $blacklist = null): void
2525
$tables = $schema->listTables();
2626
sort($tables);
2727

28-
/** @psalm-suppress RiskyTruthyFalsyComparison */
2928
if (!empty($blacklist)) {
3029
$tables = array_diff($tables, $blacklist);
3130
}

src/View/Helper/CrudViewHelper.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ public function introspect(string $field, mixed $value, array $options = []): ar
155155

156156
$fieldFormatters = $this->getConfig('fieldFormatters');
157157
if (isset($fieldFormatters[$type])) {
158-
/** @psalm-suppress PossiblyNullArrayOffset */
159158
if (is_callable($fieldFormatters[$type])) {
160159
return $fieldFormatters[$type](
161160
$field,
@@ -166,7 +165,6 @@ public function introspect(string $field, mixed $value, array $options = []): ar
166165
);
167166
}
168167

169-
/** @psalm-suppress PossiblyNullArrayOffset */
170168
return $this->{$fieldFormatters[$type]}($field, $value, $options);
171169
}
172170

src/View/Widget/DateTimeWidget.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ public function render(array $data, ContextInterface $context): string
111111

112112
$clearIcon = $this->clearIcon;
113113
$toggleIcon = $this->calendarIcon;
114-
/** @psalm-suppress PossiblyUndefinedArrayOffset */
115114
if (isset($datetimePicker['iconClass'])) {
116115
$toggleIcon = $datetimePicker['iconClass'];
117116
unset($datetimePicker['iconClass']);
@@ -155,7 +154,6 @@ public function render(array $data, ContextInterface $context): string
155154
return $input;
156155
}
157156

158-
/** @psalm-suppress PossiblyInvalidArrayOffset */
159157
return $this->_templates->format('datetimePicker', [
160158
'input' => $input,
161159
'toggleIcon' => $toggleIcon,

templates/element/action-groups.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@
1515
?>
1616

1717
<?php foreach ($groups as $key => $group) : ?>
18+
<?php
19+
if (count($group) === 1) {
20+
$subaction = key($group);
21+
if (is_numeric($subaction)) {
22+
$subaction = $group[$subaction];
23+
}
24+
25+
echo $this->element('action-button', ['config' => $links[$subaction]]);
26+
continue;
27+
}
28+
?>
1829
<div class='btn-group' role="group">
1930
<button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
2031
<?= $key ?>

0 commit comments

Comments
 (0)