You are here

public function ParserConfigurationForm::getConfigFromValues in Markdown 8.2

Retrieves configuration from an array of values.

Parameters

string $name: The config name to use.

array $values: An array of values.

Return value

\Drupal\Core\Config\Config A Config object.

3 calls to ParserConfigurationForm::getConfigFromValues()
ParserConfigurationForm::submitForm in src/Form/ParserConfigurationForm.php
Form submission handler.
ParserConfigurationForm::validateForm in src/Form/ParserConfigurationForm.php
Form validation handler.
SettingsForm::getConfigurationFromValues in src/Form/SettingsForm.php
Retrieves configuration from values.

File

src/Form/ParserConfigurationForm.php, line 659

Class

ParserConfigurationForm
Form for modifying parser configuration.

Namespace

Drupal\markdown\Form

Code

public function getConfigFromValues($name, array $values) {
  $config = $this->configFactory
    ->getEditable($name);

  // Some older 8.x-2.x code used to have the parser value as a string.
  // @todo Remove after 8.x-2.0 release.
  if (isset($values['parser']) && is_string($values['parser'])) {
    $values['id'] = $values['parser'];
    unset($values['parser']);
  }
  elseif (isset($values['parser']) && is_array($values['parser'])) {
    $values += $values['parser'];
  }

  // Load the parser with the values so it can construct the proper config.
  $parserId = isset($values['id']) ? (string) $values['id'] : '';
  $parser = $this->parserManager
    ->createInstance($parserId, $values);

  // Sort $configuration by using the $defaults keys. This ensures there
  // is a consistent order when saving the config.
  $configuration = $parser
    ->getSortedConfiguration();
  $config
    ->setData($configuration);
  return $config;
}