# Automation Scripts

This directory contains PHP scripts used to automate the setup and data population for the Compas site. These scripts are designed to be executed via Drush.

## Usage

To run any of these scripts, use the following command format:

```bash
ddev drush --uri=compas.ddev.site scr scripts/[filename].php
```

## Files

### 1. `create_exam_fields.php`
*   **Purpose:** Creates the **Exam** content type, the **Exam Type** taxonomy vocabulary, and all necessary custom fields (Dates, Fee, Image, Link).
*   **Notes:** This was created to handle the initial data architecture setup when browser tools were unavailable.

### 2. `create_service_view.php`
*   **Purpose:** Programmatically creates the **Services** view, which generates the `/service` page listing the exams.
*   **Notes:** It configures the fields, sorting, and page path for the service listing.

### 3. `create_test_nodes.php`
*   **Purpose:** Generates dummy "Exam" content and taxonomy terms.
*   **Notes:** Use this to quickly populate the site with test data.

### 4. `add_taxonomy_image.php`
*   **Purpose:** Adds an Image field to the "Exam Type" taxonomy vocabulary.
*   **Notes:** Supporting field for overview card images.

### 5. `create_split_views.php`
*   **Purpose:** Creates the two-level view structure: `services` (Overview) and `exam_listing` (Detail).
*   **Notes:** Sets up the foundational display logic for the /service and /service/% paths.

### 6. `refine_services_view.php`
*   **Purpose:** Adds the "Availability Indicator" logic to the Services overview view.
*   **Notes:** Uses relationships and aggregation to count upcoming exams per type.

### 7. `rebuild_services_view.php`
*   **Purpose:** Rebuilds/updates the Services view configuration.

### 8. `enable_taxonomy_form_field.php`
*   **Purpose:** Enables form display fields on taxonomy terms.

### 9. `allow_svg_images.php`
*   **Purpose:** Adds SVG file extension support to image fields.

### 10. `inspect_service_page.php`
*   **Purpose:** Diagnostic script to inspect the /service page configuration.

### 11. `update_exam_listing_view.php`
*   **Purpose:** Recreates the `exam_listing` view with two block displays: **Upcoming Exams** and **Past Exams**. Also adds `field_exam_type` to the "page" content type and sets exam type references on the landing page nodes.
*   **Notes:** The blocks use a contextual filter that automatically reads the exam type from the current node's `field_exam_type` field.

### 12. `fix_services_view_links.php`
*   **Purpose:** Updates the Services overview view so exam type names link to their corresponding page nodes.
*   **Notes:** Adds a reverse entity reference relationship and rewrites the term name as a link.
