Closed (duplicate)
Project:
Drupal core
Version:
8.3.x-dev
Component:
other
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
6 Jun 2014 at 20:28 UTC
Updated:
30 Sep 2016 at 22:00 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
larowlanShouldn't we be refactoring the node type condition into a generic content entity bundle condition? Custom block type also in core but plenty of contrib module examples too
Comment #2
kim.pepperDiscussed this with @tim.plunkett and agreed that #1932810: Add entity bundles condition plugin for entities with bundles is a feature, and that it's less likely to get considered at this point. In the meantime, creating plugins is a task, and fairly straight forward. I think it's best to move this discussion to that issue.
Comment #3
kim.pepperInitial implementation based on node type.
Comment #4
kim.pepperComment #5
tim.plunkett$this->t()
No isset needed if you put 'bundles' in defaultConfiguration()
The test looks good.
Comment #6
kim.pepperThanks.
Comment #7
tim.plunkettI meant this:
Comment #8
kim.pepperAh yes, of course!
Fixes for #7.
Comment #9
tim.plunkettThis shouldn't bother trying to get the context value if no bundles are configured. See the changes to NodeType in #2283929: Clean up condition plugins to have schema support and to allow them to be optional for an example.
This should also provide a schema entry, see that issue as well.
Comment #10
kim.pepperFixes for #9
Comment #11
jibran@kim.pepper and @tim.plunkett nice work on condition plugins.
Just like #1 I am unable to understand why are we adding and working on redundant code? We can do it in #1932810: Add entity bundles condition plugin for entities with bundles for all bundles. Tomorrow someone will need condition plugin for comment type, feeds or contact form categories those all are in core as well I know contrib can add it but why not contrib add this condition as well this is not used by core and I haven't seen any road map to add it to blocks visibility.
Comment #12
kim.pepperHi Jibran,
I believe @tim.plunkett has answered this on #2278541-64: Refactor block visibility to use condition plugins
Kim
Comment #13
berdirLots of minor feedback.
Tested this with overriding a term page with page_manager and then displaying different variants based on the vocabulary. Works well with #2287621: Add tests for context mapping for blocks and context fixed.
Would be more consistent to name the context "taxonomy_term"?
This is consistent with what we have, but I'm not a big fan of those super-short class names, VocabularyCondition would imho be better if we would chose freely, much easier to find than "Vocabulary" because you then have to pick the class in the right namespace.
I'd suggest to name this vocabularyStorage?
References the old name...
Also, @inheritdoc doesn't work like that, you have to duplicate the @param's, it's not an inline placeholder..
parent usually comes first?
Why do we need the taxonomy config?
use Unicode::strtolower() ?
Should use the interface (LanguageInterface)
mt_rand() in tests has been problematic before, unless we need it somehow for the test, I would just leave it out, it's not necessary to specify it explicitly.
You can use Term::create() for this now.
Comment #14
kim.pepperThanks for the review, @Berdir. Fixes for #13.
Comment #16
tim.plunkettThis should end
) + parent::defaultConfiguration();Comment #17
kim.pepperFixes #16.
Comment #18
berdirUpdate looks good to me, RTBC from me but @timplunkett should probably confirm the name change and if he's OK with that.
Comment #20
berdirActually...
That's the wrong, default configuration needs to be added to the top level array, not to bundles.
This is currently causing a notice on the block page (where this now automatically shows up..)
Comment #21
berdirAlso, the vocabulary checkboxes field is required, that probably breaks most of those tests, because it can't save block settings anymore.
Comment #22
kim.pepperFixes for #20 and #21.
Comment #23
kim.pepperDon't show vocabulary condition on block visibility form.
Comment #25
tim.plunkettHmm, I was wrong about doing this here. It should be done up in baseConfigurationDefaults, before its ever used for the form.
The reason the test fails is because it's still being called in submit
Comment #26
kim.pepperFixes for #25
Comment #27
tim.plunkettNothing left to do here, IMO.
Thanks @kim.pepper!
Comment #28
jibranI have added #2288861: Add vocabulary condition to block visibility.
Comment #29
kim.pepperRe-roll after #2281635: \Drupal\Core\Plugin\Context\Context should use a ContextDefinition class instead of arrays went in.
Comment #30
tim.plunkettRerolled because the current theme condition also was unset()ing itself in the same spot.
Comment #34
jibranCan we make it multi line?
Doesn't it start with /**?
Removed now.
in in
Comment #35
kim.pepperChatting with @chx in IRC he suggested dropping the name "bundle" and "bundles" in favour of just "vocabulary" and "vocabularies" as it is confusing. Seems like a reasonable request.
Comment #37
cbr commentedRerolled and reviewed.
@jibran: I changed all your suggestions except 1, didn't find another example of ContextDefinition using multi line.
@kim.pepper: Changed bundle & bundles to vocabulary and vocabularies.
Did some minor updates i.e. added FormStateInterface to $form_state and renamed randomName() to randomMachineName().
Comment #39
kim.pepperThanks @cbr.
This change is incorrect, as it is about content types, not vocabularies.
Comment #40
cbr commentedRenamed content type vocabularies to bundles.
Comment #41
kim.pepperLooks good to me.
Comment #42
xanoWhy wasn't PHPUnit used to write the unit test? If there is no technical reason against it, we should probably set this issue back to needs work so the test can be converted.
Comment #43
kim.pepperEclipseGC argued against unit tests for the RequestPath condition plugin over here [#1921544#comment-8801739]. Not sure if that still applies here.
Comment #44
alexpott@Xano: Well once KernelTestBase(ng) lands it will be a PHPUnit test :)
I think we need to check if the condition is negated to produce the correct summary test.
I'm not sure I get this logic - if we don't set a vocabulary then all terms match. If you tests and call the summary method then the result is quite weird.
PHPDoc blocks for these functions need @param and @return as appropriate.
Comment #45
undertext commented@alexpott : The logic of summary() and evaluate() methods is taken from NodeType condition. (\Drupal\node\Plugin\Condition\NodeType)
So we should create a new issue and fix NodeType condition too.
Comment #46
arla commentedRerolled and fixed some doc in VocabularyConditionTest, including #44.3.
Comment #48
arla commentedMeh, last .patch was the interdiff. This is right.
Comment #50
berdirThis should be $form_state->getValue('vocabularies')
Comment #51
pivica commentedFor #51 here is a correct change
Comment #52
Anushka-mp commented$form_state['values']['vocabularies'] changed to $form_state->getValue('vocabularies')
Comment #53
alexpottThis issue is a normal task that adds new functionality, and per #2350615: [policy, no patch] What changes can be accepted during the Drupal 8 beta phase?, we should discuss the priority of this issue and whether or not we should postpone until 8.1.x
Also is this not a feature given #1932810: Add entity bundles condition plugin for entities with bundles?
Comment #54
berdirThe only problem right now is this, only core can exclude certain conditions from the UI right now.
I actually need this feature, but I don't really care if it is in core or not. So if you don't want to add it to 8.0.x, then move the issue to 8.1.x and we'll start a small contrib module if people are interested or keep it in a custom module for now.
Comment #55
berdirOk, I agree that it is too late for this for 8.0.x.
As I am actually using this as mentioned, I created https://github.com/md-systems/vocabulary_condition
That's easier to track than a core patch until we can re-consider this for 8.1.x, but maybe we'll do #1932810: Add entity bundles condition plugin for entities with bundles then?
Comment #56
xanoThe
NodeTypeis a lie. Let's just leave out the class name here.Is there a reason why we do not provide a generic entity condition, or separate plugins using derivatives?
Comment #59
guschilds commentedBefore discovering this issue I built this functionality based on the NodeType condition. I went ahead and created a sandbox project for it: Vocabulary Condition.
It was only a few comments ago (#55) that another project was linked to for this functionality, and I hate to throw another in the mix instead of collaborating, but that was 2 years ago and that project no longer works. Neither does another alternative I came across, Entity Block Visibility.
I also hate to throw yet another project up instead of contributing a core patch, but again, after a year or two, the desire and direction for a core patch for this is unclear to me at this point. If a core committer were to say "yes, the approach taken in your project is something we want in core (or close to it)", I can take the time to create a patch for that (I'll need to add tests). Otherwise, if nothing else, perhaps others wanting this functionality will see this issue and be lead to the sandbox.
Comment #60
berdirClosing as duplicate of the issue mentioned in #55.
ctools for example has generic entity bundle visibility conditions built in and it works fine.