diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php index d897c22079..33e85550d7 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php @@ -1400,7 +1400,7 @@ public function hasTranslationChanges() { // The list of fields to skip from the comparision. $skip_fields = $this->getFieldsToSkipFromTranslationChangesCheck(); - // We check also untranslatable fields, so that a change to those will mark + // We also check untranslatable fields, so that a change to those will mark // all translations as affected, unless they are configured to only affect // the default translation. $skip_untranslatable_fields = !$this->isDefaultTranslation() && $this->isDefaultTranslationAffectedOnly(); diff --git a/core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityUntranslatableFieldsConstraint.php b/core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityUntranslatableFieldsConstraint.php index e1aae729c0..0044b6b4fb 100644 --- a/core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityUntranslatableFieldsConstraint.php +++ b/core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityUntranslatableFieldsConstraint.php @@ -15,6 +15,6 @@ */ class EntityUntranslatableFieldsConstraint extends Constraint { - public $message = 'Non translatable fields can only be changed either when updating the current revision or the original language.'; + public $message = 'Non translatable fields can only be changed when updating the current revision or the original language.'; } diff --git a/core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityUntranslatableFieldsConstraintValidator.php b/core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityUntranslatableFieldsConstraintValidator.php index 58d31079a4..39ed9e00a4 100644 --- a/core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityUntranslatableFieldsConstraintValidator.php +++ b/core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityUntranslatableFieldsConstraintValidator.php @@ -2,26 +2,55 @@ namespace Drupal\Core\Entity\Plugin\Validation\Constraint; +use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\EntityChangesDetectionTrait; +use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Field\ChangedFieldItemList; +use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; /** * Validates the EntityChanged constraint. */ -class EntityUntranslatableFieldsConstraintValidator extends ConstraintValidator { +class EntityUntranslatableFieldsConstraintValidator extends ConstraintValidator implements ContainerInjectionInterface { use EntityChangesDetectionTrait; + /** + * The entity type manager. + * + * @var \Drupal\Core\Entity\EntityTypeManagerInterface + */ + protected $entityTypeManager; + + /** + * Constructs an EntityUntranslatableFieldsConstraintValidator object. + * + * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager + * The entity type manager. + */ + public function __construct(EntityTypeManagerInterface $entity_type_manager) { + $this->entityTypeManager = $entity_type_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('entity_type.manager') + ); + } + /** * {@inheritdoc} */ public function validate($entity, Constraint $constraint) { /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ - // Untranslatable fields restrictions apply only to pending revisions of + // Untranslatable field restrictions apply only to pending revisions of // multilingual entities. if ($entity->isNew() || $entity->isDefaultRevision() || !$entity->isTranslatable() || !$entity->getEntityType()->isRevisionable()) { return; @@ -51,7 +80,7 @@ public function validate($entity, Constraint $constraint) { } /** - * Checks whether an entity has untranslatable fields changes. + * Checks whether an entity has untranslatable field changes. * * @param \Drupal\Core\Entity\ContentEntityInterface $entity * A content entity object. @@ -64,7 +93,7 @@ protected function hasUntranslatableFieldsChanges(ContentEntityInterface $entity /** @var \Drupal\Core\Entity\ContentEntityInterface $original */ $original = isset($entity->original) ? $entity->original : - \Drupal::entityTypeManager() + $this->entityTypeManager ->getStorage($entity->getEntityTypeId()) ->loadRevision($entity->getLoadedRevisionId()); diff --git a/core/modules/content_translation/content_translation.admin.inc b/core/modules/content_translation/content_translation.admin.inc index 98a5d5cee1..d71b150b90 100644 --- a/core/modules/content_translation/content_translation.admin.inc +++ b/core/modules/content_translation/content_translation.admin.inc @@ -336,8 +336,8 @@ function content_translation_form_language_content_settings_validate(array $form * @see content_translation_admin_settings_form_validate() */ function content_translation_form_language_content_settings_submit(array $form, FormStateInterface $form_state) { - /** @var \Drupal\content_translation\ContentTranslationManagerInterface $manager */ - $manager = \Drupal::service('content_translation.manager'); + /** @var \Drupal\content_translation\ContentTranslationManagerInterface $content_translation_manager */ + $content_translation_manager = \Drupal::service('content_translation.manager'); $entity_types = $form_state->getValue('entity_types'); $settings = &$form_state->getValue('settings'); @@ -368,11 +368,11 @@ function content_translation_form_language_content_settings_submit(array $form, } if (isset($bundle_settings['translatable'])) { // Store whether a bundle has translation enabled or not. - $manager->setEnabled($entity_type_id, $bundle, $bundle_settings['translatable']); + $content_translation_manager->setEnabled($entity_type_id, $bundle, $bundle_settings['translatable']); // Store any other bundle settings. - if ($manager instanceof BundleSettingsInterface) { - $manager->setBundleSettings($entity_type_id, $bundle, $bundle_settings['settings']['content_translation']); + if ($content_translation_manager instanceof BundleSettingsInterface) { + $content_translation_manager->setBundleSettings($entity_type_id, $bundle, $bundle_settings['settings']['content_translation']); } // Save translation_sync settings. diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index a6db070e59..b0038eca18 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -162,13 +162,13 @@ function content_translation_entity_type_alter(array &$entity_types) { * Implements hook_entity_bundle_info_alter(). */ function content_translation_entity_bundle_info_alter(&$bundles) { - /** @var \Drupal\content_translation\ContentTranslationManagerInterface $manager */ - $manager = \Drupal::service('content_translation.manager'); + /** @var \Drupal\content_translation\ContentTranslationManagerInterface $content_translation_manager */ + $content_translation_manager = \Drupal::service('content_translation.manager'); foreach ($bundles as $entity_type_id => &$info) { foreach ($info as $bundle => &$bundle_info) { - $bundle_info['translatable'] = $manager->isEnabled($entity_type_id, $bundle); - if ($manager instanceof BundleSettingsInterface) { - $settings = $manager->getBundleSettings($entity_type_id, $bundle); + $bundle_info['translatable'] = $content_translation_manager->isEnabled($entity_type_id, $bundle); + if ($content_translation_manager instanceof BundleSettingsInterface) { + $settings = $content_translation_manager->getBundleSettings($entity_type_id, $bundle); $bundle_info['untranslatable_fields.default_translation_affected'] = !empty($settings['untranslatable_fields_hide']); } } diff --git a/core/modules/content_translation/src/ContentTranslationHandler.php b/core/modules/content_translation/src/ContentTranslationHandler.php index e1a3b6b498..71e9ba86f9 100644 --- a/core/modules/content_translation/src/ContentTranslationHandler.php +++ b/core/modules/content_translation/src/ContentTranslationHandler.php @@ -96,7 +96,7 @@ class ContentTranslationHandler implements ContentTranslationHandlerInterface, E * The entity manager. * @param \Drupal\Core\Session\AccountInterface $current_user * The current user. - * @param \Drupal\Core\Messenger\MessengerInterface + * @param \Drupal\Core\Messenger\MessengerInterface $messenger * The messenger service. */ public function __construct(EntityTypeInterface $entity_type, LanguageManagerInterface $language_manager, ContentTranslationManagerInterface $manager, EntityManagerInterface $entity_manager, AccountInterface $current_user, MessengerInterface $messenger) { @@ -541,8 +541,8 @@ public function entityFormSharedElements($element, FormStateInterface $form_stat $display_warning = FALSE; // We use field definitions to identify untranslatable field widgets to be - // hidden. Fields that are not involved in translation changes checks, for - // instance the "revision_log" field, should not be affected by this logic. + // hidden. Field that are not involved in translation changes checks should + // not be affected by this logic (the "revision_log" field, for instance). $field_definitions = array_diff_key($entity->getFieldDefinitions(), array_flip($this->getFieldsToSkipFromTranslationChangesCheck($entity))); foreach (Element::children($element) as $key) { @@ -578,7 +578,7 @@ public function entityFormSharedElements($element, FormStateInterface $form_stat if ($display_warning && !$form_state->isSubmitted() && !$form_state->isRebuilding()) { $url = $entity->getUntranslated()->toUrl('edit-form')->toString(); - $this->messenger->addWarning($this->t('Fields that apply to all languages are hidden to avoid conflicting changes. Edit them on the original language form.', ['@url' => $url])); + $this->messenger->addWarning($this->t('Fields that apply to all languages are hidden to avoid conflicting changes. Edit them on the original language form.', [':url' => $url])); } return $element;