Skip to content

Commit

Permalink
ACMS-4255: Add dynamic recipes discovery on installation page.
Browse files Browse the repository at this point in the history
  • Loading branch information
rajeshreeputra committed Oct 1, 2024
1 parent c67642c commit 0e17325
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 16 deletions.
1 change: 1 addition & 0 deletions recipes/acquia_drupal_starterkit/recipe.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Acquia Drupal Starterkit
description: Applies all the basic Acquia Drupal Starterkit recipes.
type: Site
visibility: hidden
recipes:
- acquia_drupal_starterkit_admin_theme
- core/recipes/core_recommended_front_end_theme
Expand Down
1 change: 1 addition & 0 deletions recipes/acquia_drupal_starterkit_admin_theme/recipe.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: 'Acquia Drupal Starterkit Admin Theme'
type: 'Acquia Drupal Starterkit'
visibility: hidden
description: 'Sets up a nice administrative theme and toolbar.'
install:
- gin
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: 'Acquia Drupal Startekit Basic HTML editor'
type: 'Acquia Drupal Startekit'
visibility: hidden
description: 'Enhances the Basic HTML editor with better linking and media support.'
install:
- ckeditor5
Expand Down
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,6 +1,6 @@
name: 'Acquia Drupal Startekit Content Model'
description: 'An content model provides Article, Event, Page, Person, Place content types.'
type: 'Starterkit'
type: 'Starterkit addon'
recipes:
- acquia_drupal_starterkit_community
install:
Expand Down
2 changes: 1 addition & 1 deletion recipes/acquia_drupal_starterkit_dam/recipe.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: 'Acquia Drupal Startekit DAM'
description: 'Integrates with Acquia DAM.'
type: 'Starterkit'
type: 'Starterkit addon'
install:
# Contrib
- acquia_cms_dam
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: 'Acquia Drupal Startekit Full HTML editor'
type: 'Acquia Drupal Startekit'
visibility: hidden
description: 'Enhances the Full HTML editor with better linking and media support.'
install:
- ckeditor5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use Drupal\Core\Recipe\RecipeRunner;
use Drupal\acquia_drupal_starterkit_installer\Form\RecipesStarterkitForm;
use Drupal\acquia_drupal_starterkit_installer\Form\RecipesAddOnForm;
use Drupal\acquia_drupal_starterkit_installer\Form\SiteNameForm;
use Symfony\Component\Yaml\Yaml;

/**
* Implements hook_install_tasks().
Expand Down Expand Up @@ -280,3 +281,31 @@ function acquia_drupal_starterkit_installer_preprocess_install_page(array &$vari
->generateString($images_path);
$variables['images_path'] = $images_path;
}

/**
* Identifies all recipes available in the docroot/recipes directory.
*
* @param string $type
* The type of recipes to filter by.
*
* @return array
* An array of recipe names.
*/
function acquia_drupal_starterkit_installer_get_available_recipes(string $type = 'Starterkit addon'): array {
$recipes = [];
$directory = new \DirectoryIterator(\Drupal::root() . '/recipes');

foreach ($directory as $fileinfo) {
if ($fileinfo->isDir() && !$fileinfo->isDot()) {
$recipe_file = $fileinfo->getPathname() . '/recipe.yml';
if (file_exists($recipe_file)) {
$recipe_info = Yaml::parseFile($recipe_file);
if (isset($recipe_info['name']) && (!isset($recipe_info['visibility']) || $recipe_info['visibility'] !== 'hidden') && $recipe_info['type'] === $type) {
$recipes[$fileinfo->getFilename()] = $recipe_info['name'];
}
}
}
}

return $recipes;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,12 @@ public function buildForm(array $form, FormStateInterface $form_state): array {
'#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,
'#options' => acquia_drupal_starterkit_installer_get_available_recipes('Starterkit addon'),
'#default_value' => [],
];
$form['actions'] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,11 @@ public function buildForm(array $form, FormStateInterface $form_state): array {
'#suffix' => '</p>',
];

$options = [
'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'),
];

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

Expand Down
2 changes: 1 addition & 1 deletion recipes/acquia_drupal_starterkit_media_model/recipe.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: 'Acquia Drupal Startekit Media Model'
description: 'An media model provides Audio, Document, Image< Video media types.'
type: 'Starterkit'
type: 'Starterkit addon'
install:
# Contrib
- acquia_cms_audio
Expand Down
2 changes: 1 addition & 1 deletion recipes/acquia_drupal_starterkit_search/recipe.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: 'Acquia Drupal Startekit Search'
description: "Provides integration between your Drupal site and Acquia's hosted search service."
type: 'Starterkit'
type: 'Starterkit addon'
install:
# Contrib
- acquia_cms_search

0 comments on commit 0e17325

Please sign in to comment.