Center-for-Digital-Narrative / elmcip

Electronic Literature as a Model of Creativity and Innovation in Practice (ELMCIP) is a collaborative research project funded by Humanities in the European Research Area (HERA) JRP for Creativity and Innovation built in Drupal
https://elmcip.net
4 stars 0 forks source link

Allow end users to add taxonomy term description while freetagging #298

Open steinmb opened 7 years ago

steinmb commented 7 years ago

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

steinmb commented 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:

  1. The terms get added when user edit/add a record and enter data into the term field.
  2. We then av a mix of existing and perhaps new one.
  3. What next?

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?

steinmb commented 7 years ago

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()
steinmb commented 7 years ago

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.

steinmb commented 7 years ago

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

steinmb commented 7 years ago

Tricky. Moving to next release.