customer-riverside/web/modules/custom/riverside_pt/riverside_pt.install
Mork Swork ed6ff4fbf6 Add front page, nav rebuild, and CI workflow
- Home controller with hero and services sections
- Nav rebuilt on install: Home, Services, About, FAQ, Contact (CTA), Book An Appointment (CTA)
- Entrypoint uses IS_SETUP check so failed installs retry on restart
- Gitea Actions workflow builds and pushes multi-arch image to forge.quinefoundation.com

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 20:05:46 -07:00

202 lines
6.7 KiB
Text

<?php
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\menu_link_content\Entity\MenuLinkContent;
use Drupal\path_alias\Entity\PathAlias;
use Drupal\user\Entity\Role;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Entity\FieldConfig;
function riverside_pt_install() {
array_walk([
// Appointment
NodeType::create([
'type' => 'appointment',
'name' => 'Appointment',
'description' => 'A booking between a Patient and a Provider at a particular time.',
'new_revision' => FALSE,
'display_submitted' => FALSE,
]),
FieldStorageConfig::create([
'field_name' => 'field_appointment_date',
'entity_type' => 'node',
'type' => 'datetime',
'settings' => ['datetime_type' => 'datetime'],
]),
FieldStorageConfig::create([
'field_name' => 'field_duration_minutes',
'entity_type' => 'node',
'type' => 'integer',
]),
FieldStorageConfig::create([
'field_name' => 'field_service_type',
'entity_type' => 'node',
'type' => 'list_string',
'settings' => [
'allowed_values' => [
'diagnostic' => 'Diagnostic',
'sports_rehab' => 'Sports Rehab',
'pre_post_surgical_rehab' => 'Pre/Post-Surgical Rehab',
'neurological_pt' => 'Neurological PT',
],
],
]),
FieldStorageConfig::create([
'field_name' => 'field_provider',
'entity_type' => 'node',
'type' => 'entity_reference',
'settings' => ['target_type' => 'user'],
]),
FieldConfig::create([
'field_name' => 'field_appointment_date',
'entity_type' => 'node',
'bundle' => 'appointment',
'label' => 'Appointment Date',
'required' => TRUE,
]),
FieldConfig::create([
'field_name' => 'field_duration_minutes',
'entity_type' => 'node',
'bundle' => 'appointment',
'label' => 'Duration (Minutes)',
'required' => TRUE,
]),
FieldConfig::create([
'field_name' => 'field_service_type',
'entity_type' => 'node',
'bundle' => 'appointment',
'label' => 'Service Type',
'required' => TRUE,
]),
FieldConfig::create([
'field_name' => 'field_provider',
'entity_type' => 'node',
'bundle' => 'appointment',
'label' => 'Provider',
'required' => TRUE,
'settings' => [
'handler' => 'default:user',
'handler_settings' => [
'filter' => [
'type' => '_role',
'role' => ['provider' => 'provider'],
],
],
],
]),
// Provider
Role::create([
'id' => 'provider',
'label' => 'Provider',
]),
// Provider Availability
NodeType::create([
'type' => 'provider_availability',
'name' => 'Provider Availability',
'description' => 'A window of time during which a Provider is available for appointments.',
'new_revision' => FALSE,
'display_submitted' => FALSE,
]),
FieldStorageConfig::create([
'field_name' => 'field_start_datetime',
'entity_type' => 'node',
'type' => 'datetime',
'settings' => ['datetime_type' => 'datetime'],
]),
FieldStorageConfig::create([
'field_name' => 'field_end_datetime',
'entity_type' => 'node',
'type' => 'datetime',
'settings' => ['datetime_type' => 'datetime'],
]),
FieldConfig::create([
'field_name' => 'field_provider',
'entity_type' => 'node',
'bundle' => 'provider_availability',
'label' => 'Provider',
'required' => TRUE,
'settings' => [
'handler' => 'default:user',
'handler_settings' => [
'filter' => [
'type' => '_role',
'role' => ['provider' => 'provider'],
],
],
],
]),
FieldConfig::create([
'field_name' => 'field_start_datetime',
'entity_type' => 'node',
'bundle' => 'provider_availability',
'label' => 'Start',
'required' => TRUE,
]),
FieldConfig::create([
'field_name' => 'field_end_datetime',
'entity_type' => 'node',
'bundle' => 'provider_availability',
'label' => 'End',
'required' => TRUE,
]),
], fn($entity) => $entity->save());
try {
_riverside_pt_build_navigation();
}
catch (\Exception $e) {
\Drupal::logger('riverside_pt')->error('Navigation setup failed: @msg', ['@msg' => $e->getMessage()]);
}
\Drupal::configFactory()->getEditable('system.site')
->set('page.front', '/home')
->save();
}
function _riverside_pt_build_navigation(): void {
$em = \Drupal::entityTypeManager();
// Remove whatever links Standard profile put in the main menu.
foreach ($em->getStorage('menu_link_content')->loadByProperties(['menu_name' => 'main']) as $link) {
$link->delete();
}
// Create placeholder basic pages.
foreach (['Services', 'About', 'FAQ', 'Contact'] as $title) {
$existing = $em->getStorage('node')->loadByProperties(['title' => $title, 'type' => 'page']);
if ($existing) {
continue;
}
$node = Node::create(['type' => 'page', 'title' => $title, 'status' => 1]);
$node->save();
PathAlias::create([
'path' => '/node/' . $node->id(),
'alias' => '/' . strtolower($title),
'langcode' => 'en',
])->save();
}
// Build the primary navigation.
$defs = [
['title' => 'Home', 'uri' => 'route:<front>', 'weight' => 0, 'class' => NULL],
['title' => 'Services', 'uri' => 'internal:/services', 'weight' => 1, 'class' => NULL],
['title' => 'About', 'uri' => 'internal:/about', 'weight' => 2, 'class' => NULL],
['title' => 'FAQ', 'uri' => 'internal:/faq', 'weight' => 3, 'class' => NULL],
['title' => 'Contact', 'uri' => 'internal:/contact', 'weight' => 4, 'class' => 'nav-cta'],
['title' => 'Book An Appointment', 'uri' => 'internal:/schedule', 'weight' => 5, 'class' => 'nav-cta nav-cta--primary'],
];
foreach ($defs as $def) {
$options = $def['class'] ? ['attributes' => ['class' => explode(' ', $def['class'])]] : [];
MenuLinkContent::create([
'title' => $def['title'],
'link' => ['uri' => $def['uri'], 'options' => $options],
'menu_name' => 'main',
'weight' => $def['weight'],
'enabled' => TRUE,
])->save();
}
}