diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2ac0df06..b85e9109 100755
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,8 @@ Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
+* [PR-353](https://github.com/itk-dev/hoeringsportal/pull/353)
+ Added “Allow email” checkboxes
* [PR-351](https://github.com/itk-dev/hoeringsportal/pull/351)
Added and used citizen proposal text format
* [PR-350](https://github.com/itk-dev/hoeringsportal/pull/350)
diff --git a/config/sync/core.entity_form_display.node.citizen_proposal.default.yml b/config/sync/core.entity_form_display.node.citizen_proposal.default.yml
index a086dd48..b23e4b8c 100644
--- a/config/sync/core.entity_form_display.node.citizen_proposal.default.yml
+++ b/config/sync/core.entity_form_display.node.citizen_proposal.default.yml
@@ -3,6 +3,7 @@ langcode: da
status: true
dependencies:
config:
+ - field.field.node.citizen_proposal.field_author_allow_email
- field.field.node.citizen_proposal.field_author_email
- field.field.node.citizen_proposal.field_author_email_display
- field.field.node.citizen_proposal.field_author_name
@@ -42,6 +43,13 @@ targetEntityType: node
bundle: citizen_proposal
mode: default
content:
+ field_author_allow_email:
+ type: boolean_checkbox
+ weight: 4
+ region: content
+ settings:
+ display_label: true
+ third_party_settings: { }
field_author_email:
type: email_default
weight: 2
@@ -83,7 +91,7 @@ content:
third_party_settings: { }
field_more_info:
type: text_textarea
- weight: 7
+ weight: 8
region: content
settings:
rows: 5
@@ -94,7 +102,7 @@ content:
hide_guidelines: '1'
field_proposal:
type: text_textarea
- weight: 5
+ weight: 6
region: content
settings:
rows: 5
@@ -105,7 +113,7 @@ content:
hide_guidelines: '1'
field_remarks:
type: text_textarea
- weight: 6
+ weight: 7
region: content
settings:
rows: 5
@@ -116,14 +124,14 @@ content:
hide_guidelines: '1'
status:
type: boolean_checkbox
- weight: 8
+ weight: 9
region: content
settings:
display_label: true
third_party_settings: { }
title:
type: string_textfield
- weight: 4
+ weight: 5
region: content
settings:
size: 60
diff --git a/config/sync/core.entity_view_display.node.citizen_proposal.citizen_proposal_add.yml b/config/sync/core.entity_view_display.node.citizen_proposal.citizen_proposal_add.yml
index ed1c1f7a..4926e446 100644
--- a/config/sync/core.entity_view_display.node.citizen_proposal.citizen_proposal_add.yml
+++ b/config/sync/core.entity_view_display.node.citizen_proposal.citizen_proposal_add.yml
@@ -4,6 +4,7 @@ status: true
dependencies:
config:
- core.entity_view_mode.node.citizen_proposal_add
+ - field.field.node.citizen_proposal.field_author_allow_email
- field.field.node.citizen_proposal.field_author_email
- field.field.node.citizen_proposal.field_author_email_display
- field.field.node.citizen_proposal.field_author_name
@@ -122,6 +123,7 @@ content:
weight: 100
region: content
hidden:
+ field_author_allow_email: true
field_author_email_display: true
field_author_phone: true
field_author_uuid: true
diff --git a/config/sync/core.entity_view_display.node.citizen_proposal.citizen_proposal_approval.yml b/config/sync/core.entity_view_display.node.citizen_proposal.citizen_proposal_approval.yml
index d9cc4cd1..c2d187ac 100644
--- a/config/sync/core.entity_view_display.node.citizen_proposal.citizen_proposal_approval.yml
+++ b/config/sync/core.entity_view_display.node.citizen_proposal.citizen_proposal_approval.yml
@@ -4,6 +4,7 @@ status: true
dependencies:
config:
- core.entity_view_mode.node.citizen_proposal_approval
+ - field.field.node.citizen_proposal.field_author_allow_email
- field.field.node.citizen_proposal.field_author_email
- field.field.node.citizen_proposal.field_author_email_display
- field.field.node.citizen_proposal.field_author_name
@@ -55,6 +56,7 @@ content:
weight: 1
region: content
hidden:
+ field_author_allow_email: true
field_author_email_display: true
field_author_phone: true
field_author_uuid: true
diff --git a/config/sync/core.entity_view_display.node.citizen_proposal.default.yml b/config/sync/core.entity_view_display.node.citizen_proposal.default.yml
index 7c387cf1..4d7e624c 100644
--- a/config/sync/core.entity_view_display.node.citizen_proposal.default.yml
+++ b/config/sync/core.entity_view_display.node.citizen_proposal.default.yml
@@ -136,6 +136,7 @@ content:
weight: 9
region: right
hidden:
+ field_author_allow_email: true
field_author_email_display: true
field_author_phone: true
field_author_uuid: true
diff --git a/config/sync/core.entity_view_display.node.citizen_proposal.list_display.yml b/config/sync/core.entity_view_display.node.citizen_proposal.list_display.yml
index 0935b2f2..68ea9fc6 100644
--- a/config/sync/core.entity_view_display.node.citizen_proposal.list_display.yml
+++ b/config/sync/core.entity_view_display.node.citizen_proposal.list_display.yml
@@ -4,6 +4,7 @@ status: true
dependencies:
config:
- core.entity_view_mode.node.list_display
+ - field.field.node.citizen_proposal.field_author_allow_email
- field.field.node.citizen_proposal.field_author_email
- field.field.node.citizen_proposal.field_author_email_display
- field.field.node.citizen_proposal.field_author_name
@@ -103,6 +104,7 @@ content:
weight: 100
region: content
hidden:
+ field_author_allow_email: true
field_author_email_display: true
field_author_phone: true
field_author_uuid: true
diff --git a/config/sync/core.entity_view_display.node.citizen_proposal.teaser.yml b/config/sync/core.entity_view_display.node.citizen_proposal.teaser.yml
index ddde63b7..f081829a 100644
--- a/config/sync/core.entity_view_display.node.citizen_proposal.teaser.yml
+++ b/config/sync/core.entity_view_display.node.citizen_proposal.teaser.yml
@@ -4,6 +4,7 @@ status: true
dependencies:
config:
- core.entity_view_mode.node.teaser
+ - field.field.node.citizen_proposal.field_author_allow_email
- field.field.node.citizen_proposal.field_author_email
- field.field.node.citizen_proposal.field_author_email_display
- field.field.node.citizen_proposal.field_author_name
@@ -51,6 +52,7 @@ content:
weight: 1
region: content
hidden:
+ field_author_allow_email: true
field_author_email: true
field_author_email_display: true
field_author_phone: true
diff --git a/config/sync/field.field.node.citizen_proposal.field_author_allow_email.yml b/config/sync/field.field.node.citizen_proposal.field_author_allow_email.yml
new file mode 100644
index 00000000..b887e80e
--- /dev/null
+++ b/config/sync/field.field.node.citizen_proposal.field_author_allow_email.yml
@@ -0,0 +1,23 @@
+uuid: 8d3748de-e723-46a5-b473-0135dd28153e
+langcode: da
+status: true
+dependencies:
+ config:
+ - field.storage.node.field_author_allow_email
+ - node.type.citizen_proposal
+id: node.citizen_proposal.field_author_allow_email
+field_name: field_author_allow_email
+entity_type: node
+bundle: citizen_proposal
+label: 'Allow email'
+description: 'Author accepts receiving emails.'
+required: false
+translatable: false
+default_value:
+ -
+ value: 0
+default_value_callback: ''
+settings:
+ on_label: 'On'
+ off_label: 'Off'
+field_type: boolean
diff --git a/config/sync/field.storage.node.field_author_allow_email.yml b/config/sync/field.storage.node.field_author_allow_email.yml
new file mode 100644
index 00000000..42168f75
--- /dev/null
+++ b/config/sync/field.storage.node.field_author_allow_email.yml
@@ -0,0 +1,18 @@
+uuid: a831ce9e-944a-45fa-a981-3978c9841237
+langcode: da
+status: true
+dependencies:
+ module:
+ - node
+id: node.field_author_allow_email
+field_name: field_author_allow_email
+entity_type: node
+type: boolean
+settings: { }
+module: core
+locked: false
+cardinality: 1
+translatable: true
+indexes: { }
+persist_with_no_fields: false
+custom_storage: false
diff --git a/config/sync/views.view.citizen_proposal_support.yml b/config/sync/views.view.citizen_proposal_support.yml
index 854a4cdf..fef4f33f 100644
--- a/config/sync/views.view.citizen_proposal_support.yml
+++ b/config/sync/views.view.citizen_proposal_support.yml
@@ -126,6 +126,63 @@ display:
hide_empty: false
empty_zero: false
hide_alter_empty: true
+ allow_email:
+ id: allow_email
+ table: hoeringsportal_citizen_proposal_support
+ field: allow_email
+ relationship: none
+ group_type: group
+ admin_label: ''
+ plugin_id: numeric
+ label: 'Tillad e-mail'
+ exclude: false
+ alter:
+ alter_text: true
+ text: '{{ allow_email ? ''ja'' }}'
+ make_link: false
+ path: ''
+ absolute: false
+ external: false
+ replace_spaces: false
+ path_case: none
+ trim_whitespace: false
+ alt: ''
+ rel: ''
+ link_class: ''
+ prefix: ''
+ suffix: ''
+ target: ''
+ nl2br: false
+ max_length: 0
+ word_boundary: true
+ ellipsis: true
+ more_link: false
+ more_link_text: ''
+ more_link_path: ''
+ strip_tags: false
+ trim: false
+ preserve_tags: ''
+ html: false
+ element_type: ''
+ element_class: ''
+ element_label_type: ''
+ element_label_class: ''
+ element_label_colon: true
+ element_wrapper_type: ''
+ element_wrapper_class: ''
+ element_default_classes: true
+ empty: ''
+ hide_empty: false
+ empty_zero: false
+ hide_alter_empty: true
+ set_precision: false
+ precision: 0
+ decimal: .
+ separator: ''
+ format_plural: false
+ format_plural_string: !!binary MQNAY291bnQ=
+ prefix: ''
+ suffix: ''
created:
id: created
table: hoeringsportal_citizen_proposal_support
@@ -366,7 +423,7 @@ display:
group_type: group
admin_label: ''
plugin_id: standard
- label: Name
+ label: Navn
exclude: false
alter:
alter_text: false
@@ -415,7 +472,7 @@ display:
group_type: group
admin_label: ''
plugin_id: standard
- label: Email
+ label: E-mail
exclude: false
alter:
alter_text: false
@@ -456,6 +513,63 @@ display:
hide_empty: false
empty_zero: false
hide_alter_empty: true
+ allow_email:
+ id: allow_email
+ table: hoeringsportal_citizen_proposal_support
+ field: allow_email
+ relationship: none
+ group_type: group
+ admin_label: ''
+ plugin_id: numeric
+ label: 'Tillad e-mail'
+ exclude: false
+ alter:
+ alter_text: true
+ text: '{{ allow_email ? 1 }}'
+ make_link: false
+ path: ''
+ absolute: false
+ external: false
+ replace_spaces: false
+ path_case: none
+ trim_whitespace: false
+ alt: ''
+ rel: ''
+ link_class: ''
+ prefix: ''
+ suffix: ''
+ target: ''
+ nl2br: false
+ max_length: 0
+ word_boundary: true
+ ellipsis: true
+ more_link: false
+ more_link_text: ''
+ more_link_path: ''
+ strip_tags: false
+ trim: false
+ preserve_tags: ''
+ html: false
+ element_type: ''
+ element_class: ''
+ element_label_type: ''
+ element_label_class: ''
+ element_label_colon: true
+ element_wrapper_type: ''
+ element_wrapper_class: ''
+ element_default_classes: true
+ empty: ''
+ hide_empty: false
+ empty_zero: false
+ hide_alter_empty: true
+ set_precision: false
+ precision: 0
+ decimal: .
+ separator: ''
+ format_plural: false
+ format_plural_string: !!binary MQNAY291bnQ=
+ prefix: ''
+ suffix: ''
style:
type: data_export
options:
diff --git a/web/modules/custom/hoeringsportal_citizen_proposal/hoeringsportal_citizen_proposal.install b/web/modules/custom/hoeringsportal_citizen_proposal/hoeringsportal_citizen_proposal.install
index 9d233aa4..54d5685f 100644
--- a/web/modules/custom/hoeringsportal_citizen_proposal/hoeringsportal_citizen_proposal.install
+++ b/web/modules/custom/hoeringsportal_citizen_proposal/hoeringsportal_citizen_proposal.install
@@ -47,6 +47,14 @@ function hoeringsportal_citizen_proposal_schema(): array {
'length' => 255,
'not null' => FALSE,
],
+ 'allow_email' => [
+ 'description' => 'The proposal supporter allows email',
+ 'type' => 'int',
+ 'size' => 'tiny',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ 'default' => 0,
+ ],
'created' => [
'description' => 'The time of creation',
'type' => 'int',
@@ -183,3 +191,22 @@ function hoeringsportal_citizen_proposal_update_9003(): void {
'symfony_mailer',
]);
}
+
+/**
+ * Adds allow email column.
+ */
+function hoeringsportal_citizen_proposal_update_9004(): void {
+ $schema = \Drupal::database()->schema();
+
+ $table_name = 'hoeringsportal_citizen_proposal_support';
+ $field_name = 'allow_email';
+ $spec = [
+ 'description' => 'The proposal supporter allows email',
+ 'type' => 'int',
+ 'size' => 'tiny',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ 'default' => 0,
+ ];
+ $schema->addField($table_name, $field_name, $spec);
+}
diff --git a/web/modules/custom/hoeringsportal_citizen_proposal/src/Form/ProposalAdminForm.php b/web/modules/custom/hoeringsportal_citizen_proposal/src/Form/ProposalAdminForm.php
index ba387e10..fc54f1e1 100644
--- a/web/modules/custom/hoeringsportal_citizen_proposal/src/Form/ProposalAdminForm.php
+++ b/web/modules/custom/hoeringsportal_citizen_proposal/src/Form/ProposalAdminForm.php
@@ -113,6 +113,13 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#default_value' => $adminFormStateValues['email_display_help'] ?? '',
];
+ $form['add_form']['allow_email_help'] = [
+ '#type' => 'textfield',
+ '#title' => $this->t('Allow email help'),
+ '#default_value' => $adminFormStateValues['allow_email_help'] ?? '',
+ '#description' => $this->t('Use <a target="_blank" href="…">Read more about the emails we may send</a>
to insert a link to details on what emails might be sent.'),
+ ];
+
$form['add_form']['proposal_intro'] = [
'#type' => 'text_format',
'#title' => $this->t('Proposal intro'),
@@ -215,6 +222,13 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#default_value' => $adminFormStateValues['support_email_help'] ?? '',
];
+ $form['support_form']['support_allow_email_help'] = [
+ '#type' => 'textfield',
+ '#title' => $this->t('Allow email help'),
+ '#default_value' => $adminFormStateValues['support_allow_email_help'] ?? '',
+ '#description' => $this->t('Use <a target="_blank" href="…">Read more about the emails we may send</a>
to insert a link to details on what emails might be sent.'),
+ ];
+
$form['support_form']['support_goto_url'] = [
'#type' => 'textfield',
'#title' => $this->t('Redirect URL after a proposal has been supported'),
diff --git a/web/modules/custom/hoeringsportal_citizen_proposal/src/Form/ProposalFormAdd.php b/web/modules/custom/hoeringsportal_citizen_proposal/src/Form/ProposalFormAdd.php
index 91b454c2..46a2d2a7 100644
--- a/web/modules/custom/hoeringsportal_citizen_proposal/src/Form/ProposalFormAdd.php
+++ b/web/modules/custom/hoeringsportal_citizen_proposal/src/Form/ProposalFormAdd.php
@@ -88,6 +88,14 @@ public function buildProposalForm(array $form, FormStateInterface $formState): a
'#description_display' => 'before',
];
+ $form['allow_email'] = [
+ '#type' => 'checkbox',
+ '#title' => $this
+ ->t('Allow email'),
+ '#default_value' => $defaltValues['allow_email'] ?? FALSE,
+ '#description' => $this->getAdminFormStateValue('allow_email_help'),
+ ];
+
$form['proposal_intro_container'] = [
'#type' => 'container',
'#attributes' => ['class' => ['mt-5']],
@@ -280,6 +288,7 @@ public function submitForm(array &$form, FormStateInterface $formState): void {
'field_author_email_display' => $formState->getValue('email_display'),
'field_proposal' => $formState->getValue('proposal'),
'field_remarks' => $formState->getValue('remarks'),
+ 'field_author_allow_email' => $formState->getValue('allow_email'),
]);
$this->helper->setDraftProposal($entity);
$formState
diff --git a/web/modules/custom/hoeringsportal_citizen_proposal/src/Form/ProposalFormApprove.php b/web/modules/custom/hoeringsportal_citizen_proposal/src/Form/ProposalFormApprove.php
index 77766114..66bdee6b 100644
--- a/web/modules/custom/hoeringsportal_citizen_proposal/src/Form/ProposalFormApprove.php
+++ b/web/modules/custom/hoeringsportal_citizen_proposal/src/Form/ProposalFormApprove.php
@@ -122,6 +122,17 @@ public function buildProposalForm(array $form, FormStateInterface $formState): a
],
];
+ $form['allow_email'] = [
+ '#type' => 'checkbox',
+ '#title' => $this
+ ->t('Allow email'),
+ '#default_value' => $defaltValues['allow_email'],
+ '#description' => $this->getAdminFormStateValue('allow_email_help'),
+ '#attributes' => [
+ 'disabled' => 'disabled',
+ ],
+ ];
+
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = [
'#type' => 'submit',
diff --git a/web/modules/custom/hoeringsportal_citizen_proposal/src/Form/ProposalFormBase.php b/web/modules/custom/hoeringsportal_citizen_proposal/src/Form/ProposalFormBase.php
index 3d9b6487..b309500f 100644
--- a/web/modules/custom/hoeringsportal_citizen_proposal/src/Form/ProposalFormBase.php
+++ b/web/modules/custom/hoeringsportal_citizen_proposal/src/Form/ProposalFormBase.php
@@ -142,6 +142,7 @@ protected function getDefaultFormValues(): array {
'title' => $entity?->title->value ?? NULL,
'proposal' => $entity?->field_proposal->value ?? '',
'remarks' => $entity?->field_remarks->value ?? '',
+ 'allow_email' => $entity?->field_author_allow_email->value ?? FALSE,
];
}
diff --git a/web/modules/custom/hoeringsportal_citizen_proposal/src/Form/ProposalFormSupport.php b/web/modules/custom/hoeringsportal_citizen_proposal/src/Form/ProposalFormSupport.php
index 382ac4da..080009ad 100644
--- a/web/modules/custom/hoeringsportal_citizen_proposal/src/Form/ProposalFormSupport.php
+++ b/web/modules/custom/hoeringsportal_citizen_proposal/src/Form/ProposalFormSupport.php
@@ -95,7 +95,6 @@ protected function buildProposalForm(array $form, FormStateInterface $formState)
$form['email'] = [
'#type' => 'email',
- '#required' => TRUE,
'#title' => $this
->t('Email'),
'#default_value' => $defaltValues['email'],
@@ -103,6 +102,19 @@ protected function buildProposalForm(array $form, FormStateInterface $formState)
'#description_display' => 'before',
];
+ $form['allow_email'] = [
+ '#type' => 'checkbox',
+ '#title' => $this
+ ->t('Allow email'),
+ '#default_value' => $defaltValues['support_allow_email_help'] ?? FALSE,
+ '#description' => $this->getAdminFormStateValue('support_allow_email_help'),
+ '#states' => [
+ 'visible' => [
+ ':input[name="email"]' => ['filled' => TRUE],
+ ],
+ ],
+ ];
+
$form['consent'] = [
'#type' => 'checkbox',
'#title' => $this
@@ -154,6 +166,7 @@ public function submitForm(array &$form, FormStateInterface $form_state): void {
[
'user_name' => $form_state->getValue('name'),
'user_email' => $form_state->getValue('email'),
+ 'allow_email' => $form_state->getValue('allow_email'),
],
);
$this->messenger()->addStatus($this->getAdminFormStateValue('support_submission_text', $this->t('Thank you for your support.')));
diff --git a/web/modules/custom/hoeringsportal_citizen_proposal/src/Helper/Helper.php b/web/modules/custom/hoeringsportal_citizen_proposal/src/Helper/Helper.php
index 4c43852b..ad67157f 100644
--- a/web/modules/custom/hoeringsportal_citizen_proposal/src/Helper/Helper.php
+++ b/web/modules/custom/hoeringsportal_citizen_proposal/src/Helper/Helper.php
@@ -218,6 +218,7 @@ public function saveSupport(string $userIdentifier, NodeInterface $node, array $
try {
$values['user_identifier'] = $userIdentifier;
$values['node_id'] = $node->id();
+ $values['allow_email'] = ($values['allow_email'] ?? FALSE) ? 1 : 0;
// Set some defaults.
$values += [
'created' => $this->time->getRequestTime(),
@@ -238,7 +239,8 @@ public function saveSupport(string $userIdentifier, NodeInterface $node, array $
'exception' => $exception,
'values' => $values,
]);
- $this->messenger()->addError($this->t('Something went wrong. Your support was not registered.'));
+
+ throw $exception;
}
}