Skip to content

Commit

Permalink
Merge pull request #4631 from lightglitch/patch-1
Browse files Browse the repository at this point in the history
Fix group menu sub items translation domain
  • Loading branch information
OskarStark committed Aug 29, 2017
2 parents 3b0357b + cf5de6f commit defe230
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Menu/Provider/GroupMenuProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function get($name, array $options = array())
$label = $admin->getLabel();
$options = $admin->generateMenuUrl('list', array(), $item['route_absolute']);
$options['extras'] = array(
'translation_domain' => $admin->getTranslationDomain(),
'label_catalogue' => $admin->getTranslationDomain(),
'admin' => $admin,
);
} else {
Expand All @@ -128,7 +128,7 @@ public function get($name, array $options = array())
'routeParameters' => $item['route_params'],
'routeAbsolute' => $item['route_absolute'],
'extras' => array(
'translation_domain' => $group['label_catalogue'],
'label_catalogue' => $group['label_catalogue'],
),
);
}
Expand Down
3 changes: 1 addition & 2 deletions Resources/views/Menu/sonata_menu.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@

{% block linkElement %}
{% spaceless %}
{% set translation_domain = item.extra('label_catalogue', 'messages') %}
{% if item.extra('on_top') is defined and not item.extra('on_top') %}
{% set translation_domain = item.extra('translation_domain', 'messages') %}
{% set icon = item.extra('icon')|default(item.level > 1 ? '<i class="fa fa-angle-double-right" aria-hidden="true"></i>' : '') %}
{% else %}
{% set translation_domain = item.extra('label_catalogue', 'messages') %}
{% set icon = item.extra('icon') %}
{% endif %}
{% set is_link = true %}
Expand Down
24 changes: 24 additions & 0 deletions Tests/Menu/Provider/GroupMenuProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ public function testGroupMenuProviderWithoutChecker(array $adminGroups)
$this->assertArrayHasKey('route_label', $children);
$this->assertInstanceOf('Knp\Menu\MenuItem', $menu['foo_admin_label']);
$this->assertSame('foo_admin_label', $menu['foo_admin_label']->getLabel());

$extras = $menu['foo_admin_label']->getExtras();
$this->assertArrayHasKey('label_catalogue', $extras);
$this->assertSame($extras['label_catalogue'], 'SonataAdminBundle');

$extras = $menu['route_label']->getExtras();
$this->assertArrayHasKey('label_catalogue', $extras);
$this->assertSame($extras['label_catalogue'], 'SonataAdminBundle');
}

/**
Expand Down Expand Up @@ -141,6 +149,10 @@ public function testGetMenuProviderWithCheckerGrantedGroupRoles(array $adminGrou
$this->assertArrayNotHasKey('route_label', $children);
$this->assertInstanceOf('Knp\Menu\MenuItem', $menu['foo_admin_label']);
$this->assertSame('foo_admin_label', $menu['foo_admin_label']->getLabel());

$extras = $menu['foo_admin_label']->getExtras();
$this->assertArrayHasKey('label_catalogue', $extras);
$this->assertSame($extras['label_catalogue'], 'SonataAdminBundle');
}

/**
Expand Down Expand Up @@ -177,6 +189,14 @@ public function testGetMenuProviderWithAdmin(array $adminGroups)
$this->assertArrayHasKey('route_label', $children);
$this->assertInstanceOf('Knp\Menu\MenuItem', $menu['foo_admin_label']);
$this->assertSame('foo_admin_label', $menu['foo_admin_label']->getLabel());

$extras = $menu['foo_admin_label']->getExtras();
$this->assertArrayHasKey('label_catalogue', $extras);
$this->assertSame($extras['label_catalogue'], 'SonataAdminBundle');

$extras = $menu['route_label']->getExtras();
$this->assertArrayHasKey('label_catalogue', $extras);
$this->assertSame($extras['label_catalogue'], 'SonataAdminBundle');
}

/**
Expand Down Expand Up @@ -381,6 +401,10 @@ private function getAdminMock($hasRoute = true, $isGranted = true)
->method('generateMenuUrl')
->will($this->returnValue(array()));

$admin->expects($this->any())
->method('getTranslationDomain')
->will($this->returnValue('SonataAdminBundle'));

return $admin;
}
}

0 comments on commit defe230

Please sign in to comment.