In Drupal 7, I have two content types:
Parent Events with tags (like "outdoors" or "popular" or "suitable for kids"). "Tags" are taxonomy terms in a vocabulary, connected via an Entity Reference field
field_parent_tags
(using the Checkboxes widget).Child Events with the same tags & reference in
field_child_tags
. Each Child also has a mandatory Entity Reference to a Parent Event,field_parent_event
(using the Autocomplete widget).
I'm trying to have new Child Events automatically inherit their parent's tags when they're first created. For example:
- There is a Parent Event called "Weddings", which has the tags "suitable for kids" and "popular".
- When I make a new Child Event called "Joe & Sarah's Beach Wedding", I'd like it to automatically inherit the tags "suitable for kids" and "popular". Then I'd add the "outdoors" tag to this specific child event, which would apply only to this child and not the parent.
- (Another child event might be someone else's wedding, and not suitable for kids, so I'd uncheck that in the child event).
How would I go about doing that? So far, I think I need to implement some variation of hook_form_alter()
, possibly overriding its #ajax
call so that as soon as the child event's form_parent_event
is filled out, its field_child_tags
will copy the values from field_parent_tags
.
Am I going down the right path? I can't figure out where to put that code, if so. I tried overriding /node/add/childevent
using a page--node--add-child-event.tpl.php
file, but it seems to have no effect. A little lost :(
Any help would be very much appreciated. Thank you!