Closed (fixed)
Project:
Metatag
Version:
7.x-1.x-dev
Component:
Views integration
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
25 Nov 2013 at 22:06 UTC
Updated:
7 May 2018 at 22:05 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
djschoone commentedComment #2
vlooivlerke commentedThis will be a valuable add on for the meta module as there is no dynamic way to create meta data for a view at this stage.
I have a city view that shows cities via an argument. imagine now each city page could have its own meta title and description populated by the first row of views tokens
Holding thumbs some super genius drupal developer needs this too.
Comment #3
bpleduc commentedI have made a fix to allow Pattern Replacement in the Metatag Views module. You are now able to use any field in your Metatags. Support for nested tags is also included.
Comment #4
damienmckenna@bpleduc: Thanks for the patch. Please don't forget to change the issue status to "needs review" when you upload a patch, that'll test it a little and notify me (and others) that there's a patch to review.
Comment #5
cimo75 commentedWorking here, thanks for the patch!
Comment #6
yurg commentedPatch was tested, works for me, thank you!
Comment #7
kopeboyNice feature, can we include it in a stable release?
Comment #8
bjalford commentedWorks for me too
Comment #9
vlooivlerke commentedyes please comment it
Comment #10
damienmckennaThe patch needs a little tidying to match the Drupal coding standards, but it looks promising!
Comment #11
bpleduc commentedDrupal Standards Coding edits.
Comment #12
damienmckennaThanks. This still needs some further work to meet the code standards, though, e.g. comments must be complete sentences and wrap at character 80, add a space between "foreach" and the parenthesis, etc.
Comment #13
bpleduc commentedHopefully I have them all now :)
Fixed "foreach" spacing before parenthesis and made comments sentences with wrapping at character 80 :)
Comment #14
damienmckennaI made a few additional small tweaks.
Comment #15
lquessenberry commentedI am going in circles here. How do you actually patch this? I have tried everything I can try to patch this thing and it keeps asking me which file I want to patch.
Comment #16
damienmckenna@lquessenberry: You need to run the "patch" command from the metatag directory, not from your site's root directory - please see Drupal's documentation for further details.
Comment #17
davidthou commentedThanks for the patch, rolling an updated patch for stable version (1.4).
Comment #18
lquessenberry commentedThanks for the response. I did that at first and I think I may have had issues with the patch I was using. Thanks for the help. Trying #17 now.
Comment #19
lquessenberry commentedThe patch worked in #17. Thanks fellas.
Comment #20
tribsel commentedhi, i used patch in #17, but nothing happened. I get a same list of tokens as before. Id like to use either metatags from taxonomy term /title, description/ or from view fields. View's description is for administration pages and users, not to be added to page.
Comment #21
pingwin4egFrom the patches it seems that you forgot about placeholders from contextual filters: !1, %1, etc. Is it so? Or maybe I am missing something.
Comment #22
damienmckennaComment #23
damienmckennaI tested it out, but it didn't use the values from the first row, it used them from the last row. Is this as expected?
Comment #24
bpleduc commented@DamienMcKenna - Yes that is as expected.
Comment #25
damienmckennaSo is that really the "first row"? :) Not trying to nitpick, it's just that the output seemed contrary to what the UI indicates would happen. Other than this quandary, I'm happy with the patch, I just don't want to mislead people.
Comment #26
bpleduc commented@DamienMcKenna - I'm a little confused about this. The patch does not add the checkbox as suggested originally. It just allows you to use your views fields as replacement tokens in Metatags.
Where are you seeing the UI mention that the first row is being used?
Comment #27
damienmckennaI've moved this patch into a separate issue focus on just adding the tokens for the first values: #2396693: Add Token support to insert values from the Views results
Lets re-focus this on the original request, see if it'd be possible.
Comment #28
damienmckennaClarifying that this is for Views' built-in replacement tokens, not the Tokens integration which is in #2396693: Add Token support to insert values from the Views results.
Comment #29
gunwald commentedI tested the patch in #17 but I get a php error:
Comment #30
drunken monkeyAnother attempt: is this about what you had in mind here?
I'm not too familiar with the Metatag module, unfortunately, but it seems to work alright. The code comes more or less directly from
views_handler_area_text.One thing I'm wondering about, though, is the
options_definition()method: I also added the new option there, but it doesn't seem to have any effect? Even when correcting the typo (it'soption_definition()normally in Views) and the method actually does override the parent method, it doesn't seem to work for display extenders. So probably we should just remove that method?Comment #31
herd45 commentedI've tested #30 on the latest dev and it works as expected.
Comment #32
drunken monkeyAfter a bit of testing it turns out that this runs into problems when Views output caching is used, since the field tokens will then not be available.
Does anyone have a good suggestion to solve that problem? Should we try to somehow just trigger rendering of the first row before calling
tokenize_value()? Or implement the functionality ourselves as a fallback? Or, maybe, we could try to add our own information to the cache and restore it from there, getting additional cachability as a bonus – could that work?Comment #33
damienmckennaIs the problem that the results don't populate at all, or that on the second page request the tokens are empty because they were cached on the first page load?
Comment #34
drunken monkeyAt the second page request (and all subsequent ones served from cache), the
<title>content will be something like "[project_name] issues". At the first, uncached page request, everything works fine.Comment #35
damienmckennaOk, you know what that means then :)
Comment #36
drunken monkeyI managed to fix it quite easily, by just triggering manual rendering of the first restults row, if necessary. I also played around with adding the Metatags information to the Views output cache, but I couldn't get that to work – the Views cache plugin just isn't flexible enough for such special use cases.
It seems to me the Metatag Views module is completely untested, so I don't think it should be part of this issue to change that.
Comment #37
damienmckenna@drunkey monkey: Maybe there could be some (optional?) caching on the Metatag output at that point? Otherwise it may have to live on as a Known Issue.
Comment #38
damienmckennaFYI I have some tests for Metatag:Views as part of #2564483: Cannot translate metatags after last update anymore.
Comment #41
akoepke commentedI have just been testing this patch and noticed one bug. When there are results the patch works fine but if the View has no results then the tokens are left in the metatags. So the title of the page becomes "[title]".
Detecting that there are no results isn't that difficult but we need to have some way of entering some default values to use in this case. Really don't want to duplicate the entire Metatag form (very long!) for a set of default values.
Comment #42
thirdender commentedThis patch was very important to a project I'm working on right now. Basically, it's a site to track lost pets, and one of the critical features is the ability to share the pet's page on social media. I set up a View page to publicly display the pet's information, but the only way to get the pet photos into the meta tags is using this patch.
I wasn't able to apply the patch directly to the 7.x-1.x branch on git. I rerolled the patch against the latest commit on git, but I had to change a few things outside of the scope of the patch to get it to apply. Off the top of my head,
check_plainwas added on line 17, the call tometatag_translate_metatagswas changed, and the comment// Update the i18n strings.was moved.Comment #43
g33kg1rl commentedI tested the patch from #42 and it worked for me. :) The only issue I ran into was when I tried to create a backup I received an error about the cache_token from mysql being too large.
Comment #44
nchase commentedPatch #42 works for me.
Comment #45
philsward commentedHope to see this committed soon... I too would like to add images to a view and while I haven't tried the patch yet, totally expected to be able to use the tokens from within the view to do it.
Any timeline on incorporation?
Comment #46
ruha commentedI can confirm that #42 is working well. Thanks for the hard work.
Comment #47
unstatu commentedI confirm #42 also worked for me.
There are 5 people including me that applied the patch successfully. I'll change the status to RTBC.
Comment #49
damienmckennaCommitted. Thanks everyone. FYI I've moved the test coverage into a separate issue: #2912483: Add test coverage for Metatag:Views "Use replacement tokens from the first row" feature
Comment #50
jasonschweb commentedI'm still having trouble with this when cache is enabled on a search_api view. Meta Description is present when the content is first viewed, but subsequent requests do not have it.
Tried enabled metatag cache, which did not solve the problem. Also disabled authcache - the only other cache we are using.
Comment #51
jasonschweb commentedSo far while debugging, I've discovered that
tokenize_valueis returning an empty array due torow_tokensmissing all the values. It looks like the field I'm using for metatag is also missing from$view->resultwithin_metatag_views_render_first_row.Comment #52
damienmckenna@jasonschweb: I'm sorry you're having problems with this. Please open a new issue and we'll see what we can do to help fix the problem.
Comment #53
jasonschweb commented@DamienMcKenna: No problem, created new issue here: https://www.drupal.org/node/2914921
Comment #55
alex.bukach commentedIs it implemented for D8?
Comment #56
damienmckenna@Alex Bukach: No, so I opened #2952229: Allow Views meta tags to "Use replacement tokens from the first row" (D8).
Comment #57
hossein425 commentedAs reported in #41 by @akoepke, when no results, values of "NO RESULTS BEHAVIOR" should be used if there is a single "Global: View area" and if there is more than one "Global: View area" or other cases, there should be "Global: Meta tags", to avoid public exposure of not replaced tags.
Comment #58
akoepke commentedYep, 2 years later and this issue still persists. Replacement tokens from the first row in Metatag works well until there are no results and then we end up with un-replaced tokens in the tags instead.
Comment #59
damienmckennaPlease open a new issue for remaining problems with this functionality.