Skip to content

Instantly share code, notes, and snippets.

@kspurgin
Created June 23, 2021 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kspurgin/1d89307e3b5eba22274e04a99dc3c03a to your computer and use it in GitHub Desktop.
Save kspurgin/1d89307e3b5eba22274e04a99dc3c03a to your computer and use it in GitHub Desktop.
Conditional default field value - use case/description

I have added a Boolean authorized field to my I8 taxonomy terms via a lyrasis_module_entity_base_field_info function in my custom module. Currently the default value of this field is FALSE.

Many (but not all) of my vocabularies also have a URI external_vocabulary_uri field.

What I would like to be able to do is:

  • if there is an external_vocabulary_uri field on my taxonomy term AND if there is a value in that field, the value of authorized field gets set to TRUE automatically

  • otherwise, value of authorized field remains FALSE unless a user sets it to TRUE. If this field value gets set to TRUE, it does not ever get "automagically" set back to FALSE, but may be changed back to FALSE manually by a user, or by explicit batch change, etc.

Note:

  • When a new term form is opened, there is no external_vocabulary_uri value. It will be entered by the user. So it seems like something needs to happen to change the value of authorized on form save?

  • If existing term with external_vocabulary_uri value is edited via form, and the existing authorized value = TRUE, and the edits include clearing the external_vocabulary_uri field (deleting its value), the value of authorized should NOT be changed to FALSE on save of form.

Not sure if this is possible, where to do it, or what the right search terms are to find out. The conditional fields module seems to be for something different.

Any pointers?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment