Skip to content

Commit 31dea62

Browse files
committed
Merge branch 'feature/early_inclusion_dialogue' into develop
2 parents c33c803 + 9ac21c2 commit 31dea62

10 files changed

Lines changed: 199 additions & 30 deletions

web/modules/custom/hoeringsportal_dialogue/src/Helper/DialogueHelper.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,12 @@ public function __construct(
5959
public function dialogueProposalCreateAccess(AccountInterface $account, array $context, string $entity_bundle): AccessResult {
6060
if ($this::DIALOGUE_PROPOSAL_TYPE === $entity_bundle) {
6161
$parentNode = $this->getParentNode();
62-
$config = $parentNode ? $this->getProposalConfig($parentNode) : [];
62+
63+
if (NULL === $parentNode) {
64+
return AccessResult::forbidden();
65+
}
66+
67+
$config = $this->getProposalConfig($parentNode);
6368

6469
if (!in_array('public_proposals', $config)) {
6570
return AccessResult::forbiddenIf($account->isAnonymous());
@@ -107,7 +112,7 @@ public function dialogueCommentUpdate(EntityInterface $comment): void {
107112
$this->getDialogueCommentChildren($comment, $children);
108113

109114
foreach ($children as $child) {
110-
$child->set('status', FALSE);
115+
$child->setUnpublished();
111116
$child->save();
112117
}
113118
}
@@ -201,7 +206,7 @@ public function formAlterSubmit(array &$form, FormStateInterface $form_state): v
201206
* @return \Drupal\Core\Entity\EntityInterface|null
202207
* The parent node.
203208
*/
204-
private function getParentNode(): ?EntityInterface {
209+
public function getParentNode(): ?EntityInterface {
205210
try {
206211
$parentId = $this->requestStack->getCurrentRequest()->query->get('dialogue');
207212
if ($parentId && is_numeric($parentId)) {
@@ -224,7 +229,7 @@ private function getParentNode(): ?EntityInterface {
224229
* @return array
225230
* the proposal config.
226231
*/
227-
private function getProposalConfig(EntityInterface $parent): array {
232+
public function getProposalConfig(EntityInterface $parent): array {
228233
/** @var \Drupal\node\NodeInterface $parent */
229234
$parentConfig = $parent->get('field_dialogue_proposal_config')->getValue();
230235

web/themes/custom/hoeringsportal/hoeringsportal.theme

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
use Drupal\Core\Form\FormStateInterface;
9+
use Drupal\hoeringsportal_dialogue\Helper\DialogueHelper;
910
use Drupal\node\NodeInterface;
1011
use Drupal\taxonomy\Entity\Term;
1112
use Drupal\hoeringsportal_citizen_proposal\Helper\Helper as CitizenProposalHelper;
@@ -17,6 +18,7 @@ function hoeringsportal_preprocess(&$vars) {
1718
$vars['hearing_helper'] = \Drupal::service('hoeringsportal_data.hearing_helper');
1819
$vars['public_meeting_helper'] = \Drupal::service('hoeringsportal_public_meeting.public_meeting_helper');
1920
$vars['citizen_proposal_helper'] = \Drupal::service(CitizenProposalHelper::class);
21+
$vars['dialogue_helper'] = \Drupal::service(DialogueHelper::class);
2022
}
2123

2224
/**
@@ -133,7 +135,13 @@ function hoeringsportal_theme_suggestions_form_element_alter(array &$suggestions
133135
if (!empty($variables['element']['#type'])) {
134136
$suggestions[] = 'form_element__' . $variables['element']['#type'];
135137
if (!empty($variables['element']['#name'])) {
136-
$suggestions[] = 'form_element__' . $variables['element']['#type'] . '__' . $variables['element']['#name'];
138+
if(!empty($variables['element']['#parents'])) {
139+
foreach ($variables['element']['#parents'] as $parent) {
140+
$suggestions[] = 'form_element__' . $variables['element']['#type'] . '__' . str_replace('-', '_',$parent);
141+
}
142+
}
143+
144+
$suggestions[] = 'form_element__' . $variables['element']['#type'] . '__' . str_replace('-', '_',$variables['element']['#name']);
137145
}
138146
}
139147
}
@@ -151,6 +159,15 @@ function hoeringsportal_theme_suggestions_input_alter(array &$suggestions, array
151159
$suggestions[] = 'input__submit__' . $variables['element']['#button_type'];
152160
}
153161
}
162+
163+
if ('checkbox' === $variables['element']['#type']) {
164+
$suggestions[] = 'input__' . $variables['element']['#type'];
165+
if (!empty($variables['element']['#parents'])) {
166+
foreach ($variables['element']['#parents'] as $parent) {
167+
$suggestions[] = 'input__' . $variables['element']['#type'] . '__' . str_replace('-', '_', $parent);
168+
}
169+
}
170+
}
154171
}
155172

156173
/**

web/themes/custom/hoeringsportal/templates/components/toggle-button.html.twig

Lines changed: 0 additions & 4 deletions
This file was deleted.

web/themes/custom/hoeringsportal/templates/content/node--dialogue-proposal--full.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<div class="row justify-content-center pt-5">
1111
<div class="proposal-layout">
1212
<div class="breadcrumb mb-3">
13-
<span class="me-2">{{ 'Early inclusion'|t }}</span>/
13+
<span class="me-2"><a href="/tidlig-inddragelse">{{ 'Early inclusion'|t }}</a></span>/
1414
<span class="mx-2">
1515
<a href="{{ path('entity.node.canonical', {node: node.field_dialogue.entity.id}) }}">{{ node.field_dialogue.entity.label }}</a>
1616
</span>/

web/themes/custom/hoeringsportal/templates/content/node--landing-page.html.twig

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
{% extends '@hoeringsportal/node/_node--1-col-large-image-top.html.twig' %}
22

33
{% block content_top %}
4-
{# Header #}
5-
{{ include(directory ~ '/templates/components/header-default.html.twig', {
6-
images: {0: node.field_media_image_single.entity.field_itk_media_image_upload.entity},
7-
category: content.field_header_label,
8-
title: node.label,
9-
description: content.field_teaser,
10-
tags_fields: {},
11-
image_half: true,
12-
shortcuts: {}}
13-
) }}
4+
{% if node.field_show_page_title.value %}
5+
{# Header #}
6+
{{ include(directory ~ '/templates/components/header-default.html.twig', {
7+
images: {0: node.field_media_image_single.entity.field_itk_media_image_upload.entity},
8+
category: content.field_header_label,
9+
title: node.label,
10+
description: content.field_teaser,
11+
tags_fields: {},
12+
image_half: true,
13+
shortcuts: {}}
14+
) }}
15+
{% endif %}
1416
{% endblock %}
1517

1618
{% block content_main %}

web/themes/custom/hoeringsportal/templates/form/form--node-dialogue-proposal-form.html.twig

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,23 @@
1313

1414
<div class="container-fluid bg-white">
1515
<div class="row justify-content-center pt-5">
16-
<form{{ attributes.addClass('proposal-layout') }}>
17-
<h1>{{ 'Create dialog proposal'|t }}</h1>
18-
<p>
19-
{{ 'Fill out the form and send your proposal so other people can interact with it.'|t }}
20-
</p>
21-
<div class="image-drag">
22-
{{ children }}
16+
<div class="proposal-layout">
17+
<div class="breadcrumb mb-3">
18+
<span class="me-2"><a href="/tidlig-inddragelse">{{ 'Early inclusion'|t }}</a></span>/
19+
<span class="mx-2">
20+
<a href="{{ path('entity.node.canonical', {node: dialogue_helper.getParentNode.id}) }}">{{ dialogue_helper.getParentNode.label }}</a>
21+
</span>/
22+
<span class="mx-2">{{ 'Create dialog proposal'|t }}</span>
2323
</div>
24-
</form>
24+
<form{{ attributes }}>
25+
<h1>{{ 'Create dialog proposal'|t }}</h1>
26+
<p>
27+
{{ 'Fill out the form and send your proposal so other people can interact with it.'|t }}
28+
</p>
29+
<div class="image-drag">
30+
{{ children }}
31+
</div>
32+
</form>
33+
</div>
2534
</div>
2635
</div>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{#
2+
/**
3+
* @file
4+
* Theme override for a form element.
5+
*
6+
* Available variables:
7+
* - attributes: HTML attributes for the containing element.
8+
* - errors: (optional) Any errors for this form element, may not be set.
9+
* - prefix: (optional) The form element prefix, may not be set.
10+
* - suffix: (optional) The form element suffix, may not be set.
11+
* - required: The required marker, or empty if the associated form element is
12+
* not required.
13+
* - type: The type of the element.
14+
* - name: The name of the element.
15+
* - label: A rendered label element.
16+
* - label_display: Label display setting. It can have these values:
17+
* - before: The label is output before the element. This is the default.
18+
* The label includes the #title and the required marker, if #required.
19+
* - after: The label is output after the element. For example, this is used
20+
* for radio and checkbox #type elements. If the #title is empty but the
21+
* field is #required, the label will contain only the required marker.
22+
* - invisible: Labels are critical for screen readers to enable them to
23+
* properly navigate through forms but can be visually distracting. This
24+
* property hides the label for everyone except screen readers.
25+
* - attribute: Set the title attribute on the element to create a tooltip but
26+
* output no label element. This is supported only for checkboxes and radios
27+
* in \Drupal\Core\Render\Element\CompositeFormElementTrait::preRenderCompositeFormElement().
28+
* It is used where a visual label is not needed, such as a table of
29+
* checkboxes where the row and column provide the context. The tooltip will
30+
* include the title and required marker.
31+
* - description: (optional) A list of description properties containing:
32+
* - content: A description of the form element, may not be set.
33+
* - attributes: (optional) A list of HTML attributes to apply to the
34+
* description content wrapper. Will only be set when description is set.
35+
* - description_display: Description display setting. It can have these values:
36+
* - before: The description is output before the element.
37+
* - after: The description is output after the element. This is the default
38+
* value.
39+
* - invisible: The description is output after the element, hidden visually
40+
* but available to screen readers.
41+
* - disabled: True if the element is disabled.
42+
* - title_display: Title display setting.
43+
*
44+
* @see template_preprocess_form_element()
45+
*/
46+
#}
47+
48+
{%
49+
set classes = [
50+
'js-form-item',
51+
'form-item',
52+
'form-type-' ~ type|clean_class,
53+
'js-form-type-' ~ type|clean_class,
54+
'form-item-' ~ name|clean_class,
55+
'js-form-item-' ~ name|clean_class,
56+
title_display not in ['after', 'before'] ? 'form-no-label',
57+
disabled == 'disabled' ? 'form-disabled',
58+
errors ? 'form-item--error',
59+
'btn-toggle'
60+
]
61+
%}
62+
{%
63+
set description_classes = [
64+
'description',
65+
description_display == 'invisible' ? 'visually-hidden',
66+
]
67+
%}
68+
69+
<div{{ attributes.addClass(classes) }}>
70+
{{ children }}
71+
<label class="btn toggle-badge option" for="{{ element['#id'] }}">{{ label['#title'] }}</label>
72+
</div>

web/themes/custom/hoeringsportal/templates/form/form-element--checkbox.html.twig

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,55 @@
4444
* @see template_preprocess_form_element()
4545
*/
4646
#}
47-
{% extends 'themes/custom/hoeringsportal/templates/components/toggle-button.html.twig' %}
47+
{%
48+
set classes = [
49+
'js-form-item',
50+
'form-item',
51+
'mb-3',
52+
'js-form-type-' ~ type|clean_class,
53+
'form-item-' ~ name|clean_class,
54+
'js-form-item-' ~ name|clean_class,
55+
title_display not in ['after', 'before'] ? 'form-no-label',
56+
disabled == 'disabled' ? 'form-disabled',
57+
errors ? 'form-item--error',
58+
]
59+
%}
60+
{%
61+
set description_classes = [
62+
'description',
63+
'text-muted',
64+
description_display == 'invisible' ? 'visually-hidden',
65+
]
66+
%}
67+
<div{{ attributes.addClass(classes) }}>
68+
{% if label_display in ['before', 'invisible'] %}
69+
{{ label }}
70+
{% endif %}
71+
{% if prefix is not empty %}
72+
<span class="field-prefix">{{ prefix }}</span>
73+
{% endif %}
74+
{% if description_display == 'before' and description.content %}
75+
<div{{ description.attributes }}>
76+
{{ description.content }}
77+
</div>
78+
{% endif %}
79+
{{ children }}
80+
{% if suffix is not empty %}
81+
<span class="field-suffix">{{ suffix }}</span>
82+
{% endif %}
83+
{% if label_display == 'after' %}
84+
{{ label }}
85+
{% endif %}
86+
{% if errors %}
87+
<div class="form-item--error-message">
88+
{{ errors }}
89+
</div>
90+
{% endif %}
91+
{% if description_display in ['after', 'invisible'] and description.content %}
92+
<div>
93+
<small{{ description.attributes.addClass(description_classes) }}>
94+
{{ description.content }}
95+
</small>
96+
</div>
97+
{% endif %}
98+
</div>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{#
2+
/**
3+
* @file
4+
* Theme override for an 'input' #type form element.
5+
*
6+
* Available variables:
7+
* - attributes: A list of HTML attributes for the input element.
8+
* - children: Optional additional rendered elements.
9+
*
10+
* @see template_preprocess_input()
11+
*/
12+
#}
13+
<input{{ attributes.addClass('btn-check form-checkbox') }} />{{ children }}

web/themes/custom/hoeringsportal/templates/views/views-view--dialogue-proposals.html.twig

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@
5050

5151
<div class="d-flex justify-content-between">
5252
{{ exposed }}
53-
<div><a href="{{ path('node.add', {node_type: 'dialogue_proposal', dialogue: view.args[0]}) }}" class="btn btn-primary btn-sm rounded-2">{{ 'Participate with your proposal'|t }}</a></div>
53+
{% set node = drupal_entity('node', view.args[0])['#node'] %}
54+
{% set proposalConfig = dialogue_helper.getProposalConfig(node) %}
55+
{% if 'public_proposals' in proposalConfig %}
56+
<div><a href="{{ path('node.add', {node_type: 'dialogue_proposal', dialogue: view.args[0]}) }}" class="btn btn-primary btn-sm rounded-2">{{ 'Participate with your proposal'|t }}</a></div>
57+
{% endif %}
5458
</div>
5559
{{ attachment_before }}
5660

0 commit comments

Comments
 (0)