Skip to content

Commit

Permalink
ACMS-4255: Option to extend starterkit.
Browse files Browse the repository at this point in the history
  • Loading branch information
rajeshreeputra committed Sep 30, 2024
1 parent 8666a8f commit 7aa98fc
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 11 deletions.
2 changes: 1 addition & 1 deletion recipes/acquia_drupal_starterkit_content_model/recipe.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Acquia Drupal Startekit Low-Code'
name: 'Acquia Drupal Startekit Content Model'
description: 'An content model provides Article, Event, Page, Person, Place content types.'
type: 'Starterkit'
recipes:
Expand Down
10 changes: 10 additions & 0 deletions recipes/acquia_drupal_starterkit_headless/recipe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,13 @@ recipes:
install:
# Contrib
- acquia_cms_headless
config:
actions:
project_browser.admin_settings:
simple_config_update:
allowed_projects:
recipes:
- acquia_drupal_starterkit_community
- acquia_drupal_starterkit_content_model
- acquia_drupal_starterkit_headless
- acquia_drupal_starterkit_media_model
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use Drupal\Core\Installer\Form\SiteConfigureForm;
use Drupal\Core\Installer\Form\SiteSettingsForm;
use Drupal\Core\Recipe\Recipe;
use Drupal\Core\Recipe\RecipeRunner;
use Drupal\acquia_drupal_starterkit_installer\Form\RecipesForm;
use Drupal\acquia_drupal_starterkit_installer\Form\RecipesStarterkitForm;
use Drupal\acquia_drupal_starterkit_installer\Form\RecipesAddOnForm;
use Drupal\acquia_drupal_starterkit_installer\Form\SiteNameForm;

/**
Expand Down Expand Up @@ -46,12 +47,19 @@ function acquia_drupal_starterkit_installer_install_tasks_alter(array &$tasks, a
$tasks_after = array_slice($tasks, $key, NULL, TRUE);
$tasks = $tasks_before + $additions + $tasks_after;
};

$insert_before('install_settings_form', [
'acquia_drupal_starterkit_installer_choose_recipes' => [
'display_name' => t('Choose add-ons'),
'type' => 'form',
'run' => array_key_exists('recipes', $install_state['parameters']) ? INSTALL_TASK_SKIP : INSTALL_TASK_RUN_IF_REACHED,
'function' => RecipesForm::class,
'function' => RecipesStarterkitForm::class,
],
'acquia_drupal_starterkit_installer_addons' => [
'display_name' => t('Extend Acquia Drupal Starter Kit with Add-ons'),
'type' => 'form',
'run' => array_key_exists('recipes_starterkit_addons', $install_state['parameters']) ? INSTALL_TASK_SKIP : INSTALL_TASK_RUN_IF_REACHED,
'function' => RecipesAddOnForm::class,
],
'acquia_drupal_starterkit_installer_site_name_form' => [
'display_name' => t('Name your site'),
Expand Down
9 changes: 9 additions & 0 deletions recipes/acquia_drupal_starterkit_installer/css/add-ons.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
word-wrap: normal;
}

#edit-add-ons [type="radio"] {
position: absolute;
overflow: hidden;
clip: rect(1px, 1px, 1px, 1px);
width: 1px;
height: 1px;
word-wrap: normal;
}

#edit-add-ons label {
display: inline-block;
color: #39353e;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

namespace Drupal\acquia_drupal_starterkit_installer\Form;

use Drupal\Core\Form\FormStateInterface;

/**
* Provides a form to choose the site template and optional add-on recipes.
*
* @todo Present this as a mini project browser once
* https://www.drupal.org/i/3450629 is fixed.
*/
final class RecipesAddOnForm extends InstallerFormBase {

/**
* {@inheritdoc}
*/
public function getFormId(): string {
return 'acquia_drupal_starterkit_recipes_addon_form';
}

/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state): array {
$form['#title'] = $this->t('Extend Acquia Drupal Starter Kit with Add-ons');

$form['help'] = [
'#prefix' => '<p class="cms-installer__subhead">',
'#markup' => $this->t('You can change your mind later.'),
'#suffix' => '</p>',
];
$options = [
'acquia_drupal_starterkit_content_model' => $this->t('Acquia Drupal Starterkit Content Model'),
'acquia_drupal_starterkit_media_model' => $this->t('Acquia Drupal Starterkit Media Model'),
];

$form['add_ons'] = [
'#prefix' => '<div class="cms-installer__form-group">',
'#suffix' => '</div>',
'#type' => 'checkboxes',
'#options' => $options,
'#default_value' => [],
];
$form['actions'] = [
'submit' => [
'#type' => 'submit',
'#value' => $this->t('Next'),
'#button_type' => 'primary',
],
'skip' => [
'#type' => 'submit',
'#value' => $this->t('Skip this step'),
],
'#type' => 'actions',
];
return parent::buildForm($form, $form_state);
}

