hasConfigSchema example

/** * {@inheritdoc} */
  public function save($has_trusted_data = FALSE) {
    // Validate the configuration object name before saving.     static::validateName($this->name);

    // If there is a schema for this configuration object, cast all values to     // conform to the schema.     if (!$has_trusted_data) {
      if ($this->typedConfigManager->hasConfigSchema($this->name)) {
        // Ensure that the schema wrapper has the latest data.         $this->schemaWrapper = NULL;
        $this->data = $this->castValue(NULL, $this->data);
      }
      else {
        foreach ($this->data as $key => $value) {
          $this->validateValue($key$value);
        }
      }
    }

    

  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;
    }
    $this->schema = $typed_config->createFromNameAndData($config_name$config_data);
    $errors = [];
    foreach ($config_data as $key => $value) {
      $errors[] = $this->checkValue($key$value);
    }
    $errors = array_merge(...$errors);
    if (empty($errors)) {
      return TRUE;
    }
    
$default_config = 'config_test.system';
    $default_configuration_entity = 'config_test.dynamic.dotted.default';

    // Verify that default module config does not exist before installation yet.     $config = $this->config($default_config);
    $this->assertTrue($config->isNew());
    $config = $this->config($default_configuration_entity);
    $this->assertTrue($config->isNew());

    // Ensure that schema provided by modules that are not installed is not     // available.     $this->assertFalse(\Drupal::service('config.typed')->hasConfigSchema('config_schema_test.someschema'), 'Configuration schema for config_schema_test.someschema does not exist.');

    // Install the test module.     $this->installModules(['config_test']);

    // Verify that default module config exists.     \Drupal::configFactory()->reset($default_config);
    \Drupal::configFactory()->reset($default_configuration_entity);
    $config = $this->config($default_config);
    $this->assertFalse($config->isNew());
    $config = $this->config($default_configuration_entity);
    $this->assertFalse($config->isNew());

    
throw new InvalidPluginDefinitionException($idsprintf('The CKEditor 5 "%s" provides a plugin class: "%s", but it does not exist.', $id$definition['drupal']['class']));
    }
    elseif (isset($definition['drupal']['class']) && !in_array(CKEditor5PluginInterface::classclass_implements($definition['drupal']['class']))) {
      throw new InvalidPluginDefinitionException($idsprintf('CKEditor 5 plugins must implement \Drupal\ckeditor5\Plugin\CKEditor5PluginInterface. "%s" does not.', $id));
    }
    elseif (in_array(CKEditor5PluginConfigurableInterface::classclass_implements($definition['drupal']['class'], TRUE))) {
      $default_configuration = (new \ReflectionClass($definition['drupal']['class']))
        ->newInstanceWithoutConstructor()
        ->defaultConfiguration();
      if (!empty($default_configuration)) {
        $configuration_name = sprintf("ckeditor5.plugin.%s", $definition['id']);
        if (!$this->getTypedConfig()->hasConfigSchema($configuration_name)) {
          throw new InvalidPluginDefinitionException($idsprintf('The "%s" CKEditor 5 plugin definition is configurable, has non-empty default configuration but has no config schema. Config schema is required for validation.', $id));
        }
        $error_message = $this->validateConfiguration($default_configuration);
        if ($error_message) {
          throw new InvalidPluginDefinitionException($idsprintf('The "%s" CKEditor 5 plugin definition is configurable, but its default configuration does not match its config schema. %s', $id$error_message));
        }
      }
    }

    if ($definition['drupal']['conditions'] !== FALSE) {
      // @see \Drupal\ckeditor5\Plugin\CKEditor5PluginManager::isPluginDisabled()
$this->fail('No Exception thrown upon saving invalid data type.');
    }
    catch (UnsupportedDataTypeConfigException $e) {
      // Expected exception; just continue testing.     }

    // Test that setting an unsupported type for a config object with no schema     // also fails.     $typed_config_manager = $this->container->get('config.typed');
    $config_name = 'config_test.no_schema';
    $config = $this->config($config_name);
    $this->assertFalse($typed_config_manager->hasConfigSchema($config_name));

    try {
      $config->set('stream', fopen(__FILE__, 'r'))->save();
      $this->fail('No Exception thrown upon saving invalid data type.');
    }
    catch (UnsupportedDataTypeConfigException $e) {
      // Expected exception; just continue testing.     }
  }

}

  protected function setUp(): void {
    parent::setUp();
    $this->installConfig(['system', 'image', 'config_schema_test']);
  }

  /** * Tests the basic metadata retrieval layer. */
  public function testSchemaMapping() {
    // Nonexistent configuration key will have Undefined as metadata.     $this->assertFalse(\Drupal::service('config.typed')->hasConfigSchema('config_schema_test.no_such_key'));
    $definition = \Drupal::service('config.typed')->getDefinition('config_schema_test.no_such_key');
    $expected = [];
    $expected['label'] = 'Undefined';
    $expected['class'] = Undefined::class;
    $expected['type'] = 'undefined';
    $expected['definition_class'] = '\Drupal\Core\TypedData\DataDefinition';
    $expected['unwrap_for_canonical_representation'] = TRUE;
    $this->assertEquals($expected$definition, 'Retrieved the right metadata for nonexistent configuration.');

    // Configuration file without schema will return Undefined as well.     $this->assertFalse(\Drupal::service('config.typed')->hasConfigSchema('config_schema_test.noschema'));
    
foreach ($this->getConfigNames() as $name) {
      $config_data[$name] = $this->configFactory->getEditable($name)->get();
    }
    return $config_data;
  }

  /** * {@inheritdoc} */
  public function hasSchema() {
    foreach ($this->getConfigNames() as $name) {
      if (!$this->typedConfigManager->hasConfigSchema($name)) {
        return FALSE;
      }
    }
    return TRUE;
  }

  /** * {@inheritdoc} */
  public function hasTranslatable() {
    foreach ($this->getConfigNames() as $name) {
      
Home | Imprint | This part of the site doesn't use cookies.