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

CommentFileSizeAuthor
#70 metatag-n3083743-70.patch6.76 KBDamienMcKenna
#66 metatag-3083743-66.patch8.53 KBosopolar
#64 revisited_metatags.png99.37 KBbserem
#55 reroll_diff_49-55.txt3.79 KBtimohuisman
#55 metatag-3083743-55.patch7.83 KBtimohuisman
#51 diff-48-49.diff3.46 KBosopolar
#49 metatag-3083743-49.patch7.78 KBakalam
#48 metatag-n3083743-48.patch7.8 KBDamienMcKenna
#48 metatag-n3083743-48.interdiff.txt2.16 KBDamienMcKenna
#45 metatag-n3083743-45.patch7.73 KBDamienMcKenna
#43 metatag-n3083743-43.patch7.58 KBDamienMcKenna
#40 added-new-robots-tags-3083743-40.patch7.66 KBEugene Bocharov
#40 interdiff-3083743-38-40.txt3.2 KBEugene Bocharov
#38 added-new-robots-tags-8.x-1.16-3083743-38.patch4.44 KBEugene Bocharov
#38 interdiff-3083743-31-38.txt1.19 KBEugene Bocharov
#38 added-new-robots-tags-3083743-38.patch4.46 KBEugene Bocharov
#36 Xnip2021-07-16_02-34-37.png19.87 KBzcht
#34 added-new-robots-tags-8.x-1.16-3083743-34.patch4.32 KBEugene Bocharov
#31 added-new-robots-tags-3083743-31.patch4.34 KBEugene Bocharov
#27 added-new-robots-tags-3083743-27.patch4.33 KBgkannan25
#23 added-new-robots-tags-3083743-18.patch3.82 KBgkannan25
#19 added-new-robots-tags.patch3.82 KBgkannan25
#6 added-new-robots-tags-3083743-6.patch4.36 KBAnonymous (not verified)

Issue fork metatag-3083743

Command icon 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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

druhu created an issue. See original summary.

szeidler’s picture

This 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.

  1. max-snippet and max-video-preview requires a number field
  2. max-image-preview requires a select field
druhu’s picture

I really need these new tags, google sent me a reminder today:

Your property is currently designated as a European press publication, as defined by EU Directive 2019/790 on copyright and related rights in the digital single market.

Google recently announced new webmaster settings that allow you to choose how much preview content you wish to allow in search results.

This week, Google will gradually start applying these new settings, so if you've implemented them already, expect to see your instructions taking effect over the coming days. If you have not implemented the markup but intend to, please note that it may take several days for search results to update when markup is added or changed. You can read more about the new options here.

druhu’s picture

Priority: Normal » Major
DamienMcKenna’s picture

Anonymous’s picture

Status: Active » Needs review
FileSize
4.36 KB
DamienMcKenna’s picture

Status: Needs review » Needs work
DamienMcKenna’s picture

Title: Add new robots tags » Add Google's new robots tags (D8)
maticb’s picture

I 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

   // Confirm that no changes have been made yet.
    $this->assertNoText('Overridden');

Just before that we go to a view

 // Load the Arcive view.
    $this->drupalGet('/admin/structure/views/view/archive');
    $this->assertResponse(200);

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"

maticb’s picture

Status: Needs work » Needs review
DamienMcKenna’s picture

Status: Needs review » Needs work

The test failures need to be resolved.

maticb’s picture

@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:

   $this->assertNoText('Overridden');

because with a clean Drupal 8 install, this text already exists.

erwangel’s picture

Will 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)

DamienMcKenna’s picture

I added a new issue for a backport: #3106692: Add Google's new robots tags (D7)

Anonymous’s picture

Thoses line could generate error

if (in_array($value_other[0], array_keys($default_value_other))) {
  $default_value_other[$value_other[0]] = $value_other[1];
}

You need do check if $value_other[1] exist
why use in_array instead of array_key_exists ?

if (isset($value_other[1]) && array_key_exists($value_other[0], $default_value_other)) {
  $default_value_other[$value_other[0]] = $value_other[1];
}
IT-Cru’s picture

@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.

rokzabukovec made their first commit to this issue’s fork.

gkannan25’s picture

Given patch in #6 is not working. Please find the attached one.

gkannan25’s picture

Version: 8.x-1.x-dev » 8.x-1.16
Assigned: Unassigned » gkannan25
FileSize
3.82 KB
gkannan25’s picture

This should work

gkannan25’s picture

This should work

gkannan25’s picture

gkannan25’s picture

FileSize
3.82 KB
DamienMcKenna’s picture

Version: 8.x-1.16 » 8.x-1.x-dev
Assigned: gkannan25 » Unassigned
Status: Needs work » Needs review

@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.

gkannan25’s picture

