function InputConfigurator::getDefaultValue

Returns the default value for an input definition.

Parameters

array $definition: An input definition. Must contain a `source` element, which can be either 'config' or 'value'. If `source` is 'config', then there must also be a `config` element, which is a two-element indexed array containing (in order) the name of an extant config object, and a property path within that object. If `source` is 'value', then there must be a `value` element, which will be returned as-is.

Return value

mixed The default value.

1 call to InputConfigurator::getDefaultValue()
InputConfigurator::collectAll in core/lib/Drupal/Core/Recipe/InputConfigurator.php
Collects input values for this recipe and its dependencies.

File

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

Class

InputConfigurator
Collects and validates input values for a recipe.

Namespace

Drupal\Core\Recipe

Code

private function getDefaultValue(DataDefinition $definition) : mixed {
    $settings = $definition->getSetting('default');
    if ($settings['source'] === 'config') {
        [
            $name,
            $key,
        ] = $settings['config'];
        $config = \Drupal::config($name);
        if ($config->isNew()) {
            throw new \RuntimeException("The '{$name}' config object does not exist.");
        }
        return $config->get($key);
    }
    return $settings['value'];
}

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