/** * Checks the TypedConfigManager has a valid schema for the configuration. * * @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config * The TypedConfigManager. * @param string $config_name * The configuration name. * @param array $config_data * The configuration data, assumed to be data for a top-level config object. * * @return array|bool * FALSE if no schema found. List of errors if any found. TRUE if fully * valid. */ public function checkConfigSchema(TypedConfigManagerInterface $typed_config, $config_name, $config_data) { // We'd like to verify that the top-level type is either config_base, // config_entity, or a derivative. The only thing we can really test though // is that the schema supports having langcode in it. So add 'langcode' to // the data if it doesn't already exist. if (!isset($config_data['langcode'])) { $config_data['langcode'] = 'en'; } $this->configName = $config_name; if (!$typed_config->hasConfigSchema($config_name)) { return FALSE; } $definition = $typed_config->getDefinition($config_name); $data_definition = $typed_config->buildDataDefinition($definition, $config_data); $this->schema = $typed_config->create($data_definition, $config_data); $errors = array(); foreach ($config_data as $key => $value) { $errors = array_merge($errors, $this->checkValue($key, $value)); } if (empty($errors)) { return TRUE; } return $errors; }
/** * {@inheritdoc} */ public function hasSchema() { foreach ($this->getConfigNames() as $name) { if (!$this->typedConfigManager->hasConfigSchema($name)) { return FALSE; } } return TRUE; }
/** * Checks the TypedConfigManager has a valid schema for the configuration. * * @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config * The TypedConfigManager. * @param string $config_name * The configuration name. * @param array $config_data * The configuration data. * * @return array|bool * FALSE if no schema found. List of errors if any found. TRUE if fully * valid. */ public function checkConfigSchema(TypedConfigManagerInterface $typed_config, $config_name, $config_data) { $this->configName = $config_name; if (!$typed_config->hasConfigSchema($config_name)) { return FALSE; } $definition = $typed_config->getDefinition($config_name); $data_definition = $typed_config->buildDataDefinition($definition, $config_data); $this->schema = $typed_config->create($data_definition, $config_data); $errors = array(); foreach ($config_data as $key => $value) { $errors = array_merge($errors, $this->checkValue($key, $value)); } if (empty($errors)) { return TRUE; } return $errors; }
/** * Checks if the configuration schema with the given config name exists. * * @param string $name * Configuration name. * * @return bool * TRUE if configuration schema exists, FALSE otherwise. */ public function hasSchema($name) { return $this->typedConfigManager->hasConfigSchema($name); }