### Install mkcert for Local HTTPS Source: https://github.com/danskernesdigitalebibliotek/dpl-cms/blob/develop/docs/local-development.md Installs mkcert on the host machine to generate and install a root certificate for local HTTPS development. For Mac users, it can be installed via Homebrew. ```bash # Install mkcert globally mkcert -install # (Mac only) Create symbolic link for mkcert root CA mkdir -p ~/.local/share && ln -s "$(mkcert -CAROOT)" ~/.local/share ``` -------------------------------- ### Install new site from scratch using Drush Source: https://github.com/danskernesdigitalebibliotek/dpl-cms/blob/develop/docs/configuration-management.md Installs a new DPL CMS site using existing configuration. This command is typically run once during the initial setup of a site. ```bash drush site-install --existing-config -y ``` -------------------------------- ### Development Workflow: Local Setup Source: https://context7.com/danskernesdigitalebibliotek/dpl-cms/llms.txt Instructions for setting up a local development environment using Docker and task automation. This includes cloning the repository, configuring environment variables, and running initial setup commands. ```APIDOC ## Development Workflow: Local Setup ### Description Guides users through the process of establishing a local development environment for the DPL CMS project. It leverages Docker and `go-task` for simplified setup, dependency management, and routine development tasks. ### Prerequisites - Docker - Docker Compose - go-task (https://taskfile.dev) ### Steps 1. **Clone the repository:** ```bash git clone https://github.com/danskernesdigitalebibliotek/dpl-cms.git cd dpl-cms ``` 2. **Copy environment configuration:** ```bash cp .env.example .env ``` 3. **Perform a full reset and setup:** This command initializes the environment, including creating containers, installing dependencies, and importing configuration. ```bash task dev:reset ``` *This command executes:* - `docker compose up -d` - `composer install` - `drush site:install` - `drush config:import` - `drush cache:rebuild` 4. **Watch for file changes and auto-clear cache:** To enable automatic cache clearing upon file modifications. ```bash task dev:watch ``` 5. **Run commands in the CLI container:** Execute Drupal-specific commands within the running Docker container. ```bash task dev:cli -- drush status task dev:cli -- drush user:login task dev:cli -- composer require drupal/new_module ``` 6. **Enable BNF multi-site development (Optional):** For enabling and developing with the BNF multi-site feature. ```bash task dev:bnf:enable task dev:reset task dev:bnf:watch ``` ### Accessing Sites - **Default site:** `http://localhost:8080` - **BNF site:** `http://localhost:8081` - **Mailhog:** `http://localhost:8025` - **Varnish:** `http://localhost:8080` ``` -------------------------------- ### Manually Install OpenAPIClient-php Source: https://github.com/danskernesdigitalebibliotek/dpl-cms/blob/develop/packages/fbs-client/README.md This snippet demonstrates how to manually install the OpenAPIClient-php library by downloading the files and including the autoloader. Ensure you replace '/path/to/OpenAPIClient-php/' with the actual path to your downloaded library. ```php task lagoon:backup:restore ``` -------------------------------- ### Run Lighthouse Performance Testing Source: https://context7.com/danskernesdigitalebibliotek/dpl-cms/llms.txt Installs the Lighthouse CI command-line interface globally and then runs an automated performance audit. Lighthouse provides metrics and suggestions for improving website performance. ```bash # Lighthouse performance testing npm install -g @lhci/cli lhci autorun ``` -------------------------------- ### GET /opening_hours/instances Source: https://github.com/danskernesdigitalebibliotek/dpl-cms/blob/develop/packages/cms-api/README.md Lists all opening hours for the legacy API. This endpoint provides access to opening hours data compatible with the legacy API. ```APIDOC ## GET /opening_hours/instances ### Description List all opening hours for legacy API. ### Method GET ### Endpoint /opening_hours/instances ### Parameters (No parameters documented for this endpoint in the provided text) ### Request Example (No request body for GET operations) ### Response #### Success Response (200) - **array** - A list of all opening hours entries. #### Response Example { "example": "response body" } ``` -------------------------------- ### Run OpenAPI Server Unit Tests Source: https://github.com/danskernesdigitalebibliotek/dpl-cms/blob/develop/packages/cms-api/README.md Commands to execute the unit tests for the generated OpenAPI Server bundle. This involves installing dependencies with Composer and then running the PHPUnit test suite. ```bash composer install ./vendor/bin/phpunit ``` -------------------------------- ### Restore Database Snapshot Locally Source: https://github.com/danskernesdigitalebibliotek/dpl-cms/blob/develop/docs/local-development.md Restores a specific database snapshot from a Lagoon environment to the local DPL CMS setup. This process involves obtaining a .sql dump file, placing it in the 'restore/database' directory, resetting the local environment, and then running the restore task. ```bash task dev:reset task dev:restore:database ``` -------------------------------- ### Restore Files Snapshot Locally Source: https://github.com/danskernesdigitalebibliotek/dpl-cms/blob/develop/docs/local-development.md Restores a specific files snapshot from a Lagoon environment to the local DPL CMS setup. This involves obtaining a .tar.gz backup file, placing it in the 'files-backup' directory, resetting the local environment, and then running the restore task. ```bash task dev:reset task dev:restore:files ``` -------------------------------- ### Implement OpenAPI API Interface in PHP Source: https://github.com/danskernesdigitalebibliotek/dpl-cms/blob/develop/packages/cms-api/README.md Provides an example of implementing the autogenerated `DefaultApiInterface` for the OpenAPI Server. This includes setting up API key and OAuth2 authorization, and implementing specific API operations like `campaignMatchPOST`. ```php getParameter('serializer.formats'), $container->get('logger.factory')->get('rest') ); $instance->patronService = $container->get('dpl_patron.service'); $instance->currentUser = $container->get('current_user'); return $instance; } /** * Responds to GET requests. */ public function get(string $patron_id): ResourceResponse { // Check access if (!$this->currentUser->hasPermission('view patron information')) { throw new AccessDeniedHttpException('Insufficient permissions to view patron information'); } // Verify user can only access their own data if ($this->currentUser->id() != $patron_id && !$this->currentUser->hasPermission('administer patrons')) { throw new AccessDeniedHttpException('Cannot access other patron information'); } // Fetch patron data $patron_data = $this->patronService->getPatronInfo($patron_id); if (!$patron_data) { throw new NotFoundHttpException("Patron with ID {$patron_id} not found"); } // Build response $response_data = [ 'id' => $patron_data['id'], 'name' => $patron_data['name'], 'email' => $patron_data['email'], 'loans_count' => count($patron_data['loans']), 'reservations_count' => count($patron_data['reservations']), ]; $response = new ResourceResponse($response_data); $response->addCacheableDependency($patron_data['cache_metadata']); return $response; } } ``` -------------------------------- ### Manage Opening Hours API (Bash) Source: https://context7.com/danskernesdigitalebibliotek/dpl-cms/llms.txt This API endpoint manages library opening hours, supporting both single instances and weekly repetitions across multiple branches. It accepts a POST request with a JSON payload specifying times, dates, branch ID, and repetition rules. The response includes all created instances. ```bash # Create or update opening hours with weekly repetition curl -X POST "http://localhost:8080/api/v1/opening_hours?_format=json" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer " \ -d '{ "id": null, "category": { "title": "Open", "color": "#00AA00" }, "date": "2025-01-20", "start_time": "09:00", "end_time": "17:00", "branch_id": 101, "repetition": { "type": "weekly", "weekly_data": { "end_date": "2025-06-20" } } }' # Response 200 OK - Returns all created instances [ { "id": 5001, "category": { "title": "Open", "color": "#00AA00" }, "date": "2025-01-20", "start_time": "09:00", "end_time": "17:00", "branch_id": 101, "repetition": { "id": 789, "type": "weekly", "weekly_data": { "end_date": "2025-06-20" } } }, { "id": 5002, "category": { "title": "Open", "color": "#00AA00" }, "date": "2025-01-27", "start_time": "09:00", "end_time": "17:00", "branch_id": 101, "repetition": { "id": 789, "type": "weekly" } } // ... additional weekly instances until end_date ] ``` -------------------------------- ### Development Workflow: Testing and Quality Checks Source: https://context7.com/danskernesdigitalebibliotek/dpl-cms/llms.txt Details on running various automated tests and quality assurance checks, including PHPUnit, static analysis, code style checks, end-to-end tests with Cypress, and accessibility/performance audits. ```APIDOC ## Development Workflow: Running Tests and Quality Checks ### Description Provides a comprehensive guide to executing various testing and quality assurance tasks within the DPL CMS project. This includes unit testing, static code analysis, code style enforcement, end-to-end testing, and accessibility/performance audits. ### Unit and Integration Testing - **PHPUnit tests:** ```bash task dev:cli -- vendor/bin/phpunit --testdox web/modules/custom/dpl_campaign/tests ``` ### Static Code Analysis - **PHPStan:** ```bash task dev:cli -- vendor/bin/phpstan analyse web/modules/custom/dpl_patron ``` ### Code Style and Standards - **PHP_CodeSniffer (Drupal coding standards):** ```bash task dev:cli -- vendor/bin/phpcs --standard=Drupal web/modules/custom/dpl_patron ``` - **PHP CS Fixer (auto-fix coding standards):** ```bash task dev:cli -- vendor/bin/phpcbf --standard=Drupal web/modules/custom/dpl_patron ``` - **Twig CS Fixer:** ```bash task dev:cli -- vendor/bin/twig-cs-fixer lint web/themes/custom/novel ``` ### End-to-End Testing (Cypress) 1. **Install dependencies:** ```bash npm install ``` 2. **Set base URL:** ```bash export CYPRESS_BASE_URL=http://localhost:8080 ``` 3. **Run all tests:** ```bash npx cypress run ``` 4. **Run a specific test suite:** ```bash npx cypress run --spec "cypress/e2e/authentication/**/*" ``` 5. **Run interactive test runner:** ```bash npx cypress open ``` ### Accessibility Testing - **pa11y (CI mode):** ```bash npm run pa11y:ci ``` ### Performance Testing - **Lighthouse CI (LHCI):** ```bash npm install -g @lhci/cli lhci autorun ``` ### Documentation Linting - **Markdownlint CLI2:** ```bash npx markdownlint-cli2 "docs/**/*.md" ``` ### OpenAPI Validation - **Swagger CLI:** ```bash npx @apidevtools/swagger-cli validate openapi.json ``` ``` -------------------------------- ### Attaching DPL React App and Rendering Mount Point (PHP) Source: https://context7.com/danskernesdigitalebibliotek/dpl-cms/llms.txt Demonstrates how to attach the custom DPL React application library and its configuration to a Drupal render array. It also shows how to render the mount point element (a div) for the React application, passing initial data as attributes. This is typically used within a Drupal controller or theme template. ```php // Usage in template or controller $config = \Drupal::service('dpl_custom_app.settings'); $build['#attached']['library'][] = 'dpl_custom_app/dpl_custom_app'; $build['#attached']['drupalSettings']['dplReact']['customApp'] = $config->getConfig(); // Render React mount point $build['content'] = [ '#type' => 'html_tag', '#tag' => 'div', '#attributes' => [ 'id' => 'dpl-react-custom-app', 'data-library-name' => $config->getConfig()['library-name'], 'data-api-endpoint' => $config->getConfig()['api-endpoint'], ], ]; ``` -------------------------------- ### Run Cypress End-to-End Tests Source: https://context7.com/danskernesdigitalebibliotek/dpl-cms/llms.txt Installs npm dependencies and runs Cypress end-to-end tests for the DPL CMS. It sets the `CYPRESS_BASE_URL` environment variable and executes tests using `npx cypress run`. Commands for running specific test suites or opening the interactive runner are also included. ```bash # Cypress end-to-end tests npm install export CYPRESS_BASE_URL=http://localhost:8080 npx cypress run # Run specific test suite npx cypress run --spec "cypress/e2e/authentication/**/*" # Interactive Cypress test runner npx cypress open ``` -------------------------------- ### Uninstall a module using Drupal update hook (PHP) Source: https://github.com/danskernesdigitalebibliotek/dpl-cms/blob/develop/docs/configuration-management.md Demonstrates how to uninstall a Drupal module within an update hook. This is used for removing modules as part of a DPL CMS installation profile update. ```php function dpl_cms_update_9001() { \Drupal::service('module_installer')->uninstall(['shortcut']); } ``` -------------------------------- ### Configure Lagoon CLI Instance Source: https://github.com/danskernesdigitalebibliotek/dpl-cms/blob/develop/docs/lagoon-environments.md This command configures the Lagoon CLI to connect to a specific Lagoon instance. It requires the instance name, hostname, SSH port, GraphQL endpoint, and UI URL. Ensure you have the correct details from the DPL Platform documentation. ```sh lagoon config add \ --lagoon [instance name e.g. "dpl-platform"] \ --hostname [host to connect to with SSH] \ --port [SSH port] \ --graphql [url to GraphQL endpoint] \ --ui [url to UI] \ ``` -------------------------------- ### Enable a module using Drupal update hook (PHP) Source: https://github.com/danskernesdigitalebibliotek/dpl-cms/blob/develop/docs/configuration-management.md Demonstrates how to enable a Drupal module within an update hook. This is necessary for enabling modules as part of a DPL CMS installation profile update. ```php function dpl_update_update_9000() { \Drupal::service('module_installer')->install(['shortcut']); } ```