Skip to content

Commit c85885b

Browse files
committed
MAGETWO-64557: User can change the Interface Locale only to locales that are already deployed
1 parent 136f6b1 commit c85885b

File tree

6 files changed

+19
-27
lines changed

6 files changed

+19
-27
lines changed

app/code/Magento/Backend/Block/System/Account/Edit/Form.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace Magento\Backend\Block\System\Account\Edit;
77

88
use Magento\Framework\App\ObjectManager;
9-
use Magento\Framework\Locale\Deployed\OptionInterface;
9+
use Magento\Framework\Locale\OptionInterface;
1010

1111
/**
1212
* Adminhtml edit admin user account form
@@ -135,7 +135,7 @@ protected function _prepareForm()
135135
'name' => 'interface_locale',
136136
'label' => __('Interface Locale'),
137137
'title' => __('Interface Locale'),
138-
'values' => $this->deployedLocales->getTranslatedLocales(),
138+
'values' => $this->deployedLocales->getTranslatedOptionLocales(),
139139
'class' => 'select'
140140
]
141141
);

app/code/Magento/User/Block/User/Edit/Tab/Main.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace Magento\User\Block\User\Edit\Tab;
1010

1111
use Magento\Framework\App\ObjectManager;
12-
use Magento\Framework\Locale\Deployed\OptionInterface;
12+
use Magento\Framework\Locale\OptionInterface;
1313

1414
/**
1515
* Cms page edit form main tab
@@ -152,7 +152,7 @@ protected function _prepareForm()
152152
'name' => 'interface_locale',
153153
'label' => __('Interface Locale'),
154154
'title' => __('Interface Locale'),
155-
'values' => $this->deployedLocales->getLocales(),
155+
'values' => $this->deployedLocales->getOptionLocales(),
156156
'class' => 'select'
157157
]
158158
);

app/etc/di.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<preference for="Magento\Framework\View\Asset\Bundle\ConfigInterface" type="\Magento\Framework\View\Asset\Bundle\Config" />
3636
<preference for="Magento\Framework\Locale\ListsInterface" type="Magento\Framework\Locale\TranslatedLists" />
3737
<preference for="Magento\Framework\Locale\AvailableLocalesInterface" type="Magento\Framework\Locale\Deployed\Codes" />
38-
<preference for="Magento\Framework\Locale\Deployed\OptionInterface" type="Magento\Framework\Locale\Deployed\Options" />
38+
<preference for="Magento\Framework\Locale\OptionInterface" type="Magento\Framework\Locale\Deployed\Options" />
3939
<preference for="Magento\Framework\Api\AttributeTypeResolverInterface" type="Magento\Framework\Reflection\AttributeTypeResolver" />
4040
<preference for="Magento\Framework\Api\Search\SearchResultInterface" type="Magento\Framework\Api\Search\SearchResult" />
4141
<preference for="Magento\Framework\Api\Search\SearchCriteriaInterface" type="Magento\Framework\Api\Search\SearchCriteria"/>

lib/internal/Magento/Framework/Locale/Deployed/Options.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
namespace Magento\Framework\Locale\Deployed;
77

88
use Magento\Framework\App\State;
9+
use Magento\Framework\Exception\LocalizedException;
910
use Magento\Framework\Locale\AvailableLocalesInterface;
1011
use Magento\Framework\Locale\ListsInterface;
12+
use Magento\Framework\Locale\OptionInterface;
1113
use Magento\Framework\View\DesignInterface;
1214

1315
/**
@@ -64,15 +66,15 @@ public function __construct(
6466
/**
6567
* {@inheritdoc}
6668
*/
67-
public function getLocales()
69+
public function getOptionLocales()
6870
{
6971
return $this->filterLocales($this->localeLists->getOptionLocales());
7072
}
7173

7274
/**
7375
* {@inheritdoc}
7476
*/
75-
public function getTranslatedLocales()
77+
public function getTranslatedOptionLocales()
7678
{
7779
return $this->filterLocales($this->localeLists->getTranslatedOptionLocales());
7880
}
@@ -118,7 +120,11 @@ private function filterLocales(array $locales)
118120
}
119121

120122
$theme = $this->design->getDesignTheme();
121-
$availableLocales = $this->availableLocales->getList($theme->getCode(), $theme->getArea());
123+
try {
124+
$availableLocales = $this->availableLocales->getList($theme->getCode(), $theme->getArea());
125+
} catch (LocalizedException $e) {
126+
$availableLocales = [];
127+
}
122128

123129
return array_filter($locales, function ($localeData) use ($availableLocales) {
124130
return in_array($localeData['value'], $availableLocales);

lib/internal/Magento/Framework/Locale/ListsInterface.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,8 @@
55
*/
66
namespace Magento\Framework\Locale;
77

8-
interface ListsInterface
8+
interface ListsInterface extends OptionInterface
99
{
10-
/**
11-
* Get options array for locale dropdown in current locale
12-
*
13-
* @return array
14-
*/
15-
public function getOptionLocales();
16-
17-
/**
18-
* Get translated to original locale options array for locale dropdown
19-
*
20-
* @return array
21-
*/
22-
public function getTranslatedOptionLocales();
23-
2410
/**
2511
* Retrieve timezone option list
2612
*

lib/internal/Magento/Framework/Locale/Deployed/OptionInterface.php renamed to lib/internal/Magento/Framework/Locale/OptionInterface.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
namespace Magento\Framework\Locale\Deployed;
6+
namespace Magento\Framework\Locale;
77

88
/**
9-
* Interface for classes that returning array of deployed locales.
9+
* Interface for classes that return array of locales.
1010
*/
1111
interface OptionInterface
1212
{
@@ -29,7 +29,7 @@ interface OptionInterface
2929
*
3030
* @return array
3131
*/
32-
public function getLocales();
32+
public function getOptionLocales();
3333

3434
/**
3535
* Get array of deployed locales with translation.
@@ -50,5 +50,5 @@ public function getLocales();
5050
*
5151
* @return array
5252
*/
53-
public function getTranslatedLocales();
53+
public function getTranslatedOptionLocales();
5454
}

0 commit comments

Comments
 (0)