|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +## #ddev-generated |
| 4 | +## Description: Add some convenience extras for development. |
| 5 | +## Usage: xb-dev-extras |
| 6 | +## Example: ddev xb-dev-extras\nddev xb-dev-extras --dry-run |
| 7 | +## Aliases: extras |
| 8 | +## Flags: [{"Name":"dry-run","Usage":"Show what the command will do if run"}] |
| 9 | + |
| 10 | +# If the '--dry-run' flag is passed, show what the command would do and then exit. |
| 11 | +if [[ "$1" == "--dry-run" ]]; then |
| 12 | + echo "This command will... |
| 13 | + 1. Install the following modules: |
| 14 | + - Admin Toolbar (admin_toolbar) |
| 15 | + - Admin Toolbar (admin_toolbar_tools) |
| 16 | + - Coffee (coffee) |
| 17 | + - \"All-Props\" Test SDC (sdc_test_all_props) |
| 18 | + 2. Create a test page at '/test'." |
| 19 | + exit 0 |
| 20 | +fi |
| 21 | + |
| 22 | +# Add the modules to the codebase. |
| 23 | +composer require \ |
| 24 | + --no-interaction \ |
| 25 | + drupal/admin_toolbar \ |
| 26 | + drupal/admin_toolbar_tools \ |
| 27 | + drupal/coffee |
| 28 | + |
| 29 | +# Install the modules in Drupal. |
| 30 | +drush en -y \ |
| 31 | + admin_toolbar \ |
| 32 | + admin_toolbar_tools \ |
| 33 | + coffee \ |
| 34 | + sdc_test_all_props |
| 35 | + |
| 36 | +# Create a test page. Note: If any more PHP code is added here, it should be |
| 37 | +# extracted to its own file. Writing it this way is clumsy, to say the least. |
| 38 | +drush php:eval " |
| 39 | + \$alias = '/test'; |
| 40 | + \$path_alias_repository = \Drupal::service('path_alias.repository'); |
| 41 | +
|
| 42 | + // See if the test page already exists and exit if so. (Just checking for |
| 43 | + // the path alias is naive, but it will suffice for our purposes. |
| 44 | + if (\$path_alias_repository->lookupByAlias(\$alias, 'en')) { |
| 45 | + echo 'The test page already exists.' . PHP_EOL; |
| 46 | + return; |
| 47 | + } |
| 48 | +
|
| 49 | + // Create the xb_page entity. |
| 50 | + \Drupal::service('entity_type.manager') |
| 51 | + ->getStorage('xb_page') |
| 52 | + ->create([ |
| 53 | + 'title' => 'XB 💫', |
| 54 | + 'description' => 'This is an XB page.', |
| 55 | + 'path' => ['alias' => \$alias], |
| 56 | + ])->save(); |
| 57 | +
|
| 58 | + echo 'The test page has been created.' . PHP_EOL; |
| 59 | +" |
0 commit comments