Skip to content

Commit 71a44cc

Browse files
authored
Merge pull request #608 from itk-dev/feature/timeline-fixtures
Add timeline fixtures with demo project
2 parents 083e843 + a6054a7 commit 71a44cc

1 file changed

Lines changed: 107 additions & 0 deletions

File tree

web/modules/custom/hoeringsportal_project/modules/hoeringsportal_project_fixtures/src/Fixture/ProjectMainPageFixture.php

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@
55
use Drupal\content_fixtures\Fixture\AbstractFixture;
66
use Drupal\content_fixtures\Fixture\DependentFixtureInterface;
77
use Drupal\content_fixtures\Fixture\FixtureGroupInterface;
8+
use Drupal\hoeringsportal_base_fixtures\Fixture\DecisionFixture;
89
use Drupal\hoeringsportal_base_fixtures\Fixture\MediaFixture;
910
use Drupal\hoeringsportal_base_fixtures\Fixture\ParagraphFixture;
11+
use Drupal\hoeringsportal_base_fixtures\Fixture\PublicMeetingFixture;
1012
use Drupal\hoeringsportal_base_fixtures\Fixture\TermAreaFixture;
13+
use Drupal\hoeringsportal_dialogue_fixtures\Fixture\DialogueFixture;
14+
use Drupal\hoeringsportal_hearing_fixtures\Fixture\HearingFixture;
1115
use Drupal\node\Entity\Node;
16+
use Drupal\node\NodeInterface;
1217
use Drupal\paragraphs\Entity\Paragraph;
1318
use Drupal\path_alias\Entity\PathAlias;
1419
use Drupal\pathauto\PathautoState;
@@ -113,6 +118,104 @@ public function load() {
113118
]);
114119

115120
$entity->save();
121+
122+
// Create Timeline Demo Project with timeline enabled.
123+
$timelineProject = Node::create([
124+
'type' => 'project_main_page',
125+
])
126+
->setTitle('Timeline Demo Project')
127+
->set('field_project_category', [
128+
$this->getReference('project_categories:Byudvikling'),
129+
])
130+
->set('field_short_description', 'A project demonstrating the timeline feature with various content types and notes.')
131+
->set('field_project_image', [
132+
['target_id' => $this->getReference('media:Medium1')->id()],
133+
])
134+
->set('field_area', [
135+
$this->getReference('area:Hele kommunen'),
136+
])
137+
->set('field_show_timeline', TRUE);
138+
139+
// Add timeline note paragraphs.
140+
$notes = [
141+
[
142+
'title' => 'Projektstart',
143+
'subtitle' => 'Opstart af projekt',
144+
'date' => (new \DateTimeImmutable('-6 months'))->format('Y-m-d'),
145+
'note' => 'Projektet er officielt startet med en indledende undersøgelse af området.',
146+
],
147+
[
148+
'title' => 'Første fase afsluttet',
149+
'subtitle' => 'Analyse gennemført',
150+
'date' => (new \DateTimeImmutable('-3 months'))->format('Y-m-d'),
151+
'note' => 'Den indledende analyse er nu gennemført og resultaterne er klar.',
152+
],
153+
[
154+
'title' => 'Planlagt borgermøde',
155+
'subtitle' => 'Kommende aktivitet',
156+
'date' => (new \DateTimeImmutable('+3 months'))->format('Y-m-d'),
157+
'note' => 'Der planlægges et borgermøde for at præsentere de foreløbige resultater.',
158+
],
159+
[
160+
'title' => 'Forventet afslutning',
161+
'subtitle' => 'Projektmål',
162+
'date' => (new \DateTimeImmutable('+6 months'))->format('Y-m-d'),
163+
'note' => 'Projektet forventes afsluttet med en endelig rapport og anbefalinger.',
164+
],
165+
];
166+
167+
foreach ($notes as $noteData) {
168+
$paragraph = Paragraph::create([
169+
'type' => 'timeline_note',
170+
])
171+
->set('field_title', $noteData['title'])
172+
->set('field_subtitle', $noteData['subtitle'])
173+
->set('field_date', $noteData['date'])
174+
->set('field_note', $noteData['note']);
175+
$paragraph->save();
176+
177+
$timelineProject->field_timeline->appendItem([
178+
'target_id' => $paragraph->id(),
179+
'target_revision_id' => $paragraph->getRevisionId(),
180+
]);
181+
}
182+
183+
$timelineProject->save();
184+
$this->addReference('node:project_main_page:timeline_demo', $timelineProject);
185+
186+
// Update existing nodes to reference this project for timeline display.
187+
$this->updateNodeProjectReference('node:hearing:Hearing1', $timelineProject, '-2 months');
188+
$this->updateNodeProjectReference('node:dialogue:Test Dialogue - proposals full', $timelineProject);
189+
$this->updateNodeProjectReference('node:decision:En vigtig afgørelse', $timelineProject, '-1 month');
190+
$this->updateNodeProjectReference('public_meeting:fixture-1', $timelineProject);
191+
}
192+
193+
/**
194+
* Update a node to reference a project for timeline display.
195+
*
196+
* @param string $reference
197+
* The fixture reference key for the node.
198+
* @param \Drupal\node\NodeInterface $project
199+
* The project node to reference.
200+
* @param string|null $dateModifier
201+
* Optional date modifier string (e.g. '-2 months') to set the node's date.
202+
*/
203+
private function updateNodeProjectReference(string $reference, NodeInterface $project, ?string $dateModifier = NULL): void {
204+
$node = $this->getReference($reference);
205+
$node->set('field_project_reference', ['target_id' => $project->id()]);
206+
$node->set('field_hide_in_timeline', FALSE);
207+
208+
if ($dateModifier !== NULL) {
209+
$date = (new \DateTimeImmutable($dateModifier))->format('Y-m-d\TH:i:s');
210+
if ($node->hasField('field_start_date')) {
211+
$node->set('field_start_date', $date);
212+
}
213+
if ($node->hasField('field_decision_date')) {
214+
$node->set('field_decision_date', $date);
215+
}
216+
}
217+
218+
$node->save();
116219
}
117220

118221
/**
@@ -126,6 +229,10 @@ public function getDependencies() {
126229
ParagraphFixture::class,
127230
ProjectPageFixture::class,
128231
TermAreaFixture::class,
232+
HearingFixture::class,
233+
DialogueFixture::class,
234+
DecisionFixture::class,
235+
PublicMeetingFixture::class,
129236
];
130237
}
131238

0 commit comments

Comments
 (0)