When you create a vocabulary, taxo.module automatically creates a $field using this vocab.
Yet, since this field is not tied to any existing bundle, field_ui doesn't propose it in the 'add existing field' list, and there's no way to actually attach the field to any actual entity.

Can probably be fixed as a simple bug in Field UI, but this also questions the actual UI workflow we want for 'add a vocab / apply that vocab to some node types'.
So, filing against taxonomy.module for now ;-)

CommentFileSizeAuthor
#32 taxonomy_no_auto_field-628244-32.patch6.29 KByched
#31 taxonomy_field.patch6.48 KBcatch
#29 taxonomy_field.patch6.5 KBcatch
#27 taxonomy_field.patch4.51 KBcatch
#25 make_yer_own_damn_field.patch4.48 KBcatch
#11 field_ui-all_existing_fields-2.png87.41 KBAnonymous (not verified)
#11 field_ui-all_existing_fields-3.png93.27 KBAnonymous (not verified)
#10 taxonomy_field_instances-628244-10.patch1.71 KBAnonymous (not verified)
#10 field_ui-all_existing_fields.png85.31 KBAnonymous (not verified)
#5 taxonomy_field_instances-628244-5.patch2 KBAnonymous (not verified)
#5 Tags | Drupal 7 (20091130).png57.82 KBAnonymous (not verified)

Comments

Anonymous’s picture

Whoops! Thanks Yched for matching the dupes.

IIRC, the reasoning for this was that the automatically created taxonomy term field for a vocabulary was going to be the one whose instance values populated taxonomy/term/% pages. This is not the case, though, and any taxonomy term field's instance values (for nodes only) will cause that node to appear on taxonomy/term/% lists.

I wish there were some UI/UX experts and advocates who could ponder this. This issue could be holding up help text, which means it has to be decided (or left to inertia) in the next few hours.

yoroy’s picture

Talked this through with catch and bangpound in IRC. The short version of the UX review: If the automagic step creates the WTF (it does) && this automagic step is an exception in that in other cases you always do it manually (it is), then remove the automagic step.

yched’s picture

If we remove the automagic field creation step, then the workflow becomes:
1) Create a vocab in admin/structure/taxonomy/add
2) Enable the vocab on some node types by:
a) Go to 'Manage Fields' for node_type_1, create a *new* field of type 'taxo term', give it the same label than your vocab (unless you actually want a different label), and configure it to use terms from your vocab
b) Go to 'Manage Fields' for node_type_1, add the *existing* field you just created
c) Repeat b) for other node types you want the vocab to appear in.

- That's a net loss from the D6 UX :-/.
- I also think the end result in most cases will be many separate fields on different node types - i.e users doing step a) on each node type -, instead of one shared field per vocab.
Thanks to the taxonomy_index table, this will make no difference for taxo/term/%tid listing pages, even possibly not for Views *node* listings.
But code-wise, it means that, if custom code needs to find out if $node has a given term, it needs to check $node->field_foo if node type is node_type_1, $node->field_bar if node type is node_type_2, etc. Sounds like a WTF.

Possible counter proposals:
- Add the 'content types' checkboxes in the 'create new vocab' workflow - this automatically creates a taxo field on the selected types. If no type is selected, no field is automatically created.
- On the creation of a new 'taxo term' field on a vocab for which there is already an existing 'automatically created' field, display a warning message like 'Is this really what you want to do ? You might want to do X instead.'.

Anonymous’s picture

I have some code that I wrote at the beginning of the taxonomy term fields work. This is a little old and uses the wrong function calls, but it does exactly what yched is describing.

http://github.com/benjamin-agaric/drupal-taxonomy-as-fields/blob/11ebd8b...

This only deals with node types, and it's got some little problems that would need sorting out before it could apply to HEAD.

I remember having a chat with Bojhan in IRC that putting taxonomy terms solely in the Field UI is far from ideal, and he was proposing to move it to the node content type edit form in #394482: Users should be able to enable a vocabularly from the content type configuration page.

