function InputConfigurator::__construct

Parameters

array<string, array<string, mixed>> $definitions: The recipe's input definitions, keyed by name. This is an array of arrays where each sub-array has, at minimum:

  • `description`: A short, human-readable description of the input (e.g., what the recipe uses it for).
  • `data_type`: A primitive data type known to the typed data system.
  • `constraints`: An optional array of validation constraints to apply to the value. This should be an associative array of arrays, keyed by constraint name, where each sub-array is a set of options for that constraint (identical to the way validation constraints are defined in config schema).
  • `default`: A default value for the input, if it cannot be collected the user. See ::getDefaultValue() for more information.

\Drupal\Core\Recipe\RecipeConfigurator $dependencies: The recipes that this recipe depends on.

string $prefix: A prefix for each input definition, to give each one a unique name when collecting input for multiple recipes. Usually this is the unique name of the recipe.

\Drupal\Core\TypedData\TypedDataManagerInterface $typedDataManager: The typed data manager service.

File

core/lib/Drupal/Core/Recipe/InputConfigurator.php, line 57

Class

InputConfigurator
Collects and validates input values for a recipe.

Namespace

Drupal\Core\Recipe

Code

public function __construct(array $definitions, RecipeConfigurator $dependencies, string $prefix, TypedDataManagerInterface $typedDataManager) {
    // Convert the input definitions to typed data definitions.
    foreach ($definitions as $name => $definition) {
        $data_definition = DataDefinition::create($definition['data_type'])->setDescription($definition['description'])
            ->setConstraints($definition['constraints'] ?? []);
        unset($definition['data_type'], $definition['description'], $definition['constraints']);
        $data_definition->setSettings($definition);
        $this->data[$name] = $typedDataManager->create($data_definition);
    }
}

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