Closed (fixed)
Project:
Views (for Drupal 7)
Version:
7.x-3.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
21 Jul 2012 at 09:34 UTC
Updated:
4 Jul 2019 at 12:09 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
-Mania- commented+1
Comment #2
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 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 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 commentedWhy not? Optgroups does not override hierarchy in dropdown list.
Comment #8
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 commentedYep, it looks better. Removed one dash on every option as suggested.
Comment #10
chi commentedMinor code style fix
Comment #11
semiaddict commented#10 works great.
Thank you.
Comment #12
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 commentedhow and where do I install it?
Comment #14
Ante890 commentedTime to commit it ?
Comment #15
nimek commented+1 for commit very usefull functionality
Comment #17
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) 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 commentedNew patch.
Comment #20
Ante890 commentedComment #21
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 commentedReattached a freshly generated patch.
Comment #25
jespermb commentedI tested the patch and found a few issues which I have corrected.
Comment #26
aloyr commentedPatch#1695658-25 still works for me.
Comment #27
coconnor commented#25 does the trick :)
Comment #28
millerrs commented#25 also works for me. Thanks!
Comment #29
dmitryl commentedviews_optgroups-1695658-25.patch works. Thanks!
Comment #30
travisc commentedAlso tested and looks good, RTBC.
Comment #31
glynster commented+1 RTBC please!
Comment #32
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 commentedManually applied and works well as before please RTBC!
Comment #34
aloyr 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 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 commentedok, done. :) now that assignment is on its own line.
Comment #38
aloyr commentedComment #39
millerrs commentedI tested #37 and it works.
Comment #40
millerrs commentedComment #41
ryan osītis commentedI tested #37 and it's a winner. Works great.
Comment #42
simon georges 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 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 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 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 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.incin 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_nameis 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
$optionswas 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_nameon 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 commentedThat patch was originally based on the code from Taxonomy container module. PhpStorm complains on
$parent_namebecause 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()