Anonymous’s picture

This patch is made with git, and it's not finished.

Screenshot attached.

jhodgdon’s picture

So if this patch is applied, the taxonomy fields can be attached to content types either as fields or the way they were in D6? That seems like a bad idea...

Or does this just create and attach the fields? If so, can you then manage the fields in two ways (either from this screen or on the content type's manage fields screen)? That also seems like a bad idea.

Anonymous’s picture

The checkboxes create field instances attached to those node bundles. It does not return to the non-field-api way of using taxonomy.

The checkboxes are redundant with Field UI. Changes in taxonomy vocabulary administration form will be reflected in Field UI and vice versa. Perhaps yched was suggesting that we only use the checkboxes on new vocabularies?

yched’s picture

I was suggesting the duplicate approach. I'm not saying this is ideal. But this is better than either the current or #2-#3.

jhodgdon’s picture

It seems a bit strange to have the UI in two places. Very strange, actually.

Anonymous’s picture

This patch goes the other way. It deals with Field UI and its refusal to list fields with no instances as "existing." We lose labels, but those can be brought back when fields have instances.

A screenshot of what this looks like is also attached. It's not too awful, is it?

Anonymous’s picture

Here are some screenshots with more random fields in it.

The one named #3 uses option groups to group by field type.

At the field info level, we don't have a lot of "humanized" info... no labels, no descriptions.

webchick’s picture

I actually think #10 and #11 looks fine. When I was asked my opinion about this, I initially went the "keep the old D6 UI for taxonomy" route, but quickly back-peddled since we've done a lot of good work this release trying to remove one-off UIs. Field UI is a bit complex, but once people learn it, they can re-use that knowledge for almost anything.

I'm curious why this code was like that to begin with. Holdover from CCK? It seems natural that fields should instantaneously appear there once they're created, regardless of whether they're currently affiliated with an instance. Would be great of Barry or Yves could chime in on this design decision.

yched’s picture

re webchick #12:
The issue did not exist in D6 because there were no separate notion of fields and instances. The only way to have a field exist was to actually attach it to a node type. Had nasty WTFs, because when asking for info on one field (as in 'some data bucket'), you always got some instance-specific info along, from "one of" (random - possibly but not officially, the first in time) the node types the field appears in. So in D7 we separated $field and $instance.

The UI 'hides' that $field / $instance distinction, that would be complex for end users: all they see are 'fields on a given bundle' (i.e instances).
This also means that when a user does 'delete field', it's actually 'delete instance'.
UI has no way to delete a $field. When an instance is deleted, Field API takes care of deleting the field if it has no more instances (happens at the end of field_purge_batch()).

So I'm fine with patch #10 (and +1 on using optgroups in the 'add existing field' dropdown, as in #11 shot "-3.png" ).
I agree with webchick and support the "magically created 'term in %vocab' field" and the 'node type checkboxes' on vocab page - because without those, UX is terrible compared to D6, see my #3 above.

But we still have an issue with the following workflow:
- Admin creates vocab -> field taxonomy_$vid is created
- Admin creates instances for a couple bundles (either through the 'node types' checkboxes on the vocab form, or through 'add existing field' in Field UI)
- Admin later removes a couple instances -> when the last one is gone, the field is deleted
At this point, the field cannot be re-added through Field UI, and we're back at 'no default field associated to the vocab' and #3.

Maybe one solution would be a hook on instance deletion to let modules say 'keep the field around even if it's the last instance' ?

jhodgdon’s picture

Just a note: If you get around to patching this, please also update taxonomy_help() so that it explains the new way of doing things.

morbus iff’s picture

I've been fiddling with creating vocabularies from an .install file and had a bitch of a time trying to figure out how to do it, primarily because core seems to depend on the above in the install profiles:

  $vocabulary = (object) array(
    'name' => 'Tags',
    'description' => $description,
    'machine_name' => 'tags',
    'help' => $help,

  );
  taxonomy_vocabulary_save($vocabulary);
  $instance = array(
    'field_name' => 'taxonomy_' . $vocabulary->machine_name,
    'object_type' => 'node',
    'label' => $vocabulary->name,
    'bundle' => 'article',
    'description' => $vocabulary->help,
    'widget' => array(
      'type' => 'taxonomy_autocomplete',
      'weight' => 4,
    ),
  );
  field_create_instance($instance);

Innocent ol' me took a look at that and kept wondering how the the vocabulary vid was ever properly associated with the instance. Not knowing that these taxonomy_ fields were being created automatically by taxonomy_vocabulary_create_field(), I just kept trying to comprehend how it actually worked. I finally did figure out how to do it (or rather, I'm a lot closer than I was before), but these taxonomy_ versions of the fields are STILL being created, even if they're programmatically created elsewhere (as opposed to through the taxonomy.module UI):

  $libdb_vocabulary_endeavorers = (object) array(
    'name'          => 'Endeavorers',
    'machine_name'  => 'libdb_endeavorers',
    'description'   => t('FRBR Group 2 entities: Persons and Corporate Bodies.'),
    'help'          => t('Enter a comma-separated list of persons or corporations.'),
  );
  taxonomy_vocabulary_save($libdb_vocabulary_endeavorers);

  $libdb_m_authors_field = array(
    'field_name'  => 'libdb_m_authors',
    'type'        => 'taxonomy_term',
    'cardinality' => FIELD_CARDINALITY_UNLIMITED,
    'settings' => array(
      array(
        'vid' => $vocabularies['libdb_endeavorers']->vid,
      ),
    ),
  );

  field_create_field($libdb_m_authors_field);

