Commit 646a9074 authored by git's avatar git Committed by larowlan

Issue #2800955 by Ginovski: Do a final release for 8.1 compatibility, then...

Issue #2800955 by Ginovski: Do a final release for 8.1 compatibility, then remove the redirect page third party setting
parent caf16729
......@@ -9,4 +9,5 @@ dependencies:
- views
- options
- token
- drupal:system (>=8.2)
configure: entity.contact_message.collection
......@@ -83,3 +83,27 @@ function contact_storage_update_8003() {
\Drupal::entityDefinitionUpdateManager()
->installFieldStorageDefinition('ip_address', 'contact_message', 'contact_storage', $storage_definition);
}
/**
* Updates the redirect paths to the core property redirect path.
*/
function contact_storage_update_8200() {
$config_factory = \Drupal::configFactory();
// Iterate on all text formats config entities.
foreach ($config_factory->listAll('contact.form.') as $name) {
if ($redirect_page = $config_factory->get($name)->get('third_party_settings.contact_storage.redirect_uri')) {
$config = $config_factory->getEditable($name);
$config->clear('third_party_settings.contact_storage.redirect_uri');
try {
$url = '/' . \Drupal\Core\Url::fromUri($redirect_page)->getInternalPath();
}
catch (Exception $e) {
continue;
}
if (!$config->get('redirect')) {
$config->set('redirect', $url);
}
$config->save();
}
}
}
......@@ -14,9 +14,9 @@ use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\contact\ContactFormInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Url;
use Drupal\contact\Entity\ContactForm;
use Drupal\views\Views;
use Symfony\Component\Validator\Constraints\Url;
/**
* Implements hook_form_FORM_ID_alter() for contact_form_form().
......@@ -30,12 +30,6 @@ function contact_storage_form_contact_form_form_alter(&$form, FormStateInterface
return;
}
$contact_form = $form_object->getEntity();
$form['contact_storage_uri'] = [
'#type' => 'textfield',
'#title' => t('Redirect Page'),
'#description' => t('Input the Uri (entity:node/NODE-ID) of the Page to redirect the form after Submit.'),
'#default_value' => $contact_form->getThirdPartySetting('contact_storage', 'redirect_uri', FALSE),
];
$form['contact_storage_submit_text'] = [
'#type' => 'textfield',
'#title' => t('Submit button text'),
......@@ -82,7 +76,6 @@ function contact_storage_form_contact_form_form_alter(&$form, FormStateInterface
* @see contact_storage_test_form_contact_form_edit_form_alter()
*/
function contact_storage_contact_form_form_builder($entity_type, ContactFormInterface $contact_form, &$form, FormStateInterface $form_state) {
$contact_form->setThirdPartySetting('contact_storage', 'redirect_uri', $form_state->getValue('contact_storage_uri'));
$contact_form->setThirdPartySetting('contact_storage', 'submit_text', $form_state->getValue('contact_storage_submit_text'));
$contact_form->setThirdPartySetting('contact_storage', 'show_preview', $form_state->getValue('contact_storage_preview'));
$contact_form->setThirdPartySetting('contact_storage', 'disabled_form_message', $form_state->getValue('contact_storage_disabled_form_message'));
......@@ -105,14 +98,6 @@ function contact_storage_contact_form_form_validate(&$form, FormStateInterface &
$formState->setError($form['contact_storage_url_alias'], 'The alias path has to start with a slash.');
}
}
if ($redirect_uri = $formState->getValue('contact_storage_uri')) {
try {
Url::fromUri($redirect_uri);
}
catch (\Exception $e) {
$formState->setErrorByName('contact_storage_uri', t('The Redirect page is not valid.'));
}
}
}
/**
......@@ -150,7 +135,6 @@ function contact_storage_contact_form_form_submit(&$form, FormStateInterface &$f
* Implements hook_form_FORM_ID_alter() for contact_form_form().
*/
function contact_storage_form_contact_message_form_alter(&$form, &$form_state, $form_id) {
$form['actions']['submit']['#submit'][] = 'contact_storage_contact_message_redirect_submit';
/** @var \Drupal\Core\Entity\ContentEntityForm $form_object */
$form_object = $form_state->getFormObject();
/* @var \Drupal\contact\MessageInterface $contact_message */
......@@ -184,18 +168,6 @@ function contact_storage_form_contact_message_form_alter(&$form, &$form_state, $
}
}
/**
* Implements a Submit Callback for contact_message_form.
*/
function contact_storage_contact_message_redirect_submit(&$form, &$form_state) {
/* @var \Drupal\contact\MessageInterface $contact_message */
$contact_message = $form_state->getFormObject()->getEntity();
$contact_form = ContactForm::load($contact_message->bundle());
if ($redirect_uri = $contact_form->getThirdPartySetting('contact_storage', 'redirect_uri', FALSE)) {
$form_state->setRedirectUrl(Url::fromUri($redirect_uri));
}
}
/**
* Implements hook_entity_base_field_info().
*/
......@@ -417,7 +389,6 @@ function contact_storage_theme() {
'template' => 'contact-storage-disabled-form',
'variables' => array(
'contact_form' => NULL,
'redirect_uri' => '',
'disabled_form_message' => '',
),
),
......
......@@ -160,21 +160,6 @@ class ContactStorageTest extends ContactStorageTestBase {
// Make sure no messages are available.
$this->assertText('There is no Contact message yet.');
// Fill the redirect field and assert the page is successfully redirected.
$edit = ['contact_storage_uri' => 'entity:user/' . $this->adminUser->id()];
$this->drupalPostForm('admin/structure/contact/manage/test_id', $edit, t('Save'));
$edit = [
'subject[0][value]' => 'Test subject',
'message[0][value]' => 'Test message',
];
$this->drupalPostForm('contact', $edit, t('Send message'));
$this->assertText('Your message has been sent.');
$this->assertEqual($this->url, $this->adminUser->urlInfo()->setAbsolute()->toString());
// Check that this new message is now in HTML format.
$captured_emails = $this->drupalGetMails();
$this->assertTrue(strpos($captured_emails[1]['headers']['Content-Type'], 'text/html') !== FALSE);
// Fill the "Submit button text" field and assert the form can still be
// submitted.
$edit = [
......@@ -310,16 +295,6 @@ class ContactStorageTest extends ContactStorageTestBase {
$this->assertText('custom disabled message');
}
/**
* Tests the redirect page validation.
*/
public function testRedirectPage() {
// Add a contact form with invalid redirect page.
$mail = 'simpletest@example.com';
$this->addContactForm('test_id', 'test_label', $mail, '', TRUE, ['contact_storage_uri' => '/']);
$this->assertText('The Redirect page is not valid.');
}
/**
* Tests the url alias creation feature.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment