Commit 6a175c39 authored by effulgentsia's avatar effulgentsia

Issue #2571655 by jan.stoeckler, maxocub, tstoeckler:...

Issue #2571655 by jan.stoeckler, maxocub, tstoeckler: ConfigNamesMapper::hasTranslatable has flawed logic
parent b827bda3
......@@ -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);
......
......@@ -11,8 +11,8 @@
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 @@ public function __construct(ConfigMapperManagerInterface $config_mapper_manager,
/**
* 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
......
......@@ -253,11 +253,11 @@ public function getTypeLabel();
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();
......
......@@ -438,11 +438,11 @@ public function hasSchema() {
*/
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;
}
/**
......
......@@ -660,7 +660,7 @@ public function testPluralConfigStringsSourceElements() {
$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.
......
......@@ -538,7 +538,7 @@ public function testHasTranslatable(array $mock_return_values, $expected) {
$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 @@ public function testHasTranslatable(array $mock_return_values, $expected) {
*/
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),
);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment