EntityGenerate 'default_values' value not processed correctly when it's an array property

Created on 18 September 2019, almost 5 years ago
Updated 21 September 2023, 9 months ago

I ran into some problems when trying to set the format of a text field inside an entity_generate plugin.

...
            'default_values' => [
              'field_description/format' => 'basic_html',
              'field_specifications/format' => 'basic_html',
            ],
...

This wasn't working, which I thought was weird, since I could use array structure inside the 'values' configuration.

// Gather any static default values for properties/fields.
    if (isset($this->configuration['default_values']) && is_array($this->configuration['default_values'])) {
      foreach ($this->configuration['default_values'] as $key => $value) {
        $entity_values[$key] = $value;
      }
    }

So my previous example was being processed as:

'field_description/format' => 'basic_html',
'field_specifications/format' => 'basic_html',

Instead of the expected

'field_description' => [
  'format' => 'basic_html',
],
'field_specifications' => [
  'format' => 'basic_html',
],

It should be using the same logic as the 'value', using NestedArray and separating it by the property separator '/':

NestedArray::setValue($entity_values, explode(Row::PROPERTY_SEPARATOR, $key), $source_value, TRUE);
πŸ› Bug report
Status

Needs work

Version

5.0

Component

Plugins

Created by

πŸ‡΅πŸ‡ΉPortugal gueguerreiro Lisboa

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024