@@ -63,27 +63,34 @@ protected function generate(array &$vars): void {
6363
6464 /** @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface $bundle_info */
6565 $ bundle_info = $ this ->drupalContext ->getContainer ()->get ('entity_type.bundle.info ' );
66- $ bundle_choices = \array_map (
66+ $ bundles = \array_map (
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 = ['' => '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. " );
70+
71+ // Skip the question when only 1 bundle exists.
72+ if (\count ($ bundles ) === 1 ) {
73+ $ vars ['bundle_ids ' ] = \array_keys ($ bundles );
74+ }
75+ else {
76+ // Prepend an 'All' choice for user's convenience.
77+ $ bundle_choices = ['' => 'All ' ] + $ bundles ;
78+ $ vars ['bundle_ids ' ] = $ this ->choice ('Bundles, comma separated ' , $ bundle_choices , NULL , TRUE );
79+ if (\in_array ('' , $ vars ['bundle_ids ' ])) {
80+ if (\count ($ vars ['bundle_ids ' ]) >= 2 ) {
81+ throw new \UnexpectedValueException ("'All' may not be combined with other choices. " );
82+ }
83+ // Replace 'all' with all bundle IDs.
84+ $ vars ['bundle_ids ' ] = \array_keys ($ bundles );
7685 }
77- // Replace 'all' with all bundle IDs.
78- $ vars ['bundle_ids ' ] = \array_keys ($ bundle_choices );
7986 }
8087
8188 $ vars ['classes ' ] = [];
8289 $ vars ['classes_fqn ' ] = [];
8390 foreach ($ vars ['bundle_ids ' ] as $ bundle_id ) {
8491 $ vars ['bundle_id ' ] = $ bundle_id ;
8592 $ vars ['class ' ] = $ this ->ask (
86- \sprintf ('Class for %s bundle ' , $ bundle_choices [$ bundle_id ]),
93+ \sprintf ('Class for %s bundle ' , $ bundles [$ bundle_id ]),
8794 '{bundle_id|camelize}Bundle ' ,
8895 );
8996 $ vars ['class_fqn ' ] = '\\' . $ vars ['namespace ' ] . '\\' . $ vars ['class ' ];
0 commit comments