-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ACMS-4255: Option to extend starterkit.
- Loading branch information
1 parent
8666a8f
commit 37c1d0c
Showing
4 changed files
with
100 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
recipes/acquia_drupal_starterkit_installer/src/Form/RecipesAddOnForm.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?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') ?? []; | ||
$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)); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters