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.
Need to add new robots tags: max-snippet, max-image-preview, max-video-preview. See here: https://developers.google.com/search/reference/robots_meta_tag
Comment | File | Size | Author |
---|---|---|---|
#70 | metatag-n3083743-70.patch | 6.76 KB | DamienMcKenna |
#66 | metatag-3083743-66.patch | 8.53 KB | osopolar |
|
Issue fork metatag-3083743
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
szeidler CreditAttribution: szeidler at Ramsalt Lab commentedThis is going to be interesting. Currently we use a
checkboxes
element and simply concatenating the values. Now we have additional properties, separated by a colon.max-snippet
andmax-video-preview
requires a number fieldmax-image-preview
requires a select fieldComment #3
druhu CreditAttribution: druhu as a volunteer commentedI really need these new tags, google sent me a reminder today:
Comment #4
druhu CreditAttribution: druhu as a volunteer commentedComment #5
DamienMcKennaRelated: #3068572: Add support for googlebot_news meta tags (D8)
Comment #6
Anonymous (not verified) CreditAttribution: Anonymous at Agiledrop - Your Trusted Drupal Teammates commentedComment #7
DamienMcKennaComment #8
DamienMcKennaComment #9
maticb CreditAttribution: maticb commentedI have tested the above patch and can confirm it's output is correctly shown on the configured page.
I have also checked the PHPUnit test and it seems to fail on this line
Just before that we go to a view
I do not think this test fail is related to the patch provided above, seems unrelated. It fails because this view contains a contextual filter "Content: Created year + month" which is "Overridden"
Comment #10
maticb CreditAttribution: maticb commentedComment #11
DamienMcKennaThe test failures need to be resolved.
Comment #12
maticb CreditAttribution: maticb commented@DamienMcKenna, the test fails on an unrelated view('/admin/structure/views/view/archive'), not sure why we would fix this in this issue? I looked over it and we simply cannot do the assertion:
because with a clean Drupal 8 install, this text already exists.
Comment #13
erwangel CreditAttribution: erwangel commentedWill this feature be backported to D7 ? We really need it, and I suppose several of News sites still under D7 do it as well. Google removed description and all snippets of my site's lines appearing in search results - only a poor title shows - according to it's statement on EU Directive 2019/790 (see above @druhu #3)
Comment #14
DamienMcKennaI added a new issue for a backport: #3106692: Add Google's new robots tags (D7)
Comment #15
Anonymous (not verified) CreditAttribution: Anonymous commentedThoses line could generate error
You need do check if $value_other[1] exist
why use in_array instead of array_key_exists ?
Comment #16
IT-Cru@DamienMcKenna: Is it possible to adapt code from D7 to get this also working on D8?
Problem is, that current provided D8 patch breaks robots metatag when saving a content, because in setValue() method new form structure is not handled correctly.
We currently get articles with something like "robots" or "robots, max-image-preview" in content of robots metatag. So it seems that default and/or selected settings will get lost and maybe also corrupt data is saved into metatag fields table for your entities.
Comment #18
gkannan25 CreditAttribution: gkannan25 as a volunteer and commentedGiven patch in #6 is not working. Please find the attached one.
Comment #19
gkannan25 CreditAttribution: gkannan25 as a volunteer and commentedComment #20
gkannan25 CreditAttribution: gkannan25 as a volunteer and commentedThis should work
Comment #21
gkannan25 CreditAttribution: gkannan25 as a volunteer and commentedThis should work
Comment #22
gkannan25 CreditAttribution: gkannan25 as a volunteer and commentedComment #23
gkannan25 CreditAttribution: gkannan25 as a volunteer and commentedComment #24
DamienMcKenna@gkannan25: fyi your file uploads and comments were not visible because your account was so new, but I've fixed that so now you can upload patches.
Let's see what testbot thinks of the new patch.
Comment #25
gkannan25 CreditAttribution: gkannan25 as a volunteer and commentedComment #27
gkannan25 CreditAttribution: gkannan25 as a volunteer and commentedTrying another patch
Comment #28
DamienMcKennaComment #30
zcht CreditAttribution: zcht commentedthe patch works so far, even if the patch tests fail. however, i always have this error when editing a node or calling the metatag admin interface. this is a bit inconvenient. occurs under drupal 9.2.0.
Notice: Undefined index: max-video-preview in Drupal\metatag\Plugin\metatag\Tag\Robots->form() (line 135 of /var/www/html/docroot/modules/contrib/metatag/src/Plugin/metatag/Tag/Robots.php)
all in all, it is a very important specification and the patch should come in core if possible.
Comment #31
Eugene Bocharov CreditAttribution: Eugene Bocharov as a volunteer commentedI modified #27 to be working with views metatags and compatible with current dev state.
Values' join logic moved from MetatagDefaultsForm::save() to the Robots::validateTag() to get it working on views options form submit as well.
Comment #32
zcht CreditAttribution: zcht commentedThanks for the update @Eugene, however this cannot be applied. Metatag version 8.x-1.16, Drupal 9.2.0.
Could not apply the patch! Skipped. The error was: Cannot apply patch https://www.drupal.org/files/issues/2021-07-06/added-new-robots-tags-3083743-31.patch
Comment #33
DamienMcKenna@zcht: FYI patches are preferably built against the current dev codebase, not against the last stable release, so I'm putting this back to "needs review".
Comment #34
Eugene Bocharov CreditAttribution: Eugene Bocharov as a volunteer commentedYes, the patching files in the dev already differ from 1.16. I've made variant for Metatag 8.x-1.16
Comment #35
zcht CreditAttribution: zcht commented@DamienMcKenna right, didn't take this into consideration. Let's hope for a release soon :)
@Eugene, thanks for the patch, works great. Karma++
Patch #34 for 8.x-1.16 RTTB++
Comment #36
zcht CreditAttribution: zcht commentedI have found a bug here, the behaviour actually only occurs with this patch. As soon as the patch is removed, everything is normal and functional again.
I use the following: Metatag version 8.x-1.16, Drupal 9.2.0, Group 1.4
I have configured the metatags for one content type and allow this content type to be used in a group. As long as migrated content is accessed via this group, all robot tags are correct, including those from this patch.
If I edit and save the node as an administrator, the output is still correct.
However, as soon as the node is saved by a user IN the group, i.e. just open and save, the output is completely wrong and strange. After the configuration export, I have the following in the
field.field.node.page.field_meta_tags.yml
Output in the frontend looks like this:
<meta name="robots" content="robots, robots-keyed">
An entry is made in the table
node__field_meta_tags
for this updated node and only if the node is updated via the group. Editing the node again as administrator does not help, all checkboxes are deselected.Comment #37
Eugene Bocharov CreditAttribution: Eugene Bocharov as a volunteer commentedThank you @zcht for pointing to this and provide the additional information. You are right, there is an issue with validateTag() function. It works well with global configured tags, but not with node's individual. I'll try to solve this. And obviously, it requires to add tests for that.
Comment #38
Eugene Bocharov CreditAttribution: Eugene Bocharov as a volunteer commentedThese are modified #31 and #34 for dev branch and 8.x-1.16 which should solve #36 issue. But they don't contains tests yet.
Comment #39
zcht CreditAttribution: zcht commentedThanks @Eugene, for the adaptation of the patch. Looks very good so far, all settings remain as they should.
Karma++ :)
Comment #40
Eugene Bocharov CreditAttribution: Eugene Bocharov as a volunteer commentedThis patch differs from #38 only in the tests. I suggest to add a call of method named
{$tagname}TestFormValues
(if presented) in theDrupal\Tests\metatag\Functional\MetatagTagsTestBase::testTagsInputOutput
to get the keys/values array for the edit form in the tests. This will allow use this method to test tags that use more than one form element for editing.Comment #41
zcht CreditAttribution: zcht commentedWith the current version 1.18 this patch can unfortunately no longer be applied. It would be really nice if we not only update this function but also actually bring it into the core of the module. These metatags are very relevant especially for content platforms.
Comment #42
DamienMcKenna@zcht: This would "bring it into the core of the module", it's additions to the "robots" tag that is part of the main Metatag module.
Comment #43
DamienMcKennaRerolled.
Comment #45
DamienMcKennaRerolled correctly X-)
Comment #46
zcht CreditAttribution: zcht commentedworks perfectly with 1.19, thanks for the reroll
Karma++ :)
Comment #47
timohuismanI've also tested #45 with 1.19, works like a charm.
Comment #48
DamienMcKennaReplace t() with $this->t().
Comment #49
akalam CreditAttribution: akalam at Dropsolid commentedLatest patch #48 doesn't apply against the 1.21 release, I'm adding a re-roll
Comment #50
osopolar#49 Does not seem to work. I set max-image-preview:large for content type article under /admin/config/search/metatag but its not set by default for already created articles (which do not have overridden the robots meta tag). Creating a new article it's not selected and not added to the robots after saving. Manually setting the value works, but in database it now appears as overridden, which shouldn't because it's the default setting.
Comment #51
osopolarI had problems with the robot meta tags, but they are likely not related with this issue, but somehow with language settings.
I have a config files sync/metatag.metatag_defaults.node__article.yml and sync/language/de/metatag.metatag_defaults.node__article.yml. While updating default settings for node article meta tags only sync/metatag.metatag_defaults.node__article.yml got updated
but not sync/language/de/metatag.metatag_defaults.node__article.yml (there I still had
robots: 'index, follow'
). Very likely that way the option for max-image-preview:large was not selected by default on /node/add/article.Then I removed all robot settings from node article metatag defaults and saved. Both config files sync/metatag.metatag_defaults.node__article.yml and sync/language/de/metatag.metatag_defaults.node__article.yml where updated. Now the default value was used from node metatag defaults, where I enabled max-image-preview:large which also worked for /node/add/article form.
Last test was setting robots metatag default for node back to "index, follow" and for node article to "index, follow, max-image-preview:large". Now again only sync/metatag.metatag_defaults.node__article.yml but not sync/language/de/metatag.metatag_defaults.node__article.yml was updated. After that the option for max-image-preview:large was selected by default on /node/add/article.
I guess it is not related with issue but who knows, maybe this helps somebody.
Comment #52
osopolarComment #53
IT-CruLatest patch #49 doesn't apply against the 1.22 release.
Comment #54
timohuismanComment #55
timohuismanRerolled #49 against 8.x-1.x, not sure if rerolling the tests went well.
Comment #59
bserem CreditAttribution: bserem at Annertech commentedMade a merge request with all the work done up to now. I attempted to fix tests and I also added the new `unavailable_after` robots tag.
Setting for review.
Thanks
Comment #60
bserem CreditAttribution: bserem at Annertech commentedSince tests are green I'm toggling visibility of previous patches.
Comment #61
bserem CreditAttribution: bserem at Annertech commentedComment #62
vuil#61 MR works for us. I set the issue status to RTBC. Thanks.
Comment #63
jansete CreditAttribution: jansete commentedWhen I applied this patch (MR), form doesn't store well robots checkbox options like "nofollow", if you check and save and then edit again the choices are disappeared, and the html it will be:
Comment #64
bserem CreditAttribution: bserem at Annertech commented@jansete can you check again please? Making sure you cleared caches etc? It works flawlessly on my test. Screenshot is after saving and revisiting the edit page:
Metatags options page is also working ok, and of course all the metatags appear as expected in the DOM.
Settings this back to needs review and will bump it to RTBC if I don't hear from you in the coming days.
Thanks
Comment #65
jansete CreditAttribution: jansete commentedI see, you are right.
The problem is only when using with the asynchronous patch from this issue https://www.drupal.org/project/metatag/issues/3057523
Sorry!
Comment #66
osopolarCopy of patch from https://git.drupalcode.org/project/metatag/-/merge_requests/73#note_140080 attached, to be used with composer, see "Patches from drupal.org merge request URLs are dangerous?".
Comment #67
Asmaa Supih CreditAttribution: Asmaa Supih commentedPatch provided in comment #66 works great for me.
thank you :)
Comment #68
zcht CreditAttribution: zcht commentedThis patch is only relevant at the moment, but has also gotten several literation. would be nice if the work can be incorporated into the core of the module.
Comment #69
DamienMcKennaWorking on making sure this is compatible with v2's tests.
Comment #70
DamienMcKennaUpdated patch with test coverage for the 2.0.x branch.
Comment #71
DamienMcKennaBecause the equivalent change went into 7.x-1.x already, I plan on adding this to 8.x-1.x but needed to get the tests working on the 2.0.x branch first.
Comment #75
DamienMcKennaCommitted. Thank you.