プログラムでレシピを読み込む
Drupal CMS 1.0 の調査は以下のようなプログラムで情報を出力したものを載せている。
web/core/lib/Drupal/Core/Recipe 以下がレシピ機能のコードでRecipeRunnerを見ると楽しい。
This API is experimental. というコメントもあるので今後変更されると思われる。
code:php
<?php
use Drupal\Core\Recipe\Recipe;
$recipe_path = '/var/www/html/recipes/drupal_cms_starter';
function printRecipeNames(Recipe $recipe, int $depth = 0): void {
// 現在のレシピ名をインデント付きで出力
echo str_repeat("\t", $depth) . $recipe->name . PHP_EOL;
// モジュールの出力
foreach ($recipe->install->modules as $val) {
echo str_repeat("\t", $depth) . " m:" . $val . PHP_EOL;
}
// テーマの出力
foreach ($recipe->install->themes as $val) {
echo str_repeat("\t", $depth) . " t:" . $val . PHP_EOL;
}
// 子レシピが存在する場合、再帰的に処理
foreach ($recipe->recipes->recipes as $childRecipe) {
printRecipeNames($childRecipe, $depth + 1);
}
}
/** @var \Drupal\Core\Recipe\Recipe $main_recipe **/
$main_recipe = Recipe::createFromDirectory($recipe_path);
printRecipeNames($main_recipe);
このコードですでにインストールされているモジュールは $recipe->install->modules には存在しない。
レシピ機能としてインストール済みのモジュールは何もしないように制御されていると思われる。
そのため情報出力は minimal プロファイルでインストールしたDrupalで行なったため、userやnodeなどはリストにない。Drupal CMSの概要知るためにはなくてもいいかなと。
#Drupal
#Drupal_CMS_1.0