Skip to content

Commit 9afd6d5

Browse files
authored
Merge pull request #79 from weitzman/bundle-class-all
Add 'All' choice for bundle selection in bundle class generator
2 parents bb87c0e + 8936189 commit 9afd6d5

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/Command/Entity/EntityBundleClass.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,16 @@ 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-
$vars['bundle_ids'] = $this->choice('Bundles, comma separated', $bundle_choices, NULL, TRUE);
70+
// Prepend an 'All' choice for user's convenience.
71+
$bundle_choices_all = ['' => 'All'] + $bundle_choices;
72+
$vars['bundle_ids'] = $this->choice('Bundles, comma separated', $bundle_choices_all, NULL, TRUE);
73+
if (\in_array('', $vars['bundle_ids'])) {
74+
if (\count($vars['bundle_ids']) >= 2) {
75+
throw new \UnexpectedValueException("'All' may not be combined with other choices.");
76+
}
77+
// Replace 'all' with all bundle IDs.
78+
$vars['bundle_ids'] = \array_keys($bundle_choices);
79+
}
7180

7281
$vars['classes'] = [];
7382
$vars['classes_fqn'] = [];

0 commit comments

Comments
 (0)