Skip to content

Commit 5add649

Browse files
authored
Merge pull request #9 from yokai-php/menu-translation-handling
Reworked the way menu labels are built
2 parents b610c43 + 371e860 commit 5add649

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

.travis.yml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,20 @@ php:
44
- 7.0
55
- 7.1
66
- 7.2
7+
- 7.3
78

89
env:
9-
- SYMFONY_VERSION="3.3.*"
1010
- SYMFONY_VERSION="3.4.*"
11-
- SYMFONY_VERSION="4.0.*"
12-
- SYMFONY_VERSION="4.1.*"
13-
- SYMFONY_VERSION="4.2.x-dev"
11+
- SYMFONY_VERSION="4.2.*"
12+
- SYMFONY_VERSION="4.3.*"
1413

1514
matrix:
1615
exclude:
1716
# Symfony >= 4.0 PHP requirement is ^7.1.3
1817
- php: 7.0
19-
env: SYMFONY_VERSION="4.0.*"
18+
env: SYMFONY_VERSION="4.2.*"
2019
- php: 7.0
21-
env: SYMFONY_VERSION="4.1.*"
22-
- php: 7.0
23-
env: SYMFONY_VERSION="4.2.x-dev"
20+
env: SYMFONY_VERSION="4.3.*"
2421

2522
sudo: false
2623

@@ -29,10 +26,10 @@ cache:
2926
- $HOME/.composer/cache
3027

3128
before_install:
32-
- composer selfupdate
29+
- rm -rf composer.lock vendor/
3330
- if [ "$SYMFONY_VERSION" != "" ]; then composer require "symfony/workflow:${SYMFONY_VERSION}" --no-update; fi;
3431

35-
install: composer update --prefer-dist --no-interaction $COMPOSER_FLAGS
32+
install: COMPOSER_MEMORY_LIMIT=-1 travis_retry composer install --prefer-dist --no-interaction
3633

3734
script:
3835
- vendor/bin/phpunit --coverage-clover=build/coverage/clover.xml

src/Admin/Extension/WorkflowExtension.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function configureSideMenu(
9090
$transitions = $workflow->getEnabledTransitions($subject);
9191

9292
if (count($transitions) === 0) {
93-
$this->noTransitions($menu);
93+
$this->noTransitions($menu, $admin);
9494
} else {
9595
$this->transitionsDropdown($menu, $admin, $transitions, $subject);
9696
}
@@ -139,15 +139,19 @@ protected function configureOptions(OptionsResolver $resolver)
139139

140140
/**
141141
* @param MenuItemInterface $menu
142+
* @param AdminInterface $admin
142143
*/
143-
protected function noTransitions(MenuItemInterface $menu)
144+
protected function noTransitions(MenuItemInterface $menu, AdminInterface $admin)
144145
{
145146
if ($this->options['no_transition_display']) {
146147
$menu->addChild($this->options['no_transition_label'], [
147148
'uri' => '#',
148149
'attributes' => [
149150
'icon' => $this->options['no_transition_icon'],
150151
],
152+
'extras' => [
153+
'translation_domain' => $admin->getTranslationDomain(),
154+
],
151155
]);
152156
}
153157
}
@@ -165,6 +169,9 @@ protected function transitionsDropdown(MenuItemInterface $menu, AdminInterface $
165169
'dropdown' => true,
166170
'icon' => $this->options['dropdown_transitions_icon'],
167171
],
172+
'extras' => [
173+
'translation_domain' => $admin->getTranslationDomain(),
174+
],
168175
]);
169176

170177
foreach ($transitions as $transition) {
@@ -183,14 +190,17 @@ protected function transitionsItem(MenuItemInterface $menu, AdminInterface $admi
183190
$options = [
184191
'uri' => $this->generateTransitionUri($admin, $transition, $subject),
185192
'attributes' => [],
193+
'extras' => [
194+
'translation_domain' => $admin->getTranslationDomain(),
195+
],
186196
];
187197

188198
if ($icon = $this->getTransitionIcon($transition)) {
189199
$options['attributes']['icon'] = $icon;
190200
}
191201

192202
$menu->addChild(
193-
$admin->getLabelTranslatorStrategy()->getLabel($transition->getName(), 'workflow'),
203+
$admin->getLabelTranslatorStrategy()->getLabel($transition->getName(), 'workflow', 'transition'),
194204
$options
195205
);
196206
}

tests/Admin/Extension/WorkflowExtensionTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Symfony\Component\Routing\Route;
1212
use Symfony\Component\Workflow\Registry;
1313
use Symfony\Component\Workflow\StateMachine;
14-
use Symfony\Component\Workflow\SupportStrategy\InstanceOfSupportStrategy;
1514
use Yokai\SonataWorkflow\Admin\Extension\WorkflowExtension;
1615
use Yokai\SonataWorkflow\Controller\WorkflowController;
1716
use Yokai\SonataWorkflow\Tests\PullRequest;
@@ -106,13 +105,14 @@ public function testConfigureSideMenu($marking, array $transitions)
106105

107106
/** @var AdminInterface|ObjectProphecy $admin */
108107
$admin = $this->prophesize(AdminInterface::class);
108+
$admin->getTranslationDomain()->willReturn('admin');
109109
$admin->getLabelTranslatorStrategy()->willReturn($labelStrategy->reveal());
110110
$admin->getSubject()->willReturn($pullRequest);
111111

112112
foreach ($transitions as $transition) {
113-
$labelStrategy->getLabel($transition, 'workflow')
113+
$labelStrategy->getLabel($transition, 'workflow', 'transition')
114114
->shouldBeCalledTimes(1)
115-
->willReturn('transition.'.$transition);
115+
->willReturn('workflow.transition.'.$transition);
116116
$admin->generateObjectUrl('workflow_apply_transition', $pullRequest, ['transition' => $transition])
117117
->shouldBeCalledTimes(1)
118118
->willReturn('/pull-request/42/workflow/transition/'.$transition.'/apply');
@@ -135,11 +135,13 @@ public function testConfigureSideMenu($marking, array $transitions)
135135
self::assertNull($child = $menu->getChild('workflow_transitions'));
136136
self::assertNotNull($child = $menu->getChild('workflow_transitions_empty'));
137137
self::assertSame('#', $child->getUri());
138+
self::assertSame('admin', $child->getExtra('translation_domain'));
138139
self::assertFalse($child->hasChildren());
139140
self::assertEmpty($child->getChildren());
140141
} else {
141142
self::assertNull($child = $menu->getChild('workflow_transitions_empty'));
142143
self::assertNotNull($child = $menu->getChild('workflow_transitions'));
144+
self::assertSame('admin', $child->getExtra('translation_domain'));
143145
self::assertTrue($child->getAttribute('dropdown'));
144146
self::assertSame('fa fa-code-fork', $child->getAttribute('icon'));
145147
self::assertTrue($child->hasChildren());
@@ -150,8 +152,9 @@ public function testConfigureSideMenu($marking, array $transitions)
150152
$icon = 'fa fa-times';
151153
}
152154

153-
self::assertNotNull($item = $child->getChild('transition.'.$transition));
155+
self::assertNotNull($item = $child->getChild('workflow.transition.'.$transition));
154156
self::assertSame('/pull-request/42/workflow/transition/'.$transition.'/apply', $item->getUri());
157+
self::assertSame('admin', $item->getExtra('translation_domain'));
155158
self::assertSame($icon, $item->getAttribute('icon'));
156159
}
157160
}

0 commit comments

Comments
 (0)