Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By dawehner on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.4.x
Introduced in version:
8.4.0
Issue links:
Description:
\Drupal\Core\Config\TypedConfigManagerInterface
gained a new method: createFromNameAndData
which leverages the existing methods to make it easy to create a typed config instance without having to have a saved instance of some configuration.
Before
// Setup.
$typed_config = \Drupal::service('config.typed');
$config_name = 'system.site';
$config_data = \Drupal::config('system.site')->get();
// Get typed representation.
$definition = $typed_config->getDefinition($config_name);
$data_definition = $typed_config->buildDataDefinition($definition, $config_data);
$schema = $typed_config->create($data_definition, $config_data);
After
// Setup.
$typed_config = \Drupal::service('config.typed');
$config_name = 'system.site';
$config_data = \Drupal::config('system.site')->get();
// Get typed representation.
$schema = $typed_config->createFromNameAndData($config_name, $config_data);
config.typed service
If you implement this interface, you will need to update your class to have the new method. You should be able to directly use the code in the patch:
/**
* {@inheritdoc}
*/
public function createFromNameAndData($config_name, array $config_data) {
$definition = $this->getDefinition($config_name);
$data_definition = $this->buildDataDefinition($definition, $config_data);
return $this->create($data_definition, $config_data);
}
Impacts:
Module developers