Status: Needs review » Needs work

The last submitted patch, 23: added-new-robots-tags-3083743-18.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

gkannan25’s picture

DamienMcKenna’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 27: added-new-robots-tags-3083743-27.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

zcht’s picture

the 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.

Eugene Bocharov’s picture

Status: Needs work » Needs review
FileSize
4.34 KB

I 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.

zcht’s picture

Status: Needs review » Needs work

Thanks 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

DamienMcKenna’s picture

Priority: Major » Normal
Status: Needs work » Needs review

@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".

Eugene Bocharov’s picture

Yes, the patching files in the dev already differ from 1.16. I've made variant for Metatag 8.x-1.16

zcht’s picture

@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++

zcht’s picture

FileSize
19.87 KB

I 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

default_value:
  -
    value: 'a:1:{s:6:"robots";s:20:"robots, robots-keyed";}'

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.

Eugene Bocharov’s picture

Status: Needs review » Needs work

Thank 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.

Eugene Bocharov’s picture

These 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.

zcht’s picture

Thanks @Eugene, for the adaptation of the patch. Looks very good so far, all settings remain as they should.

Karma++ :)

Eugene Bocharov’s picture

This patch differs from #38 only in the tests. I suggest to add a call of method named {$tagname}TestFormValues (if presented) in the Drupal\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.

zcht’s picture

Status: Needs review » Needs work

With 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.

DamienMcKenna’s picture

@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.

DamienMcKenna’s picture

Status: Needs work » Needs review
FileSize
7.58 KB

Rerolled.

Status: Needs review » Needs work

The last submitted patch, 43: metatag-n3083743-43.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

DamienMcKenna’s picture

Status: Needs work » Needs review
FileSize
7.73 KB

Rerolled correctly X-)

zcht’s picture

works perfectly with 1.19, thanks for the reroll

Karma++ :)

timohuisman’s picture

Status: Needs review » Reviewed & tested by the community

I've also tested #45 with 1.19, works like a charm.

DamienMcKenna’s picture

Replace t() with $this->t().

akalam’s picture

Latest patch #48 doesn't apply against the 1.21 release, I'm adding a re-roll

osopolar’s picture

Status: Reviewed & tested by the community » Needs work

#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.

osopolar’s picture

FileSize
3.46 KB

I 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

-  robots: 'index, follow'
+  robots: 'index, follow, max-image-preview:large'

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.

osopolar’s picture

Status: Needs work » Needs review
IT-Cru’s picture

Status: Needs review » Needs work

Latest patch #49 doesn't apply against the 1.22 release.

timohuisman’s picture

Issue tags: +Needs reroll
timohuisman’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
7.83 KB
3.79 KB

Rerolled #49 against 8.x-1.x, not sure if rerolling the tests went well.

Status: Needs review » Needs work

The last submitted patch, 55: metatag-3083743-55.patch, failed testing. View results

bserem made their first commit to this issue’s fork.

bserem’s picture

Status: Needs work » Needs review

Made 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

bserem’s picture

Since tests are green I'm toggling visibility of previous patches.

vuil’s picture

Status: Needs review » Reviewed & tested by the community

#61 MR works for us. I set the issue status to RTBC. Thanks.

jansete’s picture

Status: Reviewed & tested by the community » Needs work

When 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:

bserem’s picture

Status: Needs work » Needs review
FileSize
99.37 KB

@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:

new metatags options

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

jansete’s picture

Status: Needs review » Reviewed & tested by the community

I 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!

osopolar’s picture

Asmaa Supih’s picture

Patch provided in comment #66 works great for me.
thank you :)

zcht’s picture

This 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.

DamienMcKenna’s picture

Version: 8.x-1.x-dev » 2.0.x-dev
Assigned: Unassigned » DamienMcKenna
Status: Reviewed & tested by the community » Needs work

Working on making sure this is compatible with v2's tests.

DamienMcKenna’s picture

Version: 2.0.x-dev » 8.x-1.x-dev
Assigned: DamienMcKenna » Unassigned
Status: Needs work » Needs review
FileSize
6.76 KB

Updated patch with test coverage for the 2.0.x branch.

DamienMcKenna’s picture

Because 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.

  • DamienMcKenna committed 7ed42d2d on 8.x-1.x
    Issue #3083743 by Eugene Bocharov, DamienMcKenna, bserem, gkannan25,...

  • DamienMcKenna committed 50cf6d01 on 2.0.x
    Issue #3083743 by DamienMcKenna: Follow-up to fix tests for new Robots...

  • DamienMcKenna committed 22d949b4 on 2.0.x
    Issue #3083743 by Eugene Bocharov, DamienMcKenna, bserem, gkannan25,...
DamienMcKenna’s picture

Status: Needs review » Fixed

Committed. Thank you.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.