The content of my site is divided in two vocabulary, each of one containing some dozens of terms (and sub-terms). TAC is configured so that a given role is allowed to publish content only in a given "base" term, and its sub-terms. That is, a given user, when editing a "story" node, sees a vocabulary drop down list containing the term and subterms he is allowed to publish in, but also sees another which is empty: the only thing it shows is .

For TAC to be more user friendly, I would like it to hide any vocabulary selection list that does not contain anything more than the term option.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ricflomag’s picture

Project: Taxonomy Access Control » Drupal core
Version: 4.7.x-1.x-dev » 4.7.4
Component: User interface » taxonomy.module

This bug report was originally posted for module Taxonomy access control... But i think the right place is here.

Short version : when editing a node, the user gets a number of drop down list to select terms to associate to the content (one per vocabulary). Under some circumstances, the list might be empty, only showing the "none" option. Is this case, the list should just not show.

Example : the content of my site is divided between two main vocabularies, each of one containing some dozens of terms (and sub-terms). The taxonomy access control module is configured so that a given role is allowed to publish content only in a given "base" term and its sub-terms. That is, when editing a "story" node, a given user sees a vocabulary drop down list containing the term and subterms he/her is allowed to publish in, but also sees the list from the other vocabulary, where publishing is not allowed under any term. This list is useless and confusing: the only thing it shows is "none".

cburschka’s picture

Version: 4.7.4 » 6.x-dev
Assigned: Unassigned » cburschka
Status: Active » Needs review
FileSize
1.03 KB

I can fix this, I think.

Rolled against HEAD; makes _taxonomy_term_select return array() when there are no non-"blank" terms. I return array() instead of NULL because I seem to remember that the Form API got notice- or even warning-level hiccups on NULL elements... could be wrong though.

I have tested this successfully with a simple empty vocabulary, but I may have missed some more complex cases if any exist.

Also fixed two notice-level errors for $_POST elements on line 1444.

catch’s picture

Status: Needs review » Needs work

No longer applies.

cburschka’s picture

Status: Needs work » Needs review
FileSize
559 bytes

One of the two functions changed in the patch has moved to an admin.inc file. On checking this file, it turned out the change of the patch has already been implemented (character for character). The revised patch therefore contains only the first hunk.

catch’s picture

Version: 6.x-dev » 7.x-dev
Status: Needs review » Needs work

Still applies with fuzz to D7. We should add a test for it.

cburschka’s picture

Here's the defuzzed D7 patch.

I'll try a test case if my testing setup works right now. It seems to randomly blow up in my face sometimes.

marcingy’s picture

Version: 7.x-dev » 8.x-dev
Category: bug » task
Issue tags: +Needs backport to D7

This still holds true for require fields with no data although as we are now working off fields api the apoproach needs to change and arguably this is a task rather than a bug.

catch’s picture

Component: taxonomy.module » field system

Going to move this to field system.

amateescu’s picture

Version: 8.0.x-dev » 7.x-dev
Issue summary: View changes
Status: Needs work » Closed (won't fix)
Issue tags: -Needs backport to D7

_taxonomy_term_select() doesn't exist anymore, not even in D7: #603702: Die, _taxonomy_term_select(), die!

David_Rothstein’s picture

Version: 7.x-dev » 8.0.x-dev
Status: Closed (won't fix) » Needs work
Issue tags: +Needs backport to D7

This is still reproducible in both Drupal 7 and 8. Just create a vocabulary with no terms in it, then add a (non-required) term reference field that uses that vocabulary, and set the widget to either checkbox/radios or a select list.

When creating content, you'll see a widget that has no options besides "N/A" or "None" in it.

That looks pretty ugly. Although in some sense it's a site configuration issue, it is still probably something Drupal should handle better.

David_Rothstein’s picture

Title: Empty term list should not show when editing a node » Empty options list should not be shown when editing a field that has no allowed values (for example, a term reference field whose vocabulary has no terms)

Retitling a bit based on #7 and #8 (since in D7/D8 this is not specific to taxonomy).

amateescu’s picture

Assigned: cburschka » Unassigned
Status: Needs work » Needs review
FileSize
2.9 KB

Hm.. interesting. This is be a possible fix, but I think the real question is: do we really want to hide the widgets in that case? Wouldn't it cause more confusion than showing only the "N/A" or "None" value?

Status: Needs review » Needs work

The last submitted patch, 12: 108337.patch, failed testing.

amateescu’s picture

Version: 8.0.x-dev » 8.1.x-dev

Moving to 8.1.x since it's not a bug.

amateescu’s picture

Status: Needs work » Needs review

Back to NR, but it actually needs a usability review.

The last submitted patch, 2: taxonomy_empty_select.patch, failed testing.

The last submitted patch, 4: taxonomy_empty_select-108337-4.patch, failed testing.

swentel’s picture

And what if the field is required ?

amateescu’s picture

Issue tags: +Needs usability review

Let's try this tag :)

yoroy’s picture

Testing #12 with the scenario described in #10, making the field not required.

1. I guess this patch hides the input element when there's nothing to enter? Because I don't see it on the node form :)
2. When you make this field required you cannot save the node form, getting an error "This value should not be null."
3. Another interesting side effect:

- I initially create the field as not required
- then configure the form display to check boxes/radio buttons
- Go back to edit the field (/admin/structure/types/manage/article/fields/node.article.field_emptyvocab) and without changing anything save settings: BOOM! "Fatal error: Call to a member function uuid() on a non-object in /home/r0re7/www/core/lib/Drupal/Core/Field/EntityReferenceFieldItemList.php on line 131

Could we do something along the lines of the empty pattern we have for listings on admin pages? The table on /admin/structure/taxonomy/manage/no_term_vocab/overview will show "No terms available. Add term.", where Add term is a link.

We want to prevent people from getting into this situation in the first place. Can we detect it and:
- for site building: use the empty pattern with the Add term link?
- for content creation: show "No terms available" but let them save the content item anyway (and store "None" as the value)?

yoroy’s picture

Status: Needs review » Needs work
amateescu’s picture

Thanks @yoroy for taking a look at this :)

You are right that we can and should provide separate output for the two situations. However, there are a few problems with the suggested approach:

- for site building: we can use the empty pattern here, but the "Add term/entity" link is problematic because entity reference fields can have multiple target bundles (e.g. vocabs, content types) so we do not know which bundle to use for the 'Add' link

- for content creation: this one is even trickier because having any kind of output from the widget (i.e. a form element or just some simple markup) will trigger all kinds of entity validation code paths, and we'll have to find a way to bypass all of them, but at least in theory I think it's possible :) So, before even attempting to find a way to bypass validations for this case, are we really sure that it is desirable to show the 'No terms/entities available' text even if the content author doesn't have any way to "fix" that?

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

yoroy’s picture

I think it makes sense to show a 'no items available' message (without the link) for both scenarios because the author might be the builder as well and so would have a way to fix things. Even if the author could not fix it, she or he could at least know and tell somebody else there's something missing.

(This generalized entity concept sounds problematic for turning Drupal outside in! If we can't know what kind of thing some widget is targetting, that will make it very hard to map UI flows to specific user expectations. At least, that's what I am getting from this)

yoroy’s picture

Hmm, maybe hide everything for the content creating part after all, as long as there are no errors shown either.

Bojhan’s picture

Issue tags: -Needs usability review

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.