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) {
}
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;
}
......
......@@ -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;
}
}
}
......
......@@ -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.
*
......
......@@ -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();
}
......@@ -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);
}
/**
......
......@@ -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));
......
......@@ -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();
}
......
......@@ -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);
}
......
......@@ -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;
}
......
......@@ -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;
}
}
......
......@@ -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;
......
......@@ -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}
*/
......
......@@ -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:
......
......@@ -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;
}
}
......
......@@ -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(
......
......@@ -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(
......
......@@ -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);
}
......
......@@ -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());
}
......
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