diff --git a/core/modules/contact/contact.post_update.php b/core/modules/contact/contact.post_update.php index 9069259..32469a5 100644 --- a/core/modules/contact/contact.post_update.php +++ b/core/modules/contact/contact.post_update.php @@ -17,7 +17,7 @@ */ function contact_post_update_add_message_redirect_field_to_contact_form() { /** @var \Drupal\contact\ContactFormInterface $contact */ - foreach(ContactForm::loadMultiple() as $contact) { + foreach (ContactForm::loadMultiple() as $contact) { $contact ->setMessage('Your message has been sent.') ->setRedirectPath('') diff --git a/core/modules/contact/src/ContactFormEditForm.php b/core/modules/contact/src/ContactFormEditForm.php index ad3b0f9..c1a04e9 100644 --- a/core/modules/contact/src/ContactFormEditForm.php +++ b/core/modules/contact/src/ContactFormEditForm.php @@ -2,6 +2,7 @@ namespace Drupal\contact; +use Drupal\Component\Utility\Unicode; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Entity\EntityForm; @@ -145,7 +146,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) { $form_state->setValue('recipients', $recipients); $redirect_url = $form_state->getValue('redirect'); if ($redirect_url && $this->pathValidator->isValid($redirect_url)) { - if(substr($redirect_url, 0, 1) != '/') { + if (Unicode::substr($redirect_url, 0, 1) !== '/') { $form_state->setErrorByName('redirect', $this->t('The path should start with /.')); } } diff --git a/core/modules/contact/src/Tests/Update/ContactUpdateTest.php b/core/modules/contact/src/Tests/Update/ContactUpdateTest.php index 104389b..4cbfd64 100644 --- a/core/modules/contact/src/Tests/Update/ContactUpdateTest.php +++ b/core/modules/contact/src/Tests/Update/ContactUpdateTest.php @@ -2,7 +2,6 @@ namespace Drupal\contact\Tests\Update; -use Drupal\contact\Entity\ContactForm; use Drupal\system\Tests\Update\UpdatePathTestBase; /** @@ -31,31 +30,23 @@ public function testPostUpdateContactFormFields() { $config_factory = \Drupal::configFactory(); // Check that contact_form entities are more than zero. $contact_forms = $config_factory->listAll('contact.form.'); - $this->assertTrue(count($contact_forms), 'Contact forms are more than zero'); - foreach ($config_factory->listAll('contact.form.') as $contact_config_name) { - $contact_form = $config_factory->getEditable($contact_config_name); - // Check whether 'message' and 'redirect' property does not exist for this entity. - $message = $contact_form->get('message'); - $this->assertFALSE(is_string($message), 'Message does not exist'); - $redirect = $contact_form->get('redirect'); - $this->assertFalse(is_string($redirect), 'Redirect does not exist'); + $this->assertTrue(count($contact_forms), 'There are contact forms to update.'); + foreach ($contact_forms as $contact_config_name) { + $contact_form_data = $config_factory->get($contact_config_name)->get(); + $this->assertFalse(isset($contact_form_data['message']), 'Prior to running the update the "message" key does not exist.'); + $this->assertFalse(isset($contact_form_data['redirect']), 'Prior to running the update the "redirect" key does not exist.'); } // Run updates. $this->runUpdates(); - // Check that contact_form have fields redirect and message. - $config_factory = \Drupal::configFactory(); - // Check that contact_form entities are more than zero. - $contact_forms = $config_factory->listAll('contact.form.'); - $this->assertTrue(count($contact_forms), 'Contact forms are more than zero'); + // Check that the contact_form entities have been updated. foreach ($contact_forms as $contact_config_name) { - $contact_form = $config_factory->getEditable($contact_config_name); - // Check whether 'message' and 'redirect' property exist for this entity. - $message = $contact_form->get('message'); - $this->assertTRUE(is_string($message), 'Message property exists'); - $redirect = $contact_form->get('redirect'); - $this->assertTRUE(is_string($redirect), 'Redirect property exists'); + $contact_form_data = $config_factory->get($contact_config_name)->get(); + $this->assertTrue(isset($contact_form_data['message']), 'After running the update the "message" key exists.'); + $this->assertEqual('Your message has been sent.', $contact_form_data['message']); + $this->assertTrue(isset($contact_form_data['redirect']), 'After running the update the "redirect" key exists.'); + $this->assertEqual('', $contact_form_data['redirect']); } }