comparison core/modules/user/src/AccountForm.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 4c8ae668cc8c
children af1871eacc83
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
4 4
5 use Drupal\Component\Datetime\TimeInterface; 5 use Drupal\Component\Datetime\TimeInterface;
6 use Drupal\Component\Utility\Crypt; 6 use Drupal\Component\Utility\Crypt;
7 use Drupal\Core\Entity\ContentEntityForm; 7 use Drupal\Core\Entity\ContentEntityForm;
8 use Drupal\Core\Entity\EntityConstraintViolationListInterface; 8 use Drupal\Core\Entity\EntityConstraintViolationListInterface;
9 use Drupal\Core\Entity\EntityManagerInterface; 9 use Drupal\Core\Entity\EntityRepositoryInterface;
10 use Drupal\Core\Entity\EntityTypeBundleInfoInterface; 10 use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
11 use Drupal\Core\Form\FormStateInterface; 11 use Drupal\Core\Form\FormStateInterface;
12 use Drupal\Core\Language\LanguageInterface; 12 use Drupal\Core\Language\LanguageInterface;
13 use Drupal\Core\Language\LanguageManagerInterface; 13 use Drupal\Core\Language\LanguageManagerInterface;
14 use Drupal\language\ConfigurableLanguageManagerInterface; 14 use Drupal\language\ConfigurableLanguageManagerInterface;
29 protected $languageManager; 29 protected $languageManager;
30 30
31 /** 31 /**
32 * Constructs a new EntityForm object. 32 * Constructs a new EntityForm object.
33 * 33 *
34 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager 34 * @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
35 * The entity manager. 35 * The entity repository.
36 * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager 36 * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
37 * The language manager. 37 * The language manager.
38 * @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info 38 * @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
39 * The entity type bundle service. 39 * The entity type bundle service.
40 * @param \Drupal\Component\Datetime\TimeInterface $time 40 * @param \Drupal\Component\Datetime\TimeInterface $time
41 * The time service. 41 * The time service.
42 */ 42 */
43 public function __construct(EntityManagerInterface $entity_manager, LanguageManagerInterface $language_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, TimeInterface $time = NULL) { 43 public function __construct(EntityRepositoryInterface $entity_repository, LanguageManagerInterface $language_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, TimeInterface $time = NULL) {
44 parent::__construct($entity_manager, $entity_type_bundle_info, $time); 44 parent::__construct($entity_repository, $entity_type_bundle_info, $time);
45 $this->languageManager = $language_manager; 45 $this->languageManager = $language_manager;
46 } 46 }
47 47
48 /** 48 /**
49 * {@inheritdoc} 49 * {@inheritdoc}
50 */ 50 */
51 public static function create(ContainerInterface $container) { 51 public static function create(ContainerInterface $container) {
52 return new static( 52 return new static(
53 $container->get('entity.manager'), 53 $container->get('entity.repository'),
54 $container->get('language_manager'), 54 $container->get('language_manager'),
55 $container->get('entity_type.bundle.info'), 55 $container->get('entity_type.bundle.info'),
56 $container->get('datetime.time') 56 $container->get('datetime.time')
57 ); 57 );
58 } 58 }
159 ]; 159 ];
160 } 160 }
161 161
162 // When not building the user registration form, prevent web browsers from 162 // When not building the user registration form, prevent web browsers from
163 // autofilling/prefilling the email, username, and password fields. 163 // autofilling/prefilling the email, username, and password fields.
164 if ($this->getOperation() != 'register') { 164 if (!$register) {
165 foreach (['mail', 'name', 'pass'] as $key) { 165 foreach (['mail', 'name', 'pass'] as $key) {
166 if (isset($form['account'][$key])) { 166 if (isset($form['account'][$key])) {
167 $form['account'][$key]['#attributes']['autocomplete'] = 'off'; 167 $form['account'][$key]['#attributes']['autocomplete'] = 'off';
168 } 168 }
169 } 169 }
345 'pass', 345 'pass',
346 'mail', 346 'mail',
347 'timezone', 347 'timezone',
348 'langcode', 348 'langcode',
349 'preferred_langcode', 349 'preferred_langcode',
350 'preferred_admin_langcode' 350 'preferred_admin_langcode',
351 ], parent::getEditedFieldNames($form_state)); 351 ], parent::getEditedFieldNames($form_state));
352 } 352 }
353 353
354 /** 354 /**
355 * {@inheritdoc} 355 * {@inheritdoc}
363 'pass', 363 'pass',
364 'mail', 364 'mail',
365 'timezone', 365 'timezone',
366 'langcode', 366 'langcode',
367 'preferred_langcode', 367 'preferred_langcode',
368 'preferred_admin_langcode' 368 'preferred_admin_langcode',
369 ]; 369 ];
370 foreach ($violations->getByFields($field_names) as $violation) { 370 foreach ($violations->getByFields($field_names) as $violation) {
371 list($field_name) = explode('.', $violation->getPropertyPath(), 2); 371 list($field_name) = explode('.', $violation->getPropertyPath(), 2);
372 $form_state->setErrorByName($field_name, $violation->getMessage()); 372 $form_state->setErrorByName($field_name, $violation->getMessage());
373 } 373 }