Fieldable vocabs?

Alan D.'s picture

I needed to record some text against the vocabularies on our site and after a quick search of DO for modules, I couldn't find anything that would do this. Does anyone know of such a module?

This is a super trivial task, the entire code to get a textfield saved was just:

<?php
function fieldable_vocabularies_entity_info_alter(&$entity_info){
 
$entity_info['taxonomy_vocabulary']['fieldable'] = TRUE;
 
$entity_info['taxonomy_vocabulary']['bundles']['taxonomy_vocabulary'] = array(
   
'label' => t('Vocabulary'),
   
'admin' => array(
     
'path' => 'admin/structure/taxonomy',
     
'access arguments' => array('administer taxonomy'),
    ),
  );
}

function
fieldable_vocabularies_form_taxonomy_form_vocabulary_alter(&$form, &$form_state) {
 
$vocabulary = $form_state['vocabulary'];
 
field_attach_form('taxonomy_vocabulary', $vocabulary, $form, $form_state);
}
?>

I'm assuming that the Entity API module must be handling the field_attach_CALLBACK() functions, (or it may be core), but this is enough to save via the administration vocabulary form and load the data via the entity_load(). I haven't tested it, but I'd think File based fields would require some more work to get these successfully attached and saved.

This would be very useful code for users, so I'm tempted to publish it, but I'm finding it hard to believe that no-one else has done something similar.

Any feedback appreciated.

Comments

Working sandbox if anyone is

Alan D.'s picture

Working sandbox if anyone is interested: http://drupal.org/sandbox/aland/1608324

On a bare bones site, I had to implement the insert/update/presave/delete callbacks. I'm not sure on what contrib module is also doing this on the installation where the module was developed (about 150 modules in total)

Note that in D8, vocabulary entity may end up as a configuration object. If there is any sanity in the world, these objects will not be fieldable.

Fields in Core

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week