function RecipeConfigurator::getIncludedRecipe

Same name in other branches
  1. 11.x core/lib/Drupal/Core/Recipe/RecipeConfigurator.php \Drupal\Core\Recipe\RecipeConfigurator::getIncludedRecipe()

Gets an included recipe object.

Parameters

string $include_path: The recipe's include path.

string $name: The machine name of the recipe to get.

Return value

\Drupal\Core\Recipe\Recipe The recipe object.

Throws

\Drupal\Core\Recipe\UnknownRecipeException Thrown when the recipe cannot be found.

4 calls to RecipeConfigurator::getIncludedRecipe()
Recipe::validateRecipeExists in core/lib/Drupal/Core/Recipe/Recipe.php
Validates that a recipe exists.
RecipeConfigurator::__construct in core/lib/Drupal/Core/Recipe/RecipeConfigurator.php
RecipeConfiguratorTest::testIncludedRecipeLoader in core/tests/Drupal/KernelTests/Core/Recipe/RecipeConfiguratorTest.php
Tests that RecipeConfigurator can load recipes.
RecipeConfiguratorTest::testIncludedRecipeLoaderException in core/tests/Drupal/KernelTests/Core/Recipe/RecipeConfiguratorTest.php
Tests exception thrown when RecipeConfigurator cannot find a recipe.

File

core/lib/Drupal/Core/Recipe/RecipeConfigurator.php, line 43

Class

RecipeConfigurator
@internal This API is experimental.

Namespace

Drupal\Core\Recipe

Code

public static function getIncludedRecipe(string $include_path, string $name) : Recipe {
    // In order to allow recipes to include core provided recipes, $name can be
    // a Drupal root relative path to a recipe folder. For example, a recipe can
    // include the core provided 'article_tags' recipe by listing the recipe as
    // 'core/recipes/article_tags'. It is strongly recommended not to rely on
    // relative paths for including recipes. Required recipes should be put in
    // the same parent directory as the recipe being applied. Note, only linux
    // style directory separators are supported. PHP on Windows can resolve the
    // mix of directory separators.
    if (str_contains($name, '/')) {
        $path = \Drupal::root() . "/{$name}/recipe.yml";
    }
    else {
        $path = $include_path . "/{$name}/recipe.yml";
    }
    if (file_exists($path)) {
        return Recipe::createFromDirectory(dirname($path));
    }
    $search_path = dirname($path, 2);
    throw new UnknownRecipeException($name, $search_path, sprintf("Can not find the %s recipe, search path: %s", $name, $search_path));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.