diff --git a/core/includes/update.inc b/core/includes/update.inc index 9a4606e37d401a2627cda471dbbf86ded666d65f..d31f994e3b8a959d78d457e6e71a4cbfa458fb1d 100644 --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -751,9 +751,9 @@ function update_language_list($flags = LanguageInterface::STATE_CONFIGURABLE) { } foreach ($languages as $langcode => $language) { - if (($language->locked && !($flags & LanguageInterface::STATE_LOCKED)) || (!$language->locked && !($flags & LanguageInterface::STATE_CONFIGURABLE))) { + if (($language->isLocked() && !($flags & LanguageInterface::STATE_LOCKED)) || (!$language->isLocked() && !($flags & LanguageInterface::STATE_CONFIGURABLE))) { continue; - } + } $filtered_languages[$langcode] = $language; } diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php index 02c290612eabcaf57de9e46d085e20e6287ef9e9..636c00b7d96c3cc8ff5d459b287b49e68c87b0e6 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php @@ -241,7 +241,7 @@ public function isTranslatable() { // Check that the bundle is translatable, the entity has a language defined // and if we have more than one language on the site. $bundles = $this->entityManager()->getBundleInfo($this->entityTypeId); - return !empty($bundles[$this->bundle()]['translatable']) && empty($this->getUntranslated()->language()->locked) && $this->languageManager()->isMultilingual(); + return !empty($bundles[$this->bundle()]['translatable']) && !$this->getUntranslated()->language()->isLocked() && $this->languageManager()->isMultilingual(); } /** @@ -562,7 +562,7 @@ public function getTranslation($langcode) { // If the entity or the requested language is not a configured // language, we fall back to the entity itself, since in this case it // cannot have translations. - $translation = empty($this->languages[$this->defaultLangcode]->locked) && empty($this->languages[$langcode]->locked) ? $this->addTranslation($langcode) : $this; + $translation = !$this->languages[$this->defaultLangcode]->isLocked() && !$this->languages[$langcode]->isLocked() ? $this->addTranslation($langcode) : $this; } } } diff --git a/core/lib/Drupal/Core/Language/Language.php b/core/lib/Drupal/Core/Language/Language.php index 9e0407754758b798db10ca8282224a169b345b7e..b04f60f855a64b4464d53e542ae690e14695959c 100644 --- a/core/lib/Drupal/Core/Language/Language.php +++ b/core/lib/Drupal/Core/Language/Language.php @@ -68,7 +68,7 @@ class Language implements LanguageInterface { * * @var bool */ - public $locked = FALSE; + protected $locked = FALSE; /** * Constructs a new class instance. @@ -131,6 +131,13 @@ public function isDefault() { return static::getDefaultLangcode() == $this->getId(); } + /** + * {@inheritdoc} + */ + public function isLocked() { + return (bool) $this->locked; + } + /** * Sort language objects. * diff --git a/core/lib/Drupal/Core/Language/LanguageInterface.php b/core/lib/Drupal/Core/Language/LanguageInterface.php index f2e58f34aa6f5d8d2e99afd85ddf12b0c10a7338..5f5ff2458513061d320fcf650ec5ee1459dd1fdb 100644 --- a/core/lib/Drupal/Core/Language/LanguageInterface.php +++ b/core/lib/Drupal/Core/Language/LanguageInterface.php @@ -137,4 +137,12 @@ public function getWeight(); */ public function isDefault(); + /** + * Returns whether this language is locked. + * + * @return bool + * Whether the language is locked or not. + */ + public function isLocked(); + } diff --git a/core/lib/Drupal/Core/Language/LanguageManager.php b/core/lib/Drupal/Core/Language/LanguageManager.php index e86c6ce0fd6b52ef8c6e87b28dc1bcf07e2de48f..605a5aba7cd29cc1e8b26a3a70410fd181ac7ace 100644 --- a/core/lib/Drupal/Core/Language/LanguageManager.php +++ b/core/lib/Drupal/Core/Language/LanguageManager.php @@ -154,7 +154,7 @@ public function getLanguages($flags = LanguageInterface::STATE_CONFIGURABLE) { } foreach ($this->languages as $id => $language) { - if (($language->locked && ($flags & LanguageInterface::STATE_LOCKED)) || (!$language->locked && ($flags & LanguageInterface::STATE_CONFIGURABLE))) { + if (($language->isLocked() && ($flags & LanguageInterface::STATE_LOCKED)) || (!$language->isLocked() && ($flags & LanguageInterface::STATE_CONFIGURABLE))) { $filtered_languages[$id] = $language; } } @@ -226,7 +226,7 @@ public function getDefaultLockedLanguages($weight = 0) { */ public function isLanguageLocked($langcode) { $language = $this->getLanguage($langcode); - return ($language ? $language->locked : FALSE); + return ($language ? $language->isLocked() : FALSE); } /** diff --git a/core/modules/config_translation/src/Access/ConfigTranslationFormAccess.php b/core/modules/config_translation/src/Access/ConfigTranslationFormAccess.php index 9ea54ef5bb172626f523a86ab1eb855cbacbec0e..09f7fdce705d3bb69175f887a02ad1c49096f347 100644 --- a/core/modules/config_translation/src/Access/ConfigTranslationFormAccess.php +++ b/core/modules/config_translation/src/Access/ConfigTranslationFormAccess.php @@ -32,7 +32,7 @@ public function access(Route $route, AccountInterface $account, $langcode = NULL // that is logically not a good idea. $access = !empty($target_language) && - !$target_language->locked && + !$target_language->isLocked() && (empty($this->sourceLanguage) || ($target_language->id != $this->sourceLanguage->id)); return $base_access->andIf(AccessResult::allowedIf($access)); diff --git a/core/modules/config_translation/src/Access/ConfigTranslationOverviewAccess.php b/core/modules/config_translation/src/Access/ConfigTranslationOverviewAccess.php index fe0266b22076a93f889a32117a1f923e1e41fd20..2669778ce44eeb51703a543728a42f737afd904e 100644 --- a/core/modules/config_translation/src/Access/ConfigTranslationOverviewAccess.php +++ b/core/modules/config_translation/src/Access/ConfigTranslationOverviewAccess.php @@ -70,11 +70,12 @@ public function access(Route $route, AccountInterface $account) { // Allow access to the translation overview if the proper permission is // granted, the configuration has translatable pieces, and the source // language is not locked if it is present. + $source_language_access = is_null($this->sourceLanguage) || !$this->sourceLanguage->isLocked(); $access = $account->hasPermission('translate configuration') && $mapper->hasSchema() && $mapper->hasTranslatable() && - empty($this->sourceLanguage->locked); + $source_language_access; return AccessResult::allowedIf($access)->cachePerRole(); } diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index b8d9363225f08554d102423ae2eaa3cdaa25973b..49e4b67039711fd388a81406cacb74d96893502d 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -224,7 +224,7 @@ function _content_translation_menu_strip_loaders($path) { */ function content_translation_translate_access(EntityInterface $entity) { $account = \Drupal::currentUser(); - $condition = $entity instanceof ContentEntityInterface && empty($entity->getUntranslated()->language()->locked) && \Drupal::languageManager()->isMultilingual() && $entity->isTranslatable() && + $condition = $entity instanceof ContentEntityInterface && !$entity->getUntranslated()->language()->isLocked() && \Drupal::languageManager()->isMultilingual() && $entity->isTranslatable() && ($account->hasPermission('create content translations') || $account->hasPermission('update content translations') || $account->hasPermission('delete content translations')); return AccessResult::allowedIf($condition)->cachePerRole()->cacheUntilEntityChanges($entity); } diff --git a/core/modules/language/language.module b/core/modules/language/language.module index 381fbd422d0669747eb77ad7926e450caa554a0a..40b9bfa8656054781dcb4899b9d469114e0ebd6e 100644 --- a/core/modules/language/language.module +++ b/core/modules/language/language.module @@ -148,7 +148,7 @@ function language_process_language_select($element) { if (!isset($element['#options'])) { $element['#options'] = array(); foreach (\Drupal::languageManager()->getLanguages($element['#languages']) as $langcode => $language) { - $element['#options'][$langcode] = $language->locked ? t('- @name -', array('@name' => $language->name)) : $language->name; + $element['#options'][$langcode] = $language->isLocked() ? t('- @name -', array('@name' => $language->name)) : $language->name; } } // Add "Built-in English" language to the select when the default value is @@ -434,7 +434,7 @@ function language_modules_uninstalled($modules) { * Implements hook_ENTITY_TYPE_insert() for 'configurable_language'. */ function language_configurable_language_insert(ConfigurableLanguage $language) { - if (!empty($language->locked)) { + if ($language->isLocked()) { return; } diff --git a/core/modules/language/src/ConfigurableLanguageManager.php b/core/modules/language/src/ConfigurableLanguageManager.php index 17262366c12c6cda150bcbacc2450ea3c7c3831c..6699ab0ef191614504d0f7f2527ccc320c715526 100644 --- a/core/modules/language/src/ConfigurableLanguageManager.php +++ b/core/modules/language/src/ConfigurableLanguageManager.php @@ -337,7 +337,7 @@ public function updateLockedLanguageWeights() { // Get maximum weight to update the system languages to keep them on bottom. foreach ($this->getLanguages(LanguageInterface::STATE_CONFIGURABLE) as $language) { - if (!$language->locked && $language->weight > $max_weight) { + if (!$language->isLocked() && $language->weight > $max_weight) { $max_weight = $language->weight; } } diff --git a/core/modules/language/src/Element/LanguageConfiguration.php b/core/modules/language/src/Element/LanguageConfiguration.php index 273d7338b34df99237ef317c6ac55efef1540c22..e24f8bd8709674faaf234b4fb20696ed66a13839 100644 --- a/core/modules/language/src/Element/LanguageConfiguration.php +++ b/core/modules/language/src/Element/LanguageConfiguration.php @@ -100,7 +100,7 @@ protected static function getDefaultOptions() { $languages = static::languageManager()->getLanguages(LanguageInterface::STATE_ALL); foreach ($languages as $langcode => $language) { - $language_options[$langcode] = $language->locked ? t('- @name -', array('@name' => $language->name)) : $language->name; + $language_options[$langcode] = $language->isLocked() ? t('- @name -', array('@name' => $language->name)) : $language->name; } return $language_options; diff --git a/core/modules/language/src/Entity/ConfigurableLanguage.php b/core/modules/language/src/Entity/ConfigurableLanguage.php index bcdf7e226cd99ba3238c961ccc0226ac74344d74..1235b8a2543642fecdd40f972ca6d8b6e8597f5a 100644 --- a/core/modules/language/src/Entity/ConfigurableLanguage.php +++ b/core/modules/language/src/Entity/ConfigurableLanguage.php @@ -78,7 +78,7 @@ class ConfigurableLanguage extends ConfigEntityBase implements ConfigurableLangu * * @var bool */ - public $locked = FALSE; + protected $locked = FALSE; /** * Used during saving to detect when the site becomes multilingual. @@ -100,6 +100,13 @@ public function isDefault() { return static::getDefaultLangcode() == $this->id(); } + /** + * {@inheritdoc} + */ + public function isLocked() { + return (bool) $this->locked; + } + /** * {@inheritdoc} */ diff --git a/core/modules/language/src/LanguageAccessControlHandler.php b/core/modules/language/src/LanguageAccessControlHandler.php index 4322c178c155cb9ab30d0fad932908a5216c5d9a..0490e913a4867f8693076c243b65f60b94332078 100644 --- a/core/modules/language/src/LanguageAccessControlHandler.php +++ b/core/modules/language/src/LanguageAccessControlHandler.php @@ -26,7 +26,8 @@ public function checkAccess(EntityInterface $entity, $operation, $langcode, Acco switch ($operation) { case 'update': case 'delete': - return AccessResult::allowedIf(!$entity->locked)->cacheUntilEntityChanges($entity) + /* @var \Drupal\Core\Language\LanguageInterface $entity */ + return AccessResult::allowedIf(!$entity->isLocked())->cacheUntilEntityChanges($entity) ->andIf(parent::checkAccess($entity, $operation, $langcode, $account)); default: diff --git a/core/modules/language/src/Tests/LanguageConfigurationTest.php b/core/modules/language/src/Tests/LanguageConfigurationTest.php index c7e66d6ed2c6a2d099a30e20ca9e4b23e72dbceb..d7cc61f20fd6b13fed7424e528622bd63c48fc82 100644 --- a/core/modules/language/src/Tests/LanguageConfigurationTest.php +++ b/core/modules/language/src/Tests/LanguageConfigurationTest.php @@ -172,7 +172,7 @@ protected function getHighestConfigurableLanguageWeight(){ $languages = entity_load_multiple('configurable_language', NULL, TRUE); foreach ($languages as $language) { - if (!$language->locked && $language->weight > $max_weight) { + if (!$language->isLocked() && $language->weight > $max_weight) { $max_weight = $language->weight; } } diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index d2db127685f2fa88cd804f35570863a2f504112f..a6b785ed31049921c9f4c8fc7b13a0e1087e70c2 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -592,7 +592,7 @@ function locale_form_language_admin_overview_form_alter(&$form, FormStateInterfa 'translated' => 0, 'ratio' => 0, ); - if (!$language->locked && ($langcode != 'en' || locale_translate_english())) { + if (!$language->isLocked() && ($langcode != 'en' || locale_translate_english())) { $form['languages'][$langcode]['locale_statistics'] = array( '#markup' => \Drupal::l( t('@translated/@total (@ratio%)', array( diff --git a/core/modules/node/src/Plugin/Search/NodeSearch.php b/core/modules/node/src/Plugin/Search/NodeSearch.php index bd51e98d46880aeaddc073766d1813c9e6ab97dc..5d13e7dd23e8a47cf87927b7a796c0d048820501 100644 --- a/core/modules/node/src/Plugin/Search/NodeSearch.php +++ b/core/modules/node/src/Plugin/Search/NodeSearch.php @@ -446,7 +446,7 @@ public function searchFormAlter(array &$form, FormStateInterface $form_state) { $language_list = \Drupal::languageManager()->getLanguages(LanguageInterface::STATE_ALL); foreach ($language_list as $langcode => $language) { // Make locked languages appear special in the list. - $language_options[$langcode] = $language->locked ? t('- @name -', array('@name' => $language->name)) : $language->name; + $language_options[$langcode] = $language->isLocked() ? t('- @name -', array('@name' => $language->name)) : $language->name; } if (count($language_options) > 1) { $form['advanced']['lang-fieldset'] = array( diff --git a/core/modules/system/src/Tests/Form/LanguageSelectElementTest.php b/core/modules/system/src/Tests/Form/LanguageSelectElementTest.php index 2f4408ab24b2124e195273dc49199cff605db06c..3ec7fe8bfd9404c81ef1b460566b97ad164ff50e 100644 --- a/core/modules/system/src/Tests/Form/LanguageSelectElementTest.php +++ b/core/modules/system/src/Tests/Form/LanguageSelectElementTest.php @@ -56,7 +56,7 @@ function testLanguageSelectElementOptions() { $this->assertField($id, format_string('The @id field was found on the page.', array('@id' => $id))); $options = array(); foreach ($this->container->get('language_manager')->getLanguages($flags) as $langcode => $language) { - $options[$langcode] = $language->locked ? t('- @name -', array('@name' => $language->name)) : $language->name; + $options[$langcode] = $language->isLocked() ? t('- @name -', array('@name' => $language->name)) : $language->name; } $this->_testLanguageSelectElementOptions($id, $options); } diff --git a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php index d951f7593c86e221fd77618fade631bfa20b89b4..1287b473fb53ce53f75392da95dcc84f2de0ad25 100644 --- a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php @@ -278,11 +278,11 @@ public function testIsTranslatable() { ->method('isMultilingual') ->will($this->returnValue(TRUE)); $this->assertTrue($this->entity->language()->id == 'en'); - $this->assertFalse($this->entity->language()->locked); + $this->assertFalse($this->entity->language()->isLocked()); $this->assertTrue($this->entity->isTranslatable()); $this->assertTrue($this->entityUnd->language()->id == LanguageInterface::LANGCODE_NOT_SPECIFIED); - $this->assertTrue($this->entityUnd->language()->locked); + $this->assertTrue($this->entityUnd->language()->isLocked()); $this->assertFalse($this->entityUnd->isTranslatable()); }