Open steinmb opened 7 years ago
@elmcip wrote: The ideal thing would be that whenever someone creates a new tag, they are prompted to define it.
We add terms by freetagging that make it a little more interesting:
Perhaps we can run the validation when the record get saved? function taxonomy_field_presave() run and I see that it implement a hook we can use. https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_field_presave/7.x
Not sure though how the UI should be. Anyone?
Put term creation by freetagging through my debugger to try to figure out the order what data we have. This is the typical order:
taxonomy_field_presave() -> taxonomy_term_save() -> field_attach_presave()
Tested hooking in with hook_field_attach_presave(). If we check if the taxonomy term is lacking a ID then we know it is a new one. This code just add a fixed text tring before it get created and that work just fine.
/**
* hook_field_attach_presave(),
*/
function elmcip_setup_field_attach_presave($entity_type, $entity) {
if ($entity->vocabulary_machine_name == 'vocabulary_1') {
if (!$entity->tid) {
$entity->description = 'Machine populate description.';
}
}
}
No idea though how we should turn this into a good end user experience.
Got non working code here. It sniffs out the new terms and create and validate a custom form, though I have not yet found out how to get back to the node form validation.
commit 29e7b14ea8234bc71a6d217c523275fa188449b5
Tricky. Moving to next release.
Split this off from #294 where we made facilitated users to add/edit existing terms. We think it would improve our data set if every time a new term is created the user is forced to add a description.
Suggested fix
TBD
How to test
TBD