Commit 27636950 authored by alexpott's avatar alexpott

Issue #2340571 by Désiré | YesCT: LanguageInterface needs isLocked method for the locked property.

parent daaccc3b
...@@ -751,9 +751,9 @@ function update_language_list($flags = LanguageInterface::STATE_CONFIGURABLE) { ...@@ -751,9 +751,9 @@ function update_language_list($flags = LanguageInterface::STATE_CONFIGURABLE) {
} }
foreach ($languages as $langcode => $language) { 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; continue;
} }
$filtered_languages[$langcode] = $language; $filtered_languages[$langcode] = $language;
} }
......
...@@ -241,7 +241,7 @@ public function isTranslatable() { ...@@ -241,7 +241,7 @@ public function isTranslatable() {
// Check that the bundle is translatable, the entity has a language defined // Check that the bundle is translatable, the entity has a language defined
// and if we have more than one language on the site. // and if we have more than one language on the site.
$bundles = $this->entityManager()->getBundleInfo($this->entityTypeId); $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) { ...@@ -562,7 +562,7 @@ public function getTranslation($langcode) {
// If the entity or the requested language is not a configured // If the entity or the requested language is not a configured
// language, we fall back to the entity itself, since in this case it // language, we fall back to the entity itself, since in this case it
// cannot have translations. // 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;
} }
} }
} }
......
...@@ -68,7 +68,7 @@ class Language implements LanguageInterface { ...@@ -68,7 +68,7 @@ class Language implements LanguageInterface {
* *
* @var bool * @var bool
*/ */
public $locked = FALSE; protected $locked = FALSE;
/** /**
* Constructs a new class instance. * Constructs a new class instance.
...@@ -131,6 +131,13 @@ public function isDefault() { ...@@ -131,6 +131,13 @@ public function isDefault() {
return static::getDefaultLangcode() == $this->getId(); return static::getDefaultLangcode() == $this->getId();
} }
/**
* {@inheritdoc}
*/
public function isLocked() {
return (bool) $this->locked;
}
/** /**
* Sort language objects. * Sort language objects.
* *
......
...@@ -137,4 +137,12 @@ public function getWeight(); ...@@ -137,4 +137,12 @@ public function getWeight();
*/ */
public function isDefault(); public function isDefault();
/**
* Returns whether this language is locked.
*
* @return bool
* Whether the language is locked or not.
*/
public function isLocked();
} }
...@@ -154,7 +154,7 @@ public function getLanguages($flags = LanguageInterface::STATE_CONFIGURABLE) { ...@@ -154,7 +154,7 @@ public function getLanguages($flags = LanguageInterface::STATE_CONFIGURABLE) {
} }
foreach ($this->languages as $id => $language) { 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; $filtered_languages[$id] = $language;
} }
} }
...@@ -226,7 +226,7 @@ public function getDefaultLockedLanguages($weight = 0) { ...@@ -226,7 +226,7 @@ public function getDefaultLockedLanguages($weight = 0) {
*/ */
public function isLanguageLocked($langcode) { public function isLanguageLocked($langcode) {
$language = $this->getLanguage($langcode); $language = $this->getLanguage($langcode);
return ($language ? $language->locked : FALSE); return ($language ? $language->isLocked() : FALSE);
} }
/** /**
......
...@@ -32,7 +32,7 @@ public function access(Route $route, AccountInterface $account, $langcode = NULL ...@@ -32,7 +32,7 @@ public function access(Route $route, AccountInterface $account, $langcode = NULL
// that is logically not a good idea. // that is logically not a good idea.
$access = $access =
!empty($target_language) && !empty($target_language) &&
!$target_language->locked && !$target_language->isLocked() &&
(empty($this->sourceLanguage) || ($target_language->id != $this->sourceLanguage->id)); (empty($this->sourceLanguage) || ($target_language->id != $this->sourceLanguage->id));
return $base_access->andIf(AccessResult::allowedIf($access)); return $base_access->andIf(AccessResult::allowedIf($access));
......
...@@ -70,11 +70,12 @@ public function access(Route $route, AccountInterface $account) { ...@@ -70,11 +70,12 @@ public function access(Route $route, AccountInterface $account) {
// Allow access to the translation overview if the proper permission is // Allow access to the translation overview if the proper permission is
// granted, the configuration has translatable pieces, and the source // granted, the configuration has translatable pieces, and the source
// language is not locked if it is present. // language is not locked if it is present.
$source_language_access = is_null($this->sourceLanguage) || !$this->sourceLanguage->isLocked();
$access = $access =
$account->hasPermission('translate configuration') && $account->hasPermission('translate configuration') &&
$mapper->hasSchema() && $mapper->hasSchema() &&
$mapper->hasTranslatable() && $mapper->hasTranslatable() &&
empty($this->sourceLanguage->locked); $source_language_access;
return AccessResult::allowedIf($access)->cachePerRole(); return AccessResult::allowedIf($access)->cachePerRole();
} }
......
...@@ -224,7 +224,7 @@ function _content_translation_menu_strip_loaders($path) { ...@@ -224,7 +224,7 @@ function _content_translation_menu_strip_loaders($path) {
*/ */
function content_translation_translate_access(EntityInterface $entity) { function content_translation_translate_access(EntityInterface $entity) {
$account = \Drupal::currentUser(); $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')); ($account->hasPermission('create content translations') || $account->hasPermission('update content translations') || $account->hasPermission('delete content translations'));
return AccessResult::allowedIf($condition)->cachePerRole()->cacheUntilEntityChanges($entity); return AccessResult::allowedIf($condition)->cachePerRole()->cacheUntilEntityChanges($entity);
} }
......
...@@ -148,7 +148,7 @@ function language_process_language_select($element) { ...@@ -148,7 +148,7 @@ function language_process_language_select($element) {
if (!isset($element['#options'])) { if (!isset($element['#options'])) {
$element['#options'] = array(); $element['#options'] = array();
foreach (\Drupal::languageManager()->getLanguages($element['#languages']) as $langcode => $language) { 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 // Add "Built-in English" language to the select when the default value is
...@@ -434,7 +434,7 @@ function language_modules_uninstalled($modules) { ...@@ -434,7 +434,7 @@ function language_modules_uninstalled($modules) {
* Implements hook_ENTITY_TYPE_insert() for 'configurable_language'. * Implements hook_ENTITY_TYPE_insert() for 'configurable_language'.
*/ */
function language_configurable_language_insert(ConfigurableLanguage $language) { function language_configurable_language_insert(ConfigurableLanguage $language) {
if (!empty($language->locked)) { if ($language->isLocked()) {
return; return;
} }
......
...@@ -337,7 +337,7 @@ public function updateLockedLanguageWeights() { ...@@ -337,7 +337,7 @@ public function updateLockedLanguageWeights() {
// Get maximum weight to update the system languages to keep them on bottom. // Get maximum weight to update the system languages to keep them on bottom.
foreach ($this->getLanguages(LanguageInterface::STATE_CONFIGURABLE) as $language) { 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; $max_weight = $language->weight;
} }
} }
......
...@@ -100,7 +100,7 @@ protected static function getDefaultOptions() { ...@@ -100,7 +100,7 @@ protected static function getDefaultOptions() {
$languages = static::languageManager()->getLanguages(LanguageInterface::STATE_ALL); $languages = static::languageManager()->getLanguages(LanguageInterface::STATE_ALL);
foreach ($languages as $langcode => $language) { 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; return $language_options;
......
...@@ -78,7 +78,7 @@ class ConfigurableLanguage extends ConfigEntityBase implements ConfigurableLangu ...@@ -78,7 +78,7 @@ class ConfigurableLanguage extends ConfigEntityBase implements ConfigurableLangu
* *
* @var bool * @var bool
*/ */
public $locked = FALSE; protected $locked = FALSE;
/** /**
* Used during saving to detect when the site becomes multilingual. * Used during saving to detect when the site becomes multilingual.
...@@ -100,6 +100,13 @@ public function isDefault() { ...@@ -100,6 +100,13 @@ public function isDefault() {
return static::getDefaultLangcode() == $this->id(); return static::getDefaultLangcode() == $this->id();
} }
/**
* {@inheritdoc}
*/
public function isLocked() {
return (bool) $this->locked;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -26,7 +26,8 @@ public function checkAccess(EntityInterface $entity, $operation, $langcode, Acco ...@@ -26,7 +26,8 @@ public function checkAccess(EntityInterface $entity, $operation, $langcode, Acco
switch ($operation) { switch ($operation) {
case 'update': case 'update':
case 'delete': 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)); ->andIf(parent::checkAccess($entity, $operation, $langcode, $account));
default: default:
......
...@@ -172,7 +172,7 @@ protected function getHighestConfigurableLanguageWeight(){ ...@@ -172,7 +172,7 @@ protected function getHighestConfigurableLanguageWeight(){
$languages = entity_load_multiple('configurable_language', NULL, TRUE); $languages = entity_load_multiple('configurable_language', NULL, TRUE);
foreach ($languages as $language) { foreach ($languages as $language) {
if (!$language->locked && $language->weight > $max_weight) { if (!$language->isLocked() && $language->weight > $max_weight) {
$max_weight = $language->weight; $max_weight = $language->weight;
} }
} }
......
...@@ -592,7 +592,7 @@ function locale_form_language_admin_overview_form_alter(&$form, FormStateInterfa ...@@ -592,7 +592,7 @@ function locale_form_language_admin_overview_form_alter(&$form, FormStateInterfa
'translated' => 0, 'translated' => 0,
'ratio' => 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( $form['languages'][$langcode]['locale_statistics'] = array(
'#markup' => \Drupal::l( '#markup' => \Drupal::l(
t('@translated/@total (@ratio%)', array( t('@translated/@total (@ratio%)', array(
......
...@@ -446,7 +446,7 @@ public function searchFormAlter(array &$form, FormStateInterface $form_state) { ...@@ -446,7 +446,7 @@ public function searchFormAlter(array &$form, FormStateInterface $form_state) {
$language_list = \Drupal::languageManager()->getLanguages(LanguageInterface::STATE_ALL); $language_list = \Drupal::languageManager()->getLanguages(LanguageInterface::STATE_ALL);
foreach ($language_list as $langcode => $language) { foreach ($language_list as $langcode => $language) {
// Make locked languages appear special in the list. // 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) { if (count($language_options) > 1) {
$form['advanced']['lang-fieldset'] = array( $form['advanced']['lang-fieldset'] = array(
......
...@@ -56,7 +56,7 @@ function testLanguageSelectElementOptions() { ...@@ -56,7 +56,7 @@ function testLanguageSelectElementOptions() {
$this->assertField($id, format_string('The @id field was found on the page.', array('@id' => $id))); $this->assertField($id, format_string('The @id field was found on the page.', array('@id' => $id)));
$options = array(); $options = array();
foreach ($this->container->get('language_manager')->getLanguages($flags) as $langcode => $language) { 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); $this->_testLanguageSelectElementOptions($id, $options);
} }
......
...@@ -278,11 +278,11 @@ public function testIsTranslatable() { ...@@ -278,11 +278,11 @@ public function testIsTranslatable() {
->method('isMultilingual') ->method('isMultilingual')
->will($this->returnValue(TRUE)); ->will($this->returnValue(TRUE));
$this->assertTrue($this->entity->language()->id == 'en'); $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->entity->isTranslatable());
$this->assertTrue($this->entityUnd->language()->id == LanguageInterface::LANGCODE_NOT_SPECIFIED); $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()); $this->assertFalse($this->entityUnd->isTranslatable());
} }
......
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