Mercurial > hg > cmmr2012-drupal-site
diff core/modules/content_translation/src/ContentTranslationHandler.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | a9cd425dd02b |
children |
line wrap: on
line diff
--- a/core/modules/content_translation/src/ContentTranslationHandler.php Thu Feb 28 13:11:55 2019 +0000 +++ b/core/modules/content_translation/src/ContentTranslationHandler.php Thu May 09 15:34:47 2019 +0100 @@ -3,13 +3,15 @@ namespace Drupal\content_translation; use Drupal\Core\Access\AccessResult; +use Drupal\Core\Datetime\DateFormatterInterface; use Drupal\Core\DependencyInjection\DependencySerializationTrait; use Drupal\Core\Entity\EntityChangedInterface; use Drupal\Core\Entity\EntityChangesDetectionTrait; use Drupal\Core\Entity\EntityHandlerInterface; use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface; use Drupal\Core\Entity\EntityTypeInterface; +use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; @@ -91,6 +93,13 @@ protected $messenger; /** + * The date formatter service. + * + * @var \Drupal\Core\Datetime\DateFormatterInterface + */ + protected $dateFormatter; + + /** * Initializes an instance of the content translation controller. * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type @@ -99,22 +108,29 @@ * The language manager. * @param \Drupal\content_translation\ContentTranslationManagerInterface $manager * The content translation manager service. - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * The entity manager. + * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager + * The entity type manager. * @param \Drupal\Core\Session\AccountInterface $current_user * The current user. * @param \Drupal\Core\Messenger\MessengerInterface $messenger * The messenger service. + * @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter + * The date formatter service. */ - public function __construct(EntityTypeInterface $entity_type, LanguageManagerInterface $language_manager, ContentTranslationManagerInterface $manager, EntityManagerInterface $entity_manager, AccountInterface $current_user, MessengerInterface $messenger) { + public function __construct(EntityTypeInterface $entity_type, LanguageManagerInterface $language_manager, ContentTranslationManagerInterface $manager, EntityTypeManagerInterface $entity_type_manager, AccountInterface $current_user, MessengerInterface $messenger, DateFormatterInterface $date_formatter, EntityLastInstalledSchemaRepositoryInterface $entity_last_installed_schema_repository = NULL) { $this->entityTypeId = $entity_type->id(); $this->entityType = $entity_type; $this->languageManager = $language_manager; $this->manager = $manager; - $this->entityTypeManager = $entity_manager; + $this->entityTypeManager = $entity_type_manager; $this->currentUser = $current_user; - $this->fieldStorageDefinitions = $entity_manager->getLastInstalledFieldStorageDefinitions($this->entityTypeId); + if (!$entity_last_installed_schema_repository) { + @trigger_error('Calling ContentTranslationHandler::__construct() with the $entity_last_installed_schema_repository argument is supported in drupal:8.7.0 and will be required before drupal:9.0.0. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED); + $entity_last_installed_schema_repository = \Drupal::service('entity.last_installed_schema.repository'); + } + $this->fieldStorageDefinitions = $entity_last_installed_schema_repository->getLastInstalledFieldStorageDefinitions($this->entityTypeId); $this->messenger = $messenger; + $this->dateFormatter = $date_formatter; } /** @@ -125,9 +141,11 @@ $entity_type, $container->get('language_manager'), $container->get('content_translation.manager'), - $container->get('entity.manager'), + $container->get('entity_type.manager'), $container->get('current_user'), - $container->get('messenger') + $container->get('messenger'), + $container->get('date.formatter'), + $container->get('entity.last_installed_schema.repository') ); } @@ -508,8 +526,11 @@ '#type' => 'textfield', '#title' => t('Authored on'), '#maxlength' => 25, - '#description' => t('Format: %time. The date format is YYYY-MM-DD and %timezone is the time zone offset from UTC. Leave blank to use the time of form submission.', ['%time' => format_date(REQUEST_TIME, 'custom', 'Y-m-d H:i:s O'), '%timezone' => format_date(REQUEST_TIME, 'custom', 'O')]), - '#default_value' => $new_translation || !$date ? '' : format_date($date, 'custom', 'Y-m-d H:i:s O'), + '#description' => t('Format: %time. The date format is YYYY-MM-DD and %timezone is the time zone offset from UTC. Leave blank to use the time of form submission.', [ + '%time' => $this->dateFormatter->format(REQUEST_TIME, 'custom', 'Y-m-d H:i:s O'), + '%timezone' => $this->dateFormatter->format(REQUEST_TIME, 'custom', 'O'), + ]), + '#default_value' => $new_translation || !$date ? '' : $this->dateFormatter->format($date, 'custom', 'Y-m-d H:i:s O'), ]; $form['#process'][] = [$this, 'entityFormSharedElements']; @@ -680,7 +701,7 @@ $translation = $form_state->getValue('content_translation'); // Validate the "authored by" field. if (!empty($translation['uid']) && !($account = User::load($translation['uid']))) { - $form_state->setErrorByName('content_translation][uid', t('The translation authoring username %name does not exist.', ['%name' => $account->getUsername()])); + $form_state->setErrorByName('content_translation][uid', t('The translation authoring username %name does not exist.', ['%name' => $account->getAccountName()])); } // Validate the "authored on" field. if (!empty($translation['created']) && strtotime($translation['created']) === FALSE) { @@ -758,7 +779,7 @@ $entity = $form_object->getEntity(); $entity_type_id = $entity->getEntityTypeId(); if ($entity->access('delete') && $this->entityType->hasLinkTemplate('delete-form')) { - $form_state->setRedirectUrl($entity->urlInfo('delete-form')); + $form_state->setRedirectUrl($entity->toUrl('delete-form')); } else { $form_state->setRedirect("entity.$entity_type_id.content_translation_delete", [