+
+ {# If entities is null, the user does not have an edit token #}
+ {% if entities is same as(null) %}
+ {{ 'Find my content'|trans }}
+ {% endif %}
+{% else %}
+ {% for entity_type in entities %}
+
+ {% endfor %}
+
+{% endif %}
+
diff --git a/web/modules/custom/hoeringsportal_dialogue/hoeringsportal_dialogue.info.yml b/web/modules/custom/hoeringsportal_dialogue/hoeringsportal_dialogue.info.yml
index 0dc5f1fa4..faabbe128 100755
--- a/web/modules/custom/hoeringsportal_dialogue/hoeringsportal_dialogue.info.yml
+++ b/web/modules/custom/hoeringsportal_dialogue/hoeringsportal_dialogue.info.yml
@@ -5,3 +5,6 @@ package: Hoeringsportal
core_version_requirement: ^10 || ^11
interface translation project: hoeringsportal_dialogue
interface translation server pattern: modules/custom/hoeringsportal_dialogue/translations/hoeringsportal_dialogue.%language.po
+
+dependencies:
+ - hoeringsportal_anonymous_edit:hoeringsportal_anonymous_edit
diff --git a/web/modules/custom/hoeringsportal_dialogue/hoeringsportal_dialogue.module b/web/modules/custom/hoeringsportal_dialogue/hoeringsportal_dialogue.module
index ec93095be..3261a5f41 100644
--- a/web/modules/custom/hoeringsportal_dialogue/hoeringsportal_dialogue.module
+++ b/web/modules/custom/hoeringsportal_dialogue/hoeringsportal_dialogue.module
@@ -59,3 +59,10 @@ function hoeringsportal_dialogue_form_node_dialogue_proposal_form_alter(array &$
function hoeringsportal_dialogue_form_node_dialogue_proposal_edit_form_alter(array &$form, FormStateInterface $form_state) {
Drupal::service(DialogueHelper::class)->dialogueProposalFormAlter($form, $form_state);
}
+
+/**
+ * Implements hook_form_FORMID_alter().
+ */
+function hoeringsportal_dialogue_form_comment_early_inclusion_comment_form_alter(array &$form, FormStateInterface $form_state) {
+ Drupal::service(DialogueHelper::class)->commentEarlyInclusionCommentFormAlter($form, $form_state);
+}
diff --git a/web/modules/custom/hoeringsportal_dialogue/hoeringsportal_dialogue.services.yml b/web/modules/custom/hoeringsportal_dialogue/hoeringsportal_dialogue.services.yml
index 87bc9bc9f..d71c90a31 100644
--- a/web/modules/custom/hoeringsportal_dialogue/hoeringsportal_dialogue.services.yml
+++ b/web/modules/custom/hoeringsportal_dialogue/hoeringsportal_dialogue.services.yml
@@ -7,3 +7,7 @@ services:
Drupal\hoeringsportal_dialogue\Theme\ThemeDialogueNegotiator:
tags:
- { name: theme_negotiator, priority: 10 }
+
+ Drupal\hoeringsportal_dialogue\EventSubscriber\AnonymousEditSubscriber:
+ tags:
+ - { name: event_subscriber }
diff --git a/web/modules/custom/hoeringsportal_dialogue/modules/hoeringsportal_dialogue_fixtures/src/Fixture/CommentFixture.php b/web/modules/custom/hoeringsportal_dialogue/modules/hoeringsportal_dialogue_fixtures/src/Fixture/CommentFixture.php
index beed2a813..a0abdda07 100644
--- a/web/modules/custom/hoeringsportal_dialogue/modules/hoeringsportal_dialogue_fixtures/src/Fixture/CommentFixture.php
+++ b/web/modules/custom/hoeringsportal_dialogue/modules/hoeringsportal_dialogue_fixtures/src/Fixture/CommentFixture.php
@@ -130,6 +130,22 @@ public function load() {
$comment->save();
$this->addReference('comment:early_inclusion_comment:8', $comment);
+
+ $comment = Comment::create([
+ 'comment_type' => 'early_inclusion_comment',
+ 'field_name' => 'field_comments',
+ ])
+ ->set('subject', '(No subject)')
+ ->set('entity_type', 'node')
+ ->set('entity_id', $this->getReference('node:dialogue_proposal:Test Dialogue proposal with name and email'))
+ ->set('uid', 0)
+ ->set('status', 1)
+ ->set('field_comment', 'Jeg er enig!')
+ ->set('name', 'Anders And')
+ ->set('mail', 'aand@andeby.dk');
+
+ $comment->save();
+ $this->addReference('comment:early_inclusion_comment:9', $comment);
}
/**
diff --git a/web/modules/custom/hoeringsportal_dialogue/modules/hoeringsportal_dialogue_fixtures/src/Fixture/DialogueFixture.php b/web/modules/custom/hoeringsportal_dialogue/modules/hoeringsportal_dialogue_fixtures/src/Fixture/DialogueFixture.php
index a162ac2bd..c238053ae 100644
--- a/web/modules/custom/hoeringsportal_dialogue/modules/hoeringsportal_dialogue_fixtures/src/Fixture/DialogueFixture.php
+++ b/web/modules/custom/hoeringsportal_dialogue/modules/hoeringsportal_dialogue_fixtures/src/Fixture/DialogueFixture.php
@@ -114,6 +114,50 @@ public function load() {
$node->save();
$this->addReference('node:dialogue:Test Dialogue - proposals simple, private', $node);
+
+ $node = Node::create([
+ 'type' => 'dialogue',
+ 'title' => 'Test Dialogue - name and email',
+ 'status' => TRUE,
+ 'field_teaser' => 'Test teaser',
+ 'field_area' => [
+ $this->getReference('area:Hele kommunen'),
+ ],
+ 'field_top_images' => [
+ $this->getReference('media:Large1'),
+ $this->getReference('media:Large2'),
+ $this->getReference('media:Large3'),
+ ],
+ 'field_type' => [
+ $this->getReference('type:Klima'),
+ ],
+ 'field_dialogue_proposal_category' => [
+ $this->getReference('dialogue_proposal_categories:Grønne pladser'),
+ $this->getReference('dialogue_proposal_categories:Biodiversitet Initiativer'),
+ $this->getReference('dialogue_proposal_categories:Cykelstier'),
+ $this->getReference('dialogue_proposal_categories:Regnvandsopsamling'),
+ $this->getReference('dialogue_proposal_categories:Parkeringspladser for elbiler'),
+ $this->getReference('dialogue_proposal_categories:Bæredygtig Belysning'),
+ $this->getReference('dialogue_proposal_categories:Energi Effektivisering'),
+ $this->getReference('dialogue_proposal_categories:Grønne Materialer'),
+ $this->getReference('dialogue_proposal_categories:Affaldshåndtering'),
+ $this->getReference('dialogue_proposal_categories:Vedvarende Energi'),
+ ],
+ 'field_dialogue_proposal_config' => [
+ ['value' => 'public_proposals'],
+ ['value' => 'use_email_on_proposals'],
+ ['value' => 'use_name_on_proposals'],
+ ['value' => 'use_email_on_proposal_comments'],
+ ['value' => 'use_name_on_proposal_comments'],
+ ],
+ 'field_content_sections' => [
+ 'target_id' => $paragraph->id(),
+ 'target_revision_id' => $paragraph->getRevisionId(),
+ ],
+ ]);
+
+ $node->save();
+ $this->addReference('node:dialogue:Test Dialogue - name and email', $node);
}
/**
diff --git a/web/modules/custom/hoeringsportal_dialogue/modules/hoeringsportal_dialogue_fixtures/src/Fixture/DialogueProposalFixture.php b/web/modules/custom/hoeringsportal_dialogue/modules/hoeringsportal_dialogue_fixtures/src/Fixture/DialogueProposalFixture.php
index 68c60d3eb..6ee5b4223 100644
--- a/web/modules/custom/hoeringsportal_dialogue/modules/hoeringsportal_dialogue_fixtures/src/Fixture/DialogueProposalFixture.php
+++ b/web/modules/custom/hoeringsportal_dialogue/modules/hoeringsportal_dialogue_fixtures/src/Fixture/DialogueProposalFixture.php
@@ -137,6 +137,22 @@ public function load() {
$node->save();
$this->addReference('node:dialogue_proposal:Test Dialogue proposal simple', $node);
+
+ $node = Node::create([
+ 'type' => 'dialogue_proposal',
+ 'title' => 'Test Dialogue proposal with name and email',
+ 'status' => TRUE,
+ 'field_dialogue_proposal_descr' => 'Jeg vil gerne stå ved mit forslag.',
+ 'field_dialogue_proposal_category' => [
+ $this->getReference('dialogue_proposal_categories:Grønne pladser'),
+ ],
+ 'field_dialogue' => $this->getReference('node:dialogue:Test Dialogue - name and email'),
+ 'field_owner_name' => 'J. von And',
+ 'field_owner_email' => 'jva@pengeby.dk',
+ ]);
+
+ $node->save();
+ $this->addReference('node:dialogue_proposal:Test Dialogue proposal with name and email', $node);
}
/**
diff --git a/web/modules/custom/hoeringsportal_dialogue/src/EventSubscriber/AnonymousEditSubscriber.php b/web/modules/custom/hoeringsportal_dialogue/src/EventSubscriber/AnonymousEditSubscriber.php
new file mode 100644
index 000000000..75b3a6f35
--- /dev/null
+++ b/web/modules/custom/hoeringsportal_dialogue/src/EventSubscriber/AnonymousEditSubscriber.php
@@ -0,0 +1,52 @@
+getEntity();
+ if ($entity instanceof CommentInterface && DialogueHelper::DIALOGUE_PROPOSAL_COMMENT_TYPE === $entity->bundle()) {
+ $event->setIsSupported();
+ if ($email = $entity->getAuthorEmail()) {
+ $event->getOwner()->email = $email;
+ }
+ if ($name = $entity->getAuthorName()) {
+ $event->getOwner()->name = $name;
+ }
+ }
+ elseif ($entity instanceof NodeInterface && DialogueHelper::DIALOGUE_PROPOSAL_TYPE === $entity->bundle()) {
+ $event->setIsSupported();
+ if ($email = $entity->get('field_owner_email')->getString()) {
+ $event->getOwner()->email = $email;
+ }
+ if ($name = $entity->get('field_owner_name')->getString()) {
+ $event->getOwner()->name = $name;
+ }
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getSubscribedEvents(): array {
+ return [
+ HoeringsportalAnonymousEditEvent::class => ['onHoeringsportalAnonymousEdit'],
+ ];
+ }
+
+}
diff --git a/web/modules/custom/hoeringsportal_dialogue/src/Helper/DialogueHelper.php b/web/modules/custom/hoeringsportal_dialogue/src/Helper/DialogueHelper.php
index 27306921e..610f0a67a 100644
--- a/web/modules/custom/hoeringsportal_dialogue/src/Helper/DialogueHelper.php
+++ b/web/modules/custom/hoeringsportal_dialogue/src/Helper/DialogueHelper.php
@@ -8,9 +8,11 @@
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Messenger\MessengerInterface;
+use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\node\Entity\Node;
+use Drupal\node\NodeInterface;
use Symfony\Component\HttpFoundation\RequestStack;
/**
@@ -18,6 +20,7 @@
*/
class DialogueHelper {
+ public const DIALOGUE_TYPE = 'dialogue';
public const DIALOGUE_PROPOSAL_TYPE = 'dialogue_proposal';
public const DIALOGUE_PROPOSAL_COMMENT_TYPE = 'early_inclusion_comment';
@@ -28,6 +31,8 @@ class DialogueHelper {
*
* @param \Symfony\Component\HttpFoundation\RequestStack $requestStack
* The request stack.
+ * @param \Drupal\Core\Routing\RouteMatchInterface $routeMatch
+ * The route match.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The enity type manager.
* @param \Drupal\Core\Session\AccountInterface $account
@@ -37,6 +42,7 @@ class DialogueHelper {
*/
public function __construct(
protected RequestStack $requestStack,
+ protected RouteMatchInterface $routeMatch,
protected EntityTypeManagerInterface $entityTypeManager,
protected AccountInterface $account,
protected MessengerInterface $messenger,
@@ -193,6 +199,14 @@ public function dialogueProposalFormAlter(array &$form, FormStateInterface $form
$form['field_location']['#access'] = FALSE;
}
+ if (!in_array('use_name_on_proposals', $config)) {
+ $form['field_owner_name']['#access'] = FALSE;
+ }
+
+ if (!in_array('use_email_on_proposals', $config)) {
+ $form['field_owner_email']['#access'] = FALSE;
+ }
+
$parentLocationSelection = $parent->get('field_dialogue_proposal_location')->getValue();
$parentPoint = json_decode($parentLocationSelection[0]['point'] ?? '');
@@ -237,6 +251,39 @@ public function formAlterSubmit(array &$form, FormStateInterface $form_state): v
}
}
+ /**
+ * Implements hook_form_FORMID_alter().
+ */
+ public function commentEarlyInclusionCommentFormAlter(array &$form, FormStateInterface $form_state) {
+ if (!isset($form['author'])) {
+ return;
+ }
+
+ $config = [];
+ // The comment form is shown on routes `entity.node.canonical` and the POST
+ // request (when creating a comment) is sent to `comment.reply`.
+ $node = $this->routeMatch->getParameter('node')
+ ?? $this->routeMatch->getParameter('entity');
+ if ($node instanceof NodeInterface && self::DIALOGUE_PROPOSAL_TYPE === $node->getType()) {
+ $parent = $node->get('field_dialogue')->referencedEntities()[0] ?? NULL;
+ if ($parent instanceof NodeInterface && self::DIALOGUE_TYPE === $parent->getType()) {
+ $config = $this->getProposalConfig($parent);
+ }
+ }
+
+ // Disable author fields apart from the ones explicitly enabled.
+ foreach ($form['author'] as $key => &$formPart) {
+ $disable = match ($key) {
+ 'name' => !in_array('use_name_on_proposal_comments', $config),
+ 'mail' => !in_array('use_email_on_proposal_comments', $config),
+ default => TRUE,
+ };
+ if ($disable) {
+ $formPart['#access'] = FALSE;
+ }
+ }
+ }
+
/**
* Get parent node.
*
@@ -382,7 +429,7 @@ private function getDialogueCommentChildren(Comment $comment, array &$children):
private function getDialogueIdFromFormState(FormStateInterface $form_state): ?int {
$userInput = $form_state->getUserInput();
- if ($userInput['dialogue_options']) {
+ if (isset($userInput['dialogue_options'])) {
$dialogueOptions = unserialize($userInput['dialogue_options']);
$originalUrlObject = \Drupal::service('path.validator')->getUrlIfValid($dialogueOptions['originalPath']);
diff --git a/web/sites/default/settings.php b/web/sites/default/settings.php
index 70c15886e..bd3e6ca8e 100644
--- a/web/sites/default/settings.php
+++ b/web/sites/default/settings.php
@@ -69,6 +69,9 @@
// Additions
// Allow calling `entity.toUrl`
'toUrl',
+ // and `entity.toLink`
+ 'toLink',
+ 'access',
];
// Local settings. These come last so that they can override anything.
diff --git a/web/themes/custom/hoeringsportal/hoeringsportal.theme b/web/themes/custom/hoeringsportal/hoeringsportal.theme
index a7a2a6a5c..5961c16dd 100755
--- a/web/themes/custom/hoeringsportal/hoeringsportal.theme
+++ b/web/themes/custom/hoeringsportal/hoeringsportal.theme
@@ -10,6 +10,7 @@ use Drupal\hoeringsportal_dialogue\Helper\DialogueHelper;
use Drupal\node\NodeInterface;
use Drupal\taxonomy\Entity\Term;
use Drupal\hoeringsportal_citizen_proposal\Helper\Helper as CitizenProposalHelper;
+use Drupal\hoeringsportal_anonymous_edit\Helper\Helper as AnonymousEditHelper;
/**
* Implements hook_preprocess().
@@ -19,6 +20,7 @@ function hoeringsportal_preprocess(&$vars) {
$vars['public_meeting_helper'] = \Drupal::service('hoeringsportal_public_meeting.public_meeting_helper');
$vars['citizen_proposal_helper'] = \Drupal::service(CitizenProposalHelper::class);
$vars['dialogue_helper'] = \Drupal::service(DialogueHelper::class);
+ $vars['anonymous_edit_helper'] = \Drupal::service(AnonymousEditHelper::class);
}
/**
diff --git a/web/themes/custom/hoeringsportal/templates/comment/comment.html.twig b/web/themes/custom/hoeringsportal/templates/comment/comment.html.twig
index b6d6870e6..ba2b9759a 100644
--- a/web/themes/custom/hoeringsportal/templates/comment/comment.html.twig
+++ b/web/themes/custom/hoeringsportal/templates/comment/comment.html.twig
@@ -81,6 +81,16 @@
{% if submitted and status is same as('published') %}
+ {# @todo #}
+ {% set owner = anonymous_edit_helper.getContentOwner(comment) %}
+ {% if owner and owner.name|default(false) %}
+