The above actually ends up creating two fields - one through taxonomy_vocabulary_save(), and another through the field_create_field. Only one of them I actually want.

catch’s picture

So I keep going back and forth on this, but I think even if it's a pain in the short term we should not create these automagic fields and just do everything through the field UI. While in isolation it's more steps than it was in D6, having everything centralised in one place (and hopefully for more modules which used to act on nodeapi in contrib) should end up being a net-win, and especially for people who start off using D7 rather than upgrading from D6.

If we do keep the automagic, we should move it to a submit handler.

jhodgdon’s picture

catch: I am not sure what you are advocating here.

catch’s picture

@jhogdon - either remove the automatic creation of fields whenever a vocabulary is created, or restrict it to vocabularies created via the taxonomy UI.

morbus iff’s picture

I support removal of the automatic creation but, if not, the on-UI-creation only alternative.

yched’s picture

Magically creating the field only for UI created vocabs sounds valid to me.

I'm fine with removing the 'automatic field creation too' if webchick or Dries agrees to it, but I have to ask again: is the workflow described in #3 really what we want ?
It drastically raises the number of admin pages and clicks to enable a vocab on n node types, + raises the chances of misconfigurations (1 field per bundle, where actually one single, shared field was intended)

jhodgdon’s picture

I think we want people to think of Taxonomy like other fields. So if they create a vocabulary, they should then go to the content type to attach the vocabulary as a field to the content type, rather than having a special UI on the vocabulary page to do so (as was done in D6). If the field is auto-created and someone can add it to a content type by using "add existing field", that wouldn't be bad, but I also don't think it's all that much more of a difficulty to create it via "add new field".

A link/explanation in the help text from the taxonomy page(s) to the content type management page would be appropriate, if we didn't already put that in there.

The current situation, where the field is auto-created but you cant' possibly do anything with it, is obviously crazy. And I guess I'm not totally against having a one-time attachment UI when you first create a vocabulary, to attach it to some content types, but since several of the settings are set via Fields UI and are not on the taxonomy per se, I think this would actually be problematic.

yched’s picture

If the field is auto-created and someone can add it to a content type by using "add existing field", that wouldn't be bad, but I also don't think it's all that much more of a difficulty to create it via "add new field".

