You are here

public static function RealisticDummyContentRecipe::loadRecipeClass in Realistic Dummy Content 8.2

Same name and namespace in other branches
  1. 7.2 api/src/includes/RealisticDummyContentRecipe.php \Drupal\realistic_dummy_content_api\includes\RealisticDummyContentRecipe::loadRecipeClass()
  2. 3.x api/src/includes/RealisticDummyContentRecipe.php \Drupal\realistic_dummy_content_api\includes\RealisticDummyContentRecipe::loadRecipeClass()

Loads the recipe class file only if it is valid and exists.

Version 2.x introduced the requirement that the following line should be added to recipe files:

use Drupal\realistic_dummy_content_api\includes\RealisticDummyContentRecipe;

So we will throw an exception warning users of previous versions to add that line to use the 2.x branch of realistic_dummy_content.

Parameters

string $module: A module name.

Return value

bool|string FALSE or the full path to the loaded recipe class file.

Throws

\Exception

1 call to RealisticDummyContentRecipe::loadRecipeClass()
RealisticDummyContentRecipe::findObjects in api/src/includes/RealisticDummyContentRecipe.php
Find all recipe objects defined by all modules.

File

api/src/includes/RealisticDummyContentRecipe.php, line 73

Class

RealisticDummyContentRecipe
Abstract base "recipe" class.

Namespace

Drupal\realistic_dummy_content_api\includes

Code

public static function loadRecipeClass($module) {
  $path = Framework::instance()
    ->getPath('module', $module) . '/realistic_dummy_content/recipe/' . $module . '.recipe.inc';
  $fullpath = Framework::instance()
    ->frameworkRoot() . '/' . $path;
  if (!file_exists($fullpath)) {
    return FALSE;
  }
  $contents = file_get_contents($fullpath);
  if (!preg_match('/use Drupal*/s', $contents)) {
    throw new \Exception('As of the 2.x version you need to add the following line to the top of your recipe at ' . $fullpath . ': use Drupal\\realistic_dummy_content_api\\includes\\RealisticDummyContentRecipe');
  }
  return module_load_include('inc', $module, 'realistic_dummy_content/recipe/' . $module . '.recipe');
}