Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
15 / 15 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| ResourceModifyResourceHeader | |
100.00% |
15 / 15 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| getFallbackText | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
| createFromDefinition | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | namespace Apie\Core\Translator\ValueObjects; |
| 3 | |
| 4 | use Apie\Common\ActionDefinitions\ModifyResourceActionDefinition; |
| 5 | use Apie\Core\Attributes\Description; |
| 6 | use Apie\Core\Attributes\ExampleValue; |
| 7 | use Apie\Core\Identifiers\SnakeCaseSlug; |
| 8 | use Apie\Core\Lists\ItemHashmap; |
| 9 | |
| 10 | #[Description('Header shown on edit resource button')] |
| 11 | #[ExampleValue('apie.bounded.test.example.user.action.edit.:id.header.authenticated')] |
| 12 | class ResourceModifyResourceHeader extends AbstractTranslation |
| 13 | { |
| 14 | protected const MIDDLE_REGEX = 'action\.edit\.:id\.header'; |
| 15 | |
| 16 | public function getFallbackText(): string |
| 17 | { |
| 18 | $resourceId = $this->getPlaceholders()['id'] ?? null; |
| 19 | $suffix = $resourceId ? (' ' . $resourceId) : ''; |
| 20 | |
| 21 | $id = $this->prefix->getResourceIdentifier(); |
| 22 | if ($id) { |
| 23 | return 'Edit ' . $id->humanize() . $suffix; |
| 24 | } |
| 25 | return 'Edit' . $suffix; |
| 26 | } |
| 27 | |
| 28 | public static function createFromDefinition(ModifyResourceActionDefinition $actionDefinition, ?bool $authenticated): static |
| 29 | { |
| 30 | return new static( |
| 31 | new TranslationStringPrefix( |
| 32 | $actionDefinition->getBoundedContextId(), |
| 33 | SnakeCaseSlug::fromClass($actionDefinition->getResourceName()) |
| 34 | ), |
| 35 | 'action.edit.:id.header', |
| 36 | new TranslationStringSuffix(null, $authenticated), |
| 37 | new ItemHashmap() |
| 38 | ); |
| 39 | } |
| 40 | } |