Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
17 / 17 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| OptionsComponentProvider | |
100.00% |
17 / 17 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| supports | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| createComponentFor | |
100.00% |
15 / 15 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | namespace Apie\HtmlBuilders\Factories\Concrete; |
| 3 | |
| 4 | use Apie\Core\Attributes\CmsSingleInput; |
| 5 | use Apie\Core\Dto\CmsInputOption; |
| 6 | use Apie\Core\Metadata\MetadataFactory; |
| 7 | use Apie\HtmlBuilders\Components\Forms\SingleInput; |
| 8 | use Apie\HtmlBuilders\FormBuildContext; |
| 9 | use Apie\HtmlBuilders\Interfaces\ComponentInterface; |
| 10 | use Apie\HtmlBuilders\Interfaces\FormComponentProviderInterface; |
| 11 | use ReflectionType; |
| 12 | |
| 13 | class OptionsComponentProvider implements FormComponentProviderInterface |
| 14 | { |
| 15 | public function supports(ReflectionType $type, FormBuildContext $context): bool |
| 16 | { |
| 17 | $metadata = MetadataFactory::getCreationMetadata($type, $context->getApieContext()); |
| 18 | return !empty($metadata->getValueOptions($context->getApieContext(), true)?->toArray()); |
| 19 | } |
| 20 | |
| 21 | public function createComponentFor(ReflectionType $type, FormBuildContext $context): ComponentInterface |
| 22 | { |
| 23 | $options = MetadataFactory::getCreationMetadata($type, $context->getApieContext()) |
| 24 | ->getValueOptions($context->getApieContext(), true); |
| 25 | return new SingleInput( |
| 26 | $context->getFormName(), |
| 27 | $context->getFilledInValue(), |
| 28 | $context->createTranslationLabel(), |
| 29 | $type->allowsNull(), |
| 30 | $type, |
| 31 | new CmsSingleInput( |
| 32 | ['select'], |
| 33 | new CmsInputOption( |
| 34 | options: $options |
| 35 | ) |
| 36 | ) |
| 37 | ); |
| 38 | } |
| 39 | } |