From 27636950ac3bba921fcafb0526837740201c9d9b Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Mon, 29 Sep 2014 08:10:45 +0200
Subject: [PATCH] =?UTF-8?q?Issue=20#2340571=20by=20D=C3=A9sir=C3=A9=20|=20?=
 =?UTF-8?q?YesCT:=20LanguageInterface=20needs=20isLocked=20method=20for=20?=
 =?UTF-8?q?the=20locked=20property.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 core/includes/update.inc                                 | 4 ++--
 core/lib/Drupal/Core/Entity/ContentEntityBase.php        | 4 ++--
 core/lib/Drupal/Core/Language/Language.php               | 9 ++++++++-
 core/lib/Drupal/Core/Language/LanguageInterface.php      | 8 ++++++++
 core/lib/Drupal/Core/Language/LanguageManager.php        | 4 ++--
 .../src/Access/ConfigTranslationFormAccess.php           | 2 +-
 .../src/Access/ConfigTranslationOverviewAccess.php       | 3 ++-
 .../content_translation/content_translation.module       | 2 +-
 core/modules/language/language.module                    | 4 ++--
 .../modules/language/src/ConfigurableLanguageManager.php | 2 +-
 .../language/src/Element/LanguageConfiguration.php       | 2 +-
 .../modules/language/src/Entity/ConfigurableLanguage.php | 9 ++++++++-
 .../language/src/LanguageAccessControlHandler.php        | 3 ++-
 .../language/src/Tests/LanguageConfigurationTest.php     | 2 +-
 core/modules/locale/locale.module                        | 2 +-
 core/modules/node/src/Plugin/Search/NodeSearch.php       | 2 +-
 .../system/src/Tests/Form/LanguageSelectElementTest.php  | 2 +-
 .../Tests/Core/Entity/ContentEntityBaseUnitTest.php      | 4 ++--
 18 files changed, 46 insertions(+), 22 deletions(-)

diff --git a/core/includes/update.inc b/core/includes/update.inc
index 9a4606e37d40..d31f994e3b8a 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 02c290612eab..636c00b7d96c 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 9e0407754758..b04f60f855a6 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 f2e58f34aa6f..5f5ff2458513 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 e86c6ce0fd6b..605a5aba7cd2 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 9ea54ef5bb17..09f7fdce705d 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 fe0266b22076..2669778ce44e 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 b8d9363225f0..49e4b6703971 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 381fbd422d06..40b9bfa86560 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 17262366c12c..6699ab0ef191 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 273d7338b34d..e24f8bd87096 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 bcdf7e226cd9..1235b8a25436 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 4322c178c155..0490e913a486 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 c7e66d6ed2c6..d7cc61f20fd6 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 d2db127685f2..a6b785ed3104 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 bd51e98d4688..5d13e7dd23e8 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 2f4408ab24b2..3ec7fe8bfd94 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 d951f7593c86..1287b473fb53 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());
   }
 
-- 
GitLab