First off, hats off to mpotter for this module. This has been amazing to use so far.
I have been able to successfully use config_actions to override existing config using the "change" plugin, and create field instance & field storage configs from templates for multiple entities/bundles. However I am having difficulty trying to add the newly created fields to the entity form display configs.
I have tried to add them by using their own config/actions/actions.form_display_updates.yml file:
plugin: "add"
"@form_field_settings@":
field_access_control:
type: entity_reference_autocomplete
weight: 45
region: content
settings:
match_operator: CONTAINS
size: 60
placeholder: ''
third_party_settings: { }
path: ["content"]
source: "%id%"
node_forms:
actions:
core.entity_form_display.node.detail_page.default:
value: "@form_field_settings@"
core.entity_form_display.node.event.default:
value: "@form_field_settings@"
core.entity_form_display.node.landing_page.default:
value: "@form_field_settings@"
core.entity_form_display.node.person.default:
value: "@form_field_settings@"
I also tried tacking it on to the existing (and already working) config/actions/actions.field_access_control.yml:
replace:
"@field_name@": "field_access_control"
"@form_field_settings@":
field_access_control:
type: entity_reference_autocomplete
weight: 45
region: content
settings:
match_operator: CONTAINS
size: 60
placeholder: ''
third_party_settings: { }
actions:
field_storage:
source: "field.storage.node.field_access_control.yml"
dest: "field.storage.node.@field_name@"
field_instance:
source: "field.field.node.field_access_control.yml"
dest: "field.field.node.@bundle@.@field_name@"
actions:
detail_page:
replace:
"@bundle@": detail_page
event:
replace:
"@bundle@": event
landing_page:
replace:
"@bundle@": landing_page
person:
replace:
"@bundle@": person
form_field_elements:
plugin: "add"
path: ["content"]
source: "%id%"
node_forms:
actions:
core.entity_form_display.node.detail_page.default:
value: "@form_field_settings@"
core.entity_form_display.node.event.default:
value: "@form_field_settings@"
core.entity_form_display.node.landing_page.default:
value: "@form_field_settings@"
core.entity_form_display.node.person.default:
value: "@form_field_settings@"
I've tried various different code styles for yaml and wasn't able to find one that worked for adding those settings to the existing config.entity_form_display.node.@bundle@.default configs. I suspect I am using the "add" plugin incorrectly, but I haven't been able to track down how.
Comments
Comment #2
mpotter CreditAttribution: mpotter at Phase2 commentedIt might be a bug as the "Add" plugin hasn't gotten a lot of testing. You might take a look at the automated tests for the Add plugin to see if they help, but I know doing complex array stuff is very tricky and I don't think we have any tests for passing complex data within the variables of the action itself.
Remember that config_actions is basically doing "string replacements". So it's taking your YAML for your variable, converting it to a string, doing the string replacement in the variable expansion which then gets parsed back to YAML.
Definitely open to any patches if you can track down any problem. Will likely need to set some breakpoints to see exactly how the data from the variable is being put into the config object that it tries to save into the DB.
Comment #3
cruno CreditAttribution: cruno commentedSo I was able to get it to add the field to the form display by first renaming the .yml file after the config I was trying to update. That's the same thing I had originally done when testing the "change" plugin, but thought I could use a different destination plugin to achieve similar results here.
File: core.entity_form_display.node.event.yml
When I had tried adding actions for each bundle in the same .yml file (nested under config_actions: actions: ...) I was getting this error:
I was following in xdebug and it looked like it would first set the correct values for EntityDisplayBase::__construct() but then it would iterate through each of the child actions and set the name of the config itself as the bundle. Still need to dive in and see what was going on there, but for now the above code works for implementation; it just means each entity form display config will need its own actions yml file.
Comment #4
cruno CreditAttribution: cruno commentedI did eventually get this to work on another project. Following the override documentation resulted in errors in a similar ticket. Here is what I got to work:
Closing this out in favor of https://www.drupal.org/project/config_actions/issues/2996967#comment-128... since I think documentation just needs to be updated.
Comment #5
vunda CreditAttribution: vunda as a volunteer and commentedCan you add the field characters "Maximum length" in the YML file?
Thanks,