Dear backdrop community,
I'm thrilled to build my first backdrop site (coming from D7). I would like to create some fields (used in nodes types and/or taxonomies) with dynamic default values and/or dynamic lists of allowed values.
Default values
- The default value should inherit its value from a parent, so if I change the value of that parent, the value of the field will also change (only if it is set to default, of course).
- I want to be able to choose which parent to use as default per node/term, based on another field.
I would prefer not to use rules to change all occurances of a default value when I change the parent value.
Dynamic lists of allowed values
- Like above: The list should change depending on another field that references the parent.
I'm more of the site-builder type, so if coding will be involved I might need a little help in how that would have to look like. :)
Comments
Is this what you were hoping that conditional fields would solve?
No, that's for something else.
Hello @guidot and congrats on starting your first Backdrop site 👏
I did a bit of research. I've found some related D7 modules like https://www.drupal.org/project/ddf but not any that would do exactly what you are after. Are you aware of any existing module that does that? ...perhaps we could port it to Backdrop then.
To be frank, what you are trying to achieve sounds quite complex. If no existing module, then I'm afraid that you'd have to go with a custom solution.
Here's what I found on the web that you may find helpful:
If you find any functionality missing in Backdrop that exists in Drupal 7 or 8 that would help you achieve what you are after, then please report it. It may be considered for either core or contrib.
Hi @klonos, thanks for the nice welcome!
And thanks for taking the time to look into that. DDF looks like it could solve the second part of what looking for, the dynamic list of allowed values. But that part is more like a convenience feature I could live without (at least for now).
The first part (inheritance of default values) is what I really need. It seems D8 has that now built-in.
I also did some research and these are the Drupal modules I found:
Maybe my original idea was too much focused on the word default, when what I am looking for is in fact inheritance of a field's value from a referenced entity (node or term) in a parent-child-like fashion.
Someone else has asked that question Entity field value inherited from another entity programmatically? without getting an answer.
I looked into the node clone module, but it lacks the dynamic component as it just copies the values to a new node.
I have no idea if the field system is flexible enough to extend the field settings by a reference that (if populated) says "If this field is set to default use the actual value of the corresponding field in the referenced entity instead".
Maybe computed field can help me by only copying the value of a referenced entity as long as the local value is set to default?
Hi @klonos, thanks for the nice welcome!
And thanks for taking the time to look into that. DDF looks like it could solve the second part of what I'm looking for, the dynamic list of allowed values. But that part is more like a convenience feature I could live without.
The first part (inheritance of default values) is what's really important to me. It seems D8 has that now built-in.
I also did some research and these are the Drupal modules I found:
Maybe my original idea was too much focused on the word default, when what I am looking for is in fact inheritance of a field's value from a referenced entity (node or term) in a parent-child-like fashion.
Someone else has asked that question Entity field value inherited from another entity programmatically? without getting an answer.
I looked into the node clone module, but it lacks the dynamic component as it just copies the values to the new node.
I have no idea if the field system is flexible enough to extend the field settings by a reference that (if populated) says "If this field is set to default use the actual value of the corresponding field in the referenced entity instead".
Maybe computed field can help me by only copying the value of a referenced entity as long as the local value is set to default?
OK, finally I could start working on this. I had an idea how to achieve the selective inheritance by using some modules and hopefully only little code:
The modules: Entity reference, Multifield, Computed field
That's what I did:
question
.field_myparent
that may point to a node of the same type to inherite values from.field_use_default
field_question_text
actual_value
(currently set to recalculate the field value every time, but not to store value in the database).When I display a node it works as intended.
But when I try to save it I get
Unknown data property field_use_default
I found out (by seeing my
dpm()
output twice) that in this casecomputed_field_field_actual_value_compute()
is called multiple times, and in one of them it seems to happen in a place where it doesn't have access to the multifield. Did I hit a bug?Other than that I need to solve some questions:
$parent_multifield
.$parent_node
that doesn't have the corresponding$use_default
set. Is that feasable?actual_value
depending onfield_use_default
: Haven't looked into that yet.