It's not more of a difficulty and that's the problem - that's what I point in #3:
"I also think the end result in most cases will be many separate fields on different node types - i.e users doing step a) on each node type -, instead of one shared field per vocab.
Thanks to the taxonomy_index table, this will make no difference for taxo/term/%tid listing pages, even possibly not for Views *node* listings.
But code-wise, it means that, if custom code needs to find out if $node has a given term, it needs to check $node->field_foo if node type is node_type_1, $node->field_bar if node type is node_type_2, etc. Sounds like a WTF."

The current situation, where the field is auto-created but you cant' possibly do anything with it, is obviously crazy

Well, not exactly, it's a bug, and we obviously can't ship as is :-)

yched’s picture

This being said, I can understand the argument that taxo fields should be handled like any other field, and that given some time and proper docs, users will educate themselves with the subtleties of "add new field / add existing field".
This distinction has always been one of the toughest things in CCK, though, and is not easily explained without saying the words 'storage location' or 'db table'...

catch’s picture

Status: Active » Needs review
StatusFileSize
new4.48 KB

Patch removes the automagic. Tag field still gets created in default install, any other taxonomy term you need to create the field first. I think this will make more sense to people now it's called a 'term reference' field - or at least as to people who already know what a reference field is.

Status: Needs review » Needs work

The last submitted patch, make_yer_own_damn_field.patch, failed testing.

catch’s picture

Status: Needs work » Needs review
StatusFileSize
new4.51 KB

Fixed the test.

Status: Needs review » Needs work

The last submitted patch, taxonomy_field.patch, failed testing.

catch’s picture

Status: Needs work » Needs review
StatusFileSize
new6.5 KB

.

yched’s picture

Status: Needs review » Needs work

Agreed that it's the best option at this point.

Nitpicks:

+++ modules/forum/forum.install	29 Jan 2010 06:16:49 -0000
@@ -21,14 +21,11 @@ function forum_install() {
+  // Create the forum vocabulary if it does not exist. Assign the vocabulary
+  // a low weight so it will appear first in forum topic create and edit
+  // forms.
+  $vocabulary = taxonomy_vocabulary_load(variable_get('forum_nav_vocabulary', 0));
+  if (!$vocabulary) {
     // Create the forum vocabulary if it does not exist. Assign the vocabulary
     // a low weight so it will appear first in forum topic create and edit
     // forms.

We duplicate the comment ?
Besides, I don't think there's still any correlation between the vocab weight and the position of the input element in the form ?

+++ modules/taxonomy/taxonomy.test	29 Jan 2010 06:16:50 -0000
@@ -323,6 +323,23 @@ class TaxonomyTermTestCase extends Taxon
+      // Set cardinality to unlimited so that select
+      // and autocomplete widgets behave as normal.

'as normal' makes sense in a 'coming from D6' angle, but I don't think core comments should look back. The comment can now go IMO (2 occurrences).
At least, the 80 chars wrapping needs fixing.

Powered by Dreditor.

catch’s picture

Status: Needs work » Needs review
StatusFileSize
new6.48 KB

Thanks yched, fixed.

yched’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new6.29 KB

RTBC. Attached patch just does additional comment fixing, don't credit me.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Cool. I assume if this broke something too horribly here, our tests would be screaming bloody-murder.

Committed to HEAD.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

bfroehle’s picture

Status: Closed (fixed) » Needs work
+++ modules/forum/forum.install	30 Jan 2010 18:43:07 -0000
@@ -42,6 +34,24 @@ function forum_enable() {
+  // Create the 'taxonomy_forums' field if it doesn't already exist.
+  if (!field_info_field('taxonomy_forums')) {
+    $field = array(
+      'field_name' => 'taxonomy_' . $vocabulary->machine_name,
....

We check to see if taxonomy_forums exists, but then create taxonomy_vocabulary_9 or whatever.

This cannot possibly be correct. See #1003308: Forum module cannot decide if it wants 'taxonomy_forums' hardcoded in it leading to faulty functioning.

Powered by Dreditor.

webchick’s picture

Priority: Critical » Normal
yched’s picture