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