/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state): void {
global $install_state;
$install_state['parameters']['recipes'] = $this->getRequest()->get('recipes') ?? [];
$install_state['parameters']['recipes_starterkit_addons'] = $install_state['parameters']['recipes'];
$pressed_button = $form_state->getTriggeringElement();
// Only choose add-ons if the Next button was pressed.
if ($pressed_button && end($pressed_button['#array_parents']) === 'submit') {
$add_ons = $form_state->getValue('add_ons', []);
$add_ons = array_filter($add_ons);
array_push($install_state['parameters']['recipes'], ...array_values($add_ons));
array_push($install_state['parameters']['recipes_starterkit_addons'], ...array_values($add_ons));
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @todo Present this as a mini project browser once
* https://www.drupal.org/i/3450629 is fixed.
*/
final class RecipesForm extends InstallerFormBase {
final class RecipesStarterkitForm extends InstallerFormBase {

/**
* {@inheritdoc}
Expand All @@ -35,17 +35,16 @@ public function buildForm(array $form, FormStateInterface $form_state): array {
'acquia_drupal_starterkit_community' => $this->t('Acquia Drupal Starterkit Community'),
'acquia_drupal_starterkit_headless' => $this->t('Acquia Drupal Starterkit Headless'),
'acquia_drupal_starterkit_low_code' => $this->t('Acquia Drupal Starterkit Low-Code'),
'acquia_drupal_starterkit_content_model' => $this->t('Acquia Drupal Starterkit Content Model'),
'acquia_drupal_starterkit_media_model' => $this->t('Acquia Drupal Starterkit Media Model'),
];

$form['add_ons'] = [
'#prefix' => '<div class="cms-installer__form-group">',
'#suffix' => '</div>',
'#type' => 'checkboxes',
'#type' => 'radios',
'#options' => $options,
'#default_value' => [],
];

$form['actions'] = [
'submit' => [
'#type' => 'submit',
Expand All @@ -67,13 +66,13 @@ public function buildForm(array $form, FormStateInterface $form_state): array {
public function submitForm(array &$form, FormStateInterface $form_state): void {
global $install_state;
$install_state['parameters']['recipes'] = ['acquia_drupal_starterkit'];

$pressed_button = $form_state->getTriggeringElement();
// Only choose add-ons if the Next button was pressed.
if ($pressed_button && end($pressed_button['#array_parents']) === 'submit') {
$add_ons = $form_state->getValue('add_ons', []);
$add_ons = array_filter($add_ons);
array_push($install_state['parameters']['recipes'], ...array_values($add_ons));
$add_ons = $form_state->getValue('add_ons');
if ($add_ons) {
$install_state['parameters']['recipes'][] = $add_ons;
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions recipes/acquia_drupal_starterkit_low_code/recipe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,13 @@ recipes:
install:
# Contrib
- acquia_cms_site_studio
config:
actions:
project_browser.admin_settings:
simple_config_update:
allowed_projects:
recipes:
- acquia_drupal_starterkit_community
- acquia_drupal_starterkit_content_model
- acquia_drupal_starterkit_low_code
- acquia_drupal_starterkit_media_model

0 comments on commit 7aa98fc

Please sign in to comment.