summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoreffulgentsia2015-10-04 02:55:25 (GMT)
committereffulgentsia2015-10-04 02:55:25 (GMT)
commit6a175c39a128a72a5ed7126b1bc70daef2ed0964 (patch)
tree3e44e0ba8890563cc0a9d594262e7a07db5fa3ea
parentb827bda3d1b23b424534716cb1a0b38e5157c6b7 (diff)
Issue #2571655 by jan.stoeckler, maxocub, tstoeckler: ConfigNamesMapper::hasTranslatable has flawed logic
-rw-r--r--core/modules/config_translation/src/Access/ConfigTranslationFormAccess.php6
-rw-r--r--core/modules/config_translation/src/Access/ConfigTranslationOverviewAccess.php11
-rw-r--r--core/modules/config_translation/src/ConfigMapperInterface.php6
-rw-r--r--core/modules/config_translation/src/ConfigNamesMapper.php6
-rw-r--r--core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php2
-rw-r--r--core/modules/config_translation/tests/src/Unit/ConfigNamesMapperTest.php6
6 files changed, 21 insertions, 16 deletions
diff --git a/core/modules/config_translation/src/Access/ConfigTranslationFormAccess.php b/core/modules/config_translation/src/Access/ConfigTranslationFormAccess.php
index d7baae3..af584de 100644
--- a/core/modules/config_translation/src/Access/ConfigTranslationFormAccess.php
+++ b/core/modules/config_translation/src/Access/ConfigTranslationFormAccess.php
@@ -8,8 +8,8 @@
namespace Drupal\config_translation\Access;
use Drupal\Core\Access\AccessResult;
+use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountInterface;
-use Symfony\Component\Routing\Route;
/**
* Checks access for displaying the translation add, edit, and delete forms.
@@ -19,10 +19,10 @@ class ConfigTranslationFormAccess extends ConfigTranslationOverviewAccess {
/**
* {@inheritdoc}
*/
- public function access(Route $route, AccountInterface $account, $langcode = NULL) {
+ public function access(RouteMatchInterface $route_match, AccountInterface $account, $langcode = NULL) {
// For the translation forms we have a target language, so we need some
// checks in addition to the checks performed for the translation overview.
- $base_access = parent::access($route, $account);
+ $base_access = parent::access($route_match, $account);
if ($base_access->isAllowed()) {
$target_language = $this->languageManager->getLanguage($langcode);
diff --git a/core/modules/config_translation/src/Access/ConfigTranslationOverviewAccess.php b/core/modules/config_translation/src/Access/ConfigTranslationOverviewAccess.php
index 237e89a..ec588bb 100644
--- a/core/modules/config_translation/src/Access/ConfigTranslationOverviewAccess.php
+++ b/core/modules/config_translation/src/Access/ConfigTranslationOverviewAccess.php
@@ -11,8 +11,8 @@ use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\config_translation\ConfigMapperManagerInterface;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Routing\Access\AccessInterface;
+use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountInterface;
-use Symfony\Component\Routing\Route;
/**
* Checks access for displaying the configuration translation overview.
@@ -54,17 +54,20 @@ class ConfigTranslationOverviewAccess implements AccessInterface {
/**
* Checks access to the overview based on permissions and translatability.
*
- * @param \Symfony\Component\Routing\Route $route
- * The route to check against.
+ * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
+ * The route_match to check against.
* @param \Drupal\Core\Session\AccountInterface $account
* The currently logged in account.
*
* @return \Drupal\Core\Access\AccessResultInterface
* The access result.
*/
- public function access(Route $route, AccountInterface $account) {
+ public function access(RouteMatchInterface $route_match, AccountInterface $account) {
+ $route = $route_match->getRouteObject();
+
/** @var \Drupal\config_translation\ConfigMapperInterface $mapper */
$mapper = $this->configMapperManager->createInstance($route->getDefault('plugin_id'));
+ $mapper->populateFromRouteMatch($route_match);
$this->sourceLanguage = $this->languageManager->getLanguage($mapper->getLangcode());
// Allow access to the translation overview if the proper permission is
diff --git a/core/modules/config_translation/src/ConfigMapperInterface.php b/core/modules/config_translation/src/ConfigMapperInterface.php
index 9815f85..90d405a 100644
--- a/core/modules/config_translation/src/ConfigMapperInterface.php
+++ b/core/modules/config_translation/src/ConfigMapperInterface.php
@@ -253,11 +253,11 @@ interface ConfigMapperInterface {
public function hasSchema();
/**
- * Checks that all pieces of this configuration mapper have translatables.
+ * Checks if pieces of this configuration mapper have translatables.
*
* @return bool
- * TRUE if all of the configuration elements have translatables, FALSE
- * otherwise.
+ * TRUE if at least one of the configuration elements has translatables,
+ * FALSE otherwise.
*/
public function hasTranslatable();
diff --git a/core/modules/config_translation/src/ConfigNamesMapper.php b/core/modules/config_translation/src/ConfigNamesMapper.php
index 6a51be6..4d98e2a 100644
--- a/core/modules/config_translation/src/ConfigNamesMapper.php
+++ b/core/modules/config_translation/src/ConfigNamesMapper.php
@@ -438,11 +438,11 @@ class ConfigNamesMapper extends PluginBase implements ConfigMapperInterface, Con
*/
public function hasTranslatable() {
foreach ($this->getConfigNames() as $name) {
- if (!$this->configMapperManager->hasTranslatable($name)) {
- return FALSE;
+ if ($this->configMapperManager->hasTranslatable($name)) {
+ return TRUE;
}
}
- return TRUE;
+ return FALSE;
}
/**
diff --git a/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php b/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php
index a359c9f..c565e8c 100644
--- a/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php
+++ b/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php
@@ -660,7 +660,7 @@ class ConfigTranslationUiTest extends WebTestBase {
$config->save();
// Go to the translation page of the 'files' view.
- $translation_url = 'admin/structure/views/view/files/translate/' . $langcode . '/add';
+ $translation_url = 'admin/structure/views/view/files/translate/en/add';
$this->drupalGet($translation_url);
// Check if the expected number of source elements are present.
diff --git a/core/modules/config_translation/tests/src/Unit/ConfigNamesMapperTest.php b/core/modules/config_translation/tests/src/Unit/ConfigNamesMapperTest.php
index 9ecc32b..0223c6f 100644
--- a/core/modules/config_translation/tests/src/Unit/ConfigNamesMapperTest.php
+++ b/core/modules/config_translation/tests/src/Unit/ConfigNamesMapperTest.php
@@ -538,7 +538,7 @@ class ConfigNamesMapperTest extends UnitTestCase {
$map = array();
foreach ($config_names as $i => $config_name) {
- $map[] = array($config_name, $mock_return_values[$i]);
+ $map[] = isset($mock_return_values[$i]) ? array($config_name, $mock_return_values[$i]) : array();
}
$this->configMapperManager
->expects($this->any())
@@ -560,10 +560,12 @@ class ConfigNamesMapperTest extends UnitTestCase {
*/
public function providerTestHasTranslatable() {
return array(
+ array(array(), FALSE),
array(array(TRUE), TRUE),
array(array(FALSE), FALSE),
array(array(TRUE, TRUE, TRUE), TRUE),
- array(array(TRUE, FALSE, TRUE), FALSE),
+ array(array(FALSE, FALSE, FALSE), FALSE),
+ array(array(TRUE, FALSE, TRUE), TRUE),
);
}