Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Love the module, simple and much needed. However there doesn't seem to be Views support? I'm offering an exposed field to the users in Views and I would like the taxonomy selection list to have the nice format this module provides. Is this possible?
Comment | File | Size | Author |
---|---|---|---|
#49 | views-n1695658-49.patch | 2.34 KB | DamienMcKenna |
| |||
#49 | views-n1695658-49.interdiff.txt | 815 bytes | DamienMcKenna |
#46 | core-1695658-46-opt_group_support.patch | 2.32 KB | Simon Georges |
#37 | views_optgroups-1695658-37.patch | 2.4 KB | aloyr |
| |||
#34 | views_optgroups-1695658-34.patch | 2.48 KB | aloyr |
|
Comments
Comment #1
-Mania- CreditAttribution: -Mania- commented+1
Comment #2
Chi CreditAttribution: Chi commentedI think it should be fixed in views module.
Comment #3
dawehnerIt would be cool to name the internal key "optgroups", because this, at least for me, makes it much easier to understand.
Comment #4
Chi CreditAttribution: Chi commentedComment #5
dawehnerThanks for the change! From the technical perspective this patch is perfect, the only question i have is whether this should be actually implemented in views itself or in taxonomy container.
I will ask some people about their oppinions.
Comment #6
philipz CreditAttribution: philipz commentedThis option is just what I was looking for and the patch is simple and it just works. One question. Do we need
str_repeat('-', $term->depth)
in the 'Show groups in dropdown' option? This is no longer needed I think.Comment #7
Chi CreditAttribution: Chi commentedWhy not? Optgroups does not override hierarchy in dropdown list.
Comment #8
philipz CreditAttribution: philipz commentedWhen you add optgroups you add grouping to options which means hierarchy. It looks a bit different in major browsers but adding '-' in front of terms/options that are inside optgroups seems obsolete. The dashes are there only to visually imitate the hierarchy.
EDIT: OK now I see that the optgroups are only for the top terms aren't they? If so maybe there could be one dash less for every option level to make it look better?
str_repeat('-', $term->depth-1)
Comment #9
Chi CreditAttribution: Chi commentedYep, it looks better. Removed one dash on every option as suggested.
Comment #10
Chi CreditAttribution: Chi commentedMinor code style fix
Comment #11
semiaddict CreditAttribution: semiaddict commented#10 works great.
Thank you.
Comment #12
semiaddict CreditAttribution: semiaddict commentedI ended up having to make a small change on line 51 of the patch to make it work when the optgroup option is not selected, otherwise I got the following error:
Warning: str_repeat() [function.str-repeat]: Second argument has to be greater than or equal to 0 in views_handler_filter_term_node_tid->value_form() (line 147 of ../sites/all/modules/views/modules/taxonomy/views_handler_filter_term_node_tid.inc).
The modified patch is attached.
Comment #13
giufog CreditAttribution: giufog commentedhow and where do I install it?
Comment #14
Ante890 CreditAttribution: Ante890 commentedTime to commit it ?
Comment #15
nimek CreditAttribution: nimek commented+1 for commit very usefull functionality
Comment #17
Lang Wu Jane CreditAttribution: Lang Wu Jane commentedCan any one help to commit this functionality? Please
By the way, this patch works fine for me, but it seems that the configuration for optgroup couldn't be exported...
Comment #18
Anonymous (not verified) CreditAttribution: Anonymous commentedWhy isn't the views_optgroups-1695658-11.patch being committed within views? Views 3.13 was just released but I didn't see it.
I see Jane_wu's comment that it couldn't be exported; unfortunately I'm not familiar with the process. Any answers?
Comment #19
Ante890 CreditAttribution: Ante890 commentedNew patch.
Comment #20
Ante890 CreditAttribution: Ante890 commentedComment #21
jzavrl CreditAttribution: jzavrl commentedThis is not OK yet. When using the latest patch the localised terms are not being used. If you take a look at the previous implementation:
$choice->option = array($term->tid => str_repeat('-', $term->depth) . entity_label('taxonomy_term', $term));
It's using entity_label() which provides the localised term. I'm reattaching the new patch using this implementation and now the correct term label is being shown based on the current language.
Comment #23
jzavrl CreditAttribution: jzavrl commentedReattached a freshly generated patch.
Comment #25
jespermb CreditAttribution: jespermb at Adapt commentedI tested the patch and found a few issues which I have corrected.
Comment #26
aloyr CreditAttribution: aloyr as a volunteer and commentedPatch#1695658-25 still works for me.
Comment #27
coconnor CreditAttribution: coconnor commented#25 does the trick :)
Comment #28
millerrs CreditAttribution: millerrs commented#25 also works for me. Thanks!
Comment #29
dmitryl CreditAttribution: dmitryl commentedviews_optgroups-1695658-25.patch works. Thanks!
Comment #30
travisc CreditAttribution: travisc commentedAlso tested and looks good, RTBC.
Comment #31
glynster CreditAttribution: glynster commented+1 RTBC please!
Comment #32
Ryan Osītis CreditAttribution: Ryan Osītis commentedAnyone know why this hasn't been committed? It works well and should have been included in the 7.x-3.19 release. Anyone know if we need to re-roll the patch in #25?
Comment #33
glynster CreditAttribution: glynster commentedManually applied and works well as before please RTBC!
Comment #34
aloyr CreditAttribution: aloyr as a volunteer and commentedPatch #25 works, but doesn't apply cleanly.
Updating it to run on git ref 481b5c28 (current for 7.x-3.x branch as of 2018-04-19).
Comment #35
millerrs CreditAttribution: millerrs commented#34 works for me.
Comment #36
DamienMcKennaA minor request - could you please revert the change so that the $tree assignment is on a separate line, instead of nested inside an if() statement? Thanks.
Comment #37
aloyr CreditAttribution: aloyr as a volunteer and commentedok, done. :) now that assignment is on its own line.
Comment #38
aloyr CreditAttribution: aloyr as a volunteer and commentedComment #39
millerrs CreditAttribution: millerrs commentedI tested #37 and it works.
Comment #40
millerrs CreditAttribution: millerrs commentedComment #41
Ryan Osītis CreditAttribution: Ryan Osītis commentedI tested #37 and it's a winner. Works great.
Comment #42
Simon Georges CreditAttribution: Simon Georges at Makina Corpus commentedFor those who may need it, the same patch for core 8.6.x, which seems to work exactly the same way.
Comment #44
Chi CreditAttribution: Chi commentedI don't think this will ever be fixed in Views - 3.x. Moving to core issue queue since the Views module is a part of Drupal 8 now.
Comment #45
Simon Georges CreditAttribution: Simon Georges at Makina Corpus commentedJust in case it ever get committed, all credits for this patch goes not to me, but to precedent authors, I merely copy-pasted it in the right (it seems) Drupal 8 core file.
Comment #46
Simon Georges CreditAttribution: Simon Georges at Makina Corpus commentedBetter patch, with childless first-level terms taken into account.
Comment #48
DamienMcKennaPlease create a new issue and relate this one to it for the core changes.
Moving this back to Views for D7.
Comment #49
DamienMcKennaRerolled, plus a small tweak.
Comment #51
DamienMcKennaCommitted. Thanks!
Comment #52
Chi CreditAttribution: Chi commentedThe follow-up for Drupal 8.
#3025542: Support optgroups for taxonomy selection list in Views
Comment #54
m.stentaThis change causes the following PHP notices and warnings to appear:
Looking at line 237 of
views_handler_filter_term_node_tid.inc
in PHPStorm, the IDE warns that "Variable $options might have not been defined". It seems as if this change added conditionals that under certain conditions result in the variable not being created.In addition to that, on line 165 the variable
$parent_name
is used without being defined as well (this appears as a red underline in PHPStorm, which is more severe than the "might have not been defined" on line 237.Comment #55
m.stentaWhy was line 148 removed in this commit?
https://git.drupalcode.org/project/views/commit/a19d7d8#a8d18f38f8f4cfe0...
That is where
$options
was initialized:Comment #56
m.stentaIt appears that the patch in comment #19 above is where this line was removed - without explanation. And that went undetected.
I will open a new issue and provide a patch to restore that line.
Comment #57
m.stentaHere is the new issue with patch: #3065777: Notice: Undefined variable: options in views_handler_filter_term_node_tid->value_form()
Comment #58
m.stentaI still don't know what to do about the undefined
$parent_name
on line 165: https://git.drupalcode.org/project/views/blob/2c4f62ade0af1a2541b1bd1a92...@Chi - can you take a look at that? Maybe you can see how to fix it?
Comment #59
Chi CreditAttribution: Chi commentedThat patch was originally based on the code from Taxonomy container module. PhpStorm complains on
$parent_name
because that variable is defined conditionally. However, it does not cause any PHP errors. When PHP accesses that variable it is always defined because of the way terms are sorted.You can tell PhpStorm about that fact with the following notation.
/** @var \Drupal\taxonomy\TermInterface $parent_name */
Comment #60
m.stenta@Chi - Oh I see how it works now - thanks for the explanation. Looks good! So I think the only thing that needs to be fixed is #3065777: Notice: Undefined variable: options in views_handler_filter_term_node_tid->value_form()