-
-
Save plach79/c1425c28d671ec828a6c to your computer and use it in GitHub Desktop.
Content language settings form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/core/modules/content_translation/content_translation.admin.inc b/core/modules/content_translation/content_translation.admin.inc | |
index 231dbc6..5832aed 100644 | |
--- a/core/modules/content_translation/content_translation.admin.inc | |
+++ b/core/modules/content_translation/content_translation.admin.inc | |
@@ -86,12 +86,17 @@ function _content_translation_form_language_content_settings_form_alter(array &$ | |
foreach ($form['#labels'] as $entity_type_id => $label) { | |
$entity_type = $entity_manager->getDefinition($entity_type_id); | |
$storage_definitions = $entity_type instanceof ContentEntityTypeInterface ? $entity_manager->getFieldStorageDefinitions($entity_type_id) : array(); | |
+ $entity_type_translatable = $entity_type->isTranslatable(); | |
+ $form['settings'][$entity_type_id]['#translatable'] = $entity_type_translatable; | |
foreach (entity_get_bundles($entity_type_id) as $bundle => $bundle_info) { | |
// Here we do not want the widget to be altered and hold also the "Enable | |
// translation" checkbox, which would be redundant. Hence we add this key | |
// to be able to skip alterations. | |
$form['settings'][$entity_type_id][$bundle]['settings']['language']['#content_translation_skip_alter'] = TRUE; | |
+ if (!$entity_type_translatable) { | |
+ continue; | |
+ } | |
$fields = $entity_manager->getFieldDefinitions($entity_type_id, $bundle); | |
if ($fields) { | |
@@ -138,13 +143,12 @@ function _content_translation_form_language_content_settings_form_alter(array &$ | |
function _content_translation_preprocess_language_content_settings_table(&$variables) { | |
// Alter the 'build' variable injecting the translation settings if the user | |
// has the required permission. | |
- if (!\Drupal::currentUser()->hasPermission('administer content translation')) { | |
+ $element = $variables['element']; | |
+ if (empty($element['#translatable']) || !\Drupal::currentUser()->hasPermission('administer content translation')) { | |
return; | |
} | |
- $element = $variables['element']; | |
$build = &$variables['build']; | |
- | |
array_unshift($build['#header'], array('data' => t('Translatable'), 'class' => array('translatable'))); | |
$rows = array(); | |
diff --git a/core/modules/language/language.module b/core/modules/language/language.module | |
index 01113ca..565e008 100644 | |
--- a/core/modules/language/language.module | |
+++ b/core/modules/language/language.module | |
@@ -547,6 +547,8 @@ function language_field_info_alter(&$info) { | |
* Implements hook_entity_field_access() | |
*/ | |
function language_entity_field_access($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) { | |
+ // @todo Use the language entity key here. | |
+ // See https://www.drupal.org/node/2143729. | |
if ($field_definition->getName() == 'langcode') { | |
$language_configuration = language_get_default_configuration($field_definition->getTargetEntityTypeId(), $items->getEntity()->bundle()); | |
return AccessResult::forbiddenIf(!$language_configuration['language_show']); | |
diff --git a/core/modules/language/src/Form/ContentLanguageSettingsForm.php b/core/modules/language/src/Form/ContentLanguageSettingsForm.php | |
index a415379..b48517f 100644 | |
--- a/core/modules/language/src/Form/ContentLanguageSettingsForm.php | |
+++ b/core/modules/language/src/Form/ContentLanguageSettingsForm.php | |
@@ -8,6 +8,7 @@ | |
namespace Drupal\language\Form; | |
use Drupal\Core\Config\ConfigFactoryInterface; | |
+use Drupal\Core\Entity\ContentEntityTypeInterface; | |
use Drupal\Core\Entity\EntityManagerInterface; | |
use Drupal\Core\Form\ConfigFormBase; | |
use Drupal\Core\Form\FormStateInterface; | |
@@ -68,7 +69,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { | |
$bundles = $this->entityManager->getAllBundleInfo(); | |
$language_configuration = array(); | |
foreach ($entity_types as $entity_type_id => $entity_type) { | |
- if (!$entity_type->isTranslatable()) { | |
+ if (!$entity_type instanceof ContentEntityTypeInterface || !isset($this->entityManager->getBaseFieldDefinitions($entity_type_id)['langcode'])) { | |
continue; | |
} | |
$labels[$entity_type_id] = $entity_type->getLabel() ?: $entity_type_id; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line #69 does not work well as all (core) content entity types have a language field.