Skip to content
Snippets Groups Projects
Verified Commit 55849506 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3422872 by kunal.sachdev, Wim Leers: Add validation constraints to contact.settings

(cherry picked from commit c41bea2d)
parent 43e3efe0
No related branches found
No related tags found
21 merge requests!10602Issue #3438769 by vinmayiswamy, antonnavi, michelle, amateescu: Sub workspace does not clear,!10301Issue #3469309 by mstrelan, smustgrave, moshe weitzman: Use one-time login...,!10187Issue #3487488 by dakwamine: ExtensionMimeTypeGuesser::guessMimeType must support file names with "0" (zero) like foo.0.zip,!9944Issue #3483353: Consider making the createCopy config action optionally fail...,!9929Issue #3445469 by pooja_sharma, smustgrave: Add additional test coverage for...,!9787Resolve issue 3479427 - bootstrap barrio issue under Windows,!9742Issue #3463908 by catch, quietone: Split OptionsFieldUiTest into two,!9526Issue #3458177 by mondrake, catch, quietone, godotislate, longwave, larowlan,...,!8738Issue #3424162 by camilledavis, dineshkumarbollu, smustgrave: Claro...,!8704Make greek characters available in ckeditor5,!8597Draft: Issue #3442259 by catch, quietone, dww: Reduce time of Migrate Upgrade tests...,!8533Issue #3446962 by kim.pepper: Remove incorrectly added...,!8517Issue #3443748 by NexusNovaz, smustgrave: Testcase creates false positive,!8325Update file Sort.php,!8095Expose document root on install,!7930Resolve #3427374 "Taxonomytid viewsargumentdefault plugin",!7627Issue #3439440 by nicxvan, Binoli Lalani, longwave: Remove country support from DateFormatter,!7445Issue #3440169: When using drupalGet(), provide an associative array for $headers,!6502Draft: Resolve #2938524 "Plach testing issue",!38582585169-10.1.x,!3226Issue #2987537: Custom menu link entity type should not declare "bundle" entity key
Pipeline #144696 passed with stages
in 13 minutes and 47 seconds
......@@ -52,6 +52,13 @@ trait SchemaCheckTrait {
'This value should not be blank.',
],
],
'contact.settings' => [
// @todo Simple config cannot have dependencies on any other config.
// Remove this in https://www.drupal.org/project/drupal/issues/3425992.
'default_form' => [
"The 'contact.form.feedback' config does not exist.",
],
],
'editor.editor.*' => [
// @todo Fix stream wrappers not being available early enough in
// https://www.drupal.org/project/drupal/issues/3416735
......
......@@ -37,20 +37,35 @@ contact.form.*:
contact.settings:
type: config_object
label: 'Contact settings'
constraints:
FullyValidatable: ~
mapping:
default_form:
type: string
label: 'Default form identifier'
# It is possible to not configure a default form.
# @see \Drupal\contact\ContactFormEditForm::save()
nullable: true
constraints:
ConfigExists:
prefix: contact.form.
flood:
# @see \Drupal\Core\Flood\FloodInterface::isAllowed()
type: mapping
label: 'Flood control'
mapping:
limit:
type: integer
label: 'Limit'
label: 'Limit (messages per interval)'
constraints:
Range:
min: 1
interval:
type: integer
label: 'Interval'
label: 'Interval (seconds)'
constraints:
Range:
min: 1
user_default_enabled:
type: boolean
label: 'Personal contact form enabled by default'
......@@ -13,3 +13,15 @@ function contact_removed_post_updates() {
'contact_post_update_add_message_redirect_field_to_contact_form' => '9.0.0',
];
}
/**
* Converts empty `default_form` in settings to NULL.
*/
function contact_post_update_set_empty_default_form_to_null(): void {
$config = \Drupal::configFactory()->getEditable('contact.settings');
// 'default_form' in 'contact.settings' config must be stored as NULL if it
// is empty.
if ($config->get('default_form') === '') {
$config->set('default_form', NULL)->save();
}
}
......@@ -11,6 +11,11 @@ source:
process:
user_default_enabled: contact_default_status
'flood/limit': contact_hourly_threshold
'flood/interval':
plugin: default_value
# It was defaulted to 3600 in D6.
# @see https://api.drupal.org/api/drupal/includes%21common.inc/function/flood_is_allowed/6.x
default_value: 3600
default_form:
plugin: migration_lookup
migration: contact_category
......
......@@ -11,6 +11,11 @@ source:
process:
user_default_enabled: contact_default_status
'flood/limit': contact_threshold_limit
'flood/interval':
plugin: default_value
# It was defaulted to 3600 in D7.
# @see https://api.drupal.org/api/drupal/includes%21common.inc/function/flood_is_allowed/7.x
default_value: 3600
default_form:
plugin: migration_lookup
migration: contact_category
......
......@@ -50,9 +50,13 @@ public function contactSitePage(ContactFormInterface $contact_form = NULL) {
// Use the default form if no form has been passed.
if (empty($contact_form)) {
$contact_form = $this->entityTypeManager()
->getStorage('contact_form')
->load($config->get('default_form'));
$default_form = $config->get('default_form');
// Load the default form, if configured.
if (!is_null($default_form)) {
$contact_form = $this->entityTypeManager()
->getStorage('contact_form')
->load($default_form);
}
// If there are no forms, do not display the form.
if (empty($contact_form)) {
if ($this->currentUser()->hasPermission('administer contact forms')) {
......
......@@ -256,7 +256,7 @@ public function testSiteWideContact() {
// Test contact form with no default form selected.
$this->config('contact.settings')
->set('default_form', '')
->set('default_form', NULL)
->save();
$this->drupalGet('contact');
$this->assertSession()->statusCodeEquals(404);
......
<?php
declare(strict_types=1);
namespace Drupal\Tests\contact\Functional\Update;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
/**
* Tests the upgrade path for making 'default_form' in 'contact.settings' config to NULL.
*
* @group contact
* @see contact_post_update_set_empty_default_form_to_null()
*/
class NullDefaultFormTest extends UpdatePathTestBase {
/**
* {@inheritdoc}
*/
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-9.4.0.filled.standard.php.gz',
];
}
/**
* Tests the upgrade path for updating empty 'default_form' to NULL.
*/
public function testRunUpdates(): void {
$this->config('contact.settings')->set('default_form', '')->save();
$this->assertSame('', $this->config('contact.settings')->get('default_form'));
$this->runUpdates();
$this->assertNull($this->config('contact.settings')->get('default_form'));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment