Problem/Motivation
#2869809: Make it easy to get typed config representations of entities introduced \Drupal\Core\Config\TypedConfigManager::createFromNameAndData():
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);
}
It's great! It's used in many places.
But it has one bug: the \Drupal\Core\TypedData\TraversableTypedDataInterface instances it returns do not have a working getName() nor a working getPropertyPath(), because we forgot to pass the third argument to ::create(): public function create(DataDefinitionInterface $definition, $value = NULL, $name = NULL, $parent = NULL) { — the $name!
Steps to reproduce
N/A — discovered in #3216089: Expose validation constraints (and validatability %) in Config Inspector UI.
Proposed resolution
Specify $name.
Remaining tasks
None.
User interface changes
None.
API changes
None.
Data model changes
None.
Release notes snippet
N/A
Comments
Comment #2
wim leersComment #3
wim leers@borisson_ raised a legitimate concern in Drupal Slack:
It’s been in core for years but that method is called virtually nowhere. It pretty much only exists in Typed Config tests!
Since CKEditor 5 is in core, 3 calls to it were added to core. Which brings it to a grand total of 12 🤣
The thing is that the commit that introduced it (#2869809: Make it easy to get typed config representations of entities) was specifically done as one of the blockers for
POSTandPATCHsupport for config entities via the REST module.But of course the validation pieces never materialized … so none of that really happened.
That’s why I’m running into it now: because I’m working on validation 🤓
Comment #4
borisson_Discussed with Wim in slack, I now understand why this only breaks in this scenario, patch looks great!
Comment #6
wim leersDiscovered this in #3216089: Expose validation constraints (and validatability %) in Config Inspector UI and hence had to work around this.
Comment #7
wim leersComment #10
lauriiiCommitted 96e2fd9 and pushed to 11.x. Also cherry-picked to 10.1.x. Thanks!
Interestingly, yesterday I was debugging code in #3358049: Save FieldStorageConfig at the same time as FieldConfig where I had done the same mistake 😅 It did take me a while to realize until I found yet another map in
\Drupal\Core\TypedData\TypedDataManager::$prototypes.