Skip to content

Commit d169fca

Browse files
committed
Add 'All' choice for bundle selection in bundle class generator
1 parent bb87c0e commit d169fca

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/Command/Entity/EntityBundleClass.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,18 @@ protected function generate(array &$vars): void {
6767
static fn (array $bundle): string => (string) $bundle['label'],
6868
$bundle_info->getBundleInfo($vars['entity_type_id']),
6969
);
70+
// Prepend an 'All' choice for user's convenience.
71+
$bundle_choices_all = array_merge(['all' => 'All'], $bundle_choices);
7072
$vars['bundle_ids'] = $this->choice('Bundles, comma separated', $bundle_choices, NULL, TRUE);
7173

74+
if (in_array('all', $vars['bundle_ids']) && count($vars['bundle_ids']) >= 2) {
75+
throw new \UnexpectedValueException("'All' may not be combined with other choices.");
76+
}
77+
if (in_array('all', $vars['bundle_ids'])) {
78+
// Replace 'all' with all bundle IDs.
79+
$vars['bundle_ids'] = array_keys($bundle_choices);
80+
}
81+
7282
$vars['classes'] = [];
7383
$vars['classes_fqn'] = [];
7484
foreach ($vars['bundle_ids'] as $bundle_id) {

0 commit comments

Comments
 (0)