Problem/Motivation

Current module shows the office hours nicely to visitors, but not to search engines. Integration with Metatag module with the json-ld https://schema.org/OpeningHoursSpecification tags should be possible.

Steps to reproduce

Proposed resolution

Remaining tasks

actually ycoding it

User interface changes

Extra checkbox on the display plugin for metatag integration.

API changes

Data model changes

data already available

Comments

splash112 created an issue. See original summary.

johnv’s picture

Title: Create integration with Metatag module » Add schema.org/microdata via Metatag module
Version: 8.x-1.3 » 8.x-1.x-dev
Issue tags: -metatag +Schema.org Metatag
johnv’s picture

Title: Add schema.org/microdata via Metatag module » Add schema.org/OpeningHoursSpecification microdata via Metatag module
johnv’s picture

Component: Code » Code - formatter
splash112’s picture

Issue tags: +token

Checked a bit and it seems that everything is ready, except nicely formatted (day and time) tokens from Office Hours module.
Looking into that.

johnv’s picture

Please also check the reference issue #2109699: Add schema.org/openingHours(Specification) microdata for office_hours [META] (+D7 patch).
Reason for not having implemented this, are the several doubts I have and the several formatting systems that exist out there.

splash112’s picture

StatusFileSize
new0 bytes

First stab. Adding a office_hours.token.inc file which displays the tokens as full weekdays and html time.
Displays and confirms with Google Schema.org metatags (as long you one uses a short and simple office_hour field.

splash112’s picture

StatusFileSize
new1.38 KB

now with patch that is not empty...

johnv’s picture

@splash112,
are you working in the correct ticket? The Token issue is #1848750: Add Token support.
This issue is about schema.org metatags.

johnv’s picture

@splash112,
Oh, I see you are referring to that in your comment. How are both connected? There is no schema.org support yet.

splash112’s picture

Hi @johnv,

Thanks for the quick response.
There are multiple ways to implement schema.org tags. Looks like you have been working mostly inline.
One of the other ways is via JSON-LD script (Google preferred) in the metatags. The patch supplies the tokens for Metatag module to output the correct tags.

It works, but only in the most straightforward use case (the only one accepted by Google I think).

splash112’s picture

<script type="application/ld+json">{
    "@context": "https://schema.org",
    "@graph": [
        {
            "@type": "BarOrPub",
            "@id": "dsdfds",
            "description": "dfsdsdf",
            "openingHoursSpecification": [
                {
                    "@type": "OpeningHoursSpecification",
                    "dayOfWeek": "Sunday",
                    "opens": "17:00:00",
                    "closes": "19:30:00"
                },
                {
                    "@type": "OpeningHoursSpecification",
                    "dayOfWeek": "Monday",
                    "opens": "17:05:00",
                    "closes": "19:35:00"
                },
            ]
        }
    ]
}</script>

Outputs something like above. So yes, a nice cross between Token, Schema.org and Metatag.

johnv’s picture

The token file works fine to generate tokens. (I tested with Automatic Entity Label).
I will commit it in the other ticket.

There are several parts in the code to prepare for Schema.org, in an attempt to add out-of-the box support, without use of other modules, since this fits 1-to-1 to a schema.org property:

- In the formatter settings:
SCHEMA.ORG OPENINGHOURS SUPPORT
[X] Enable Schema.org openingHours support (Enable meta tags with property for Schema.org openingHours.)

- function template_preprocess_office_hours() contains a schema part.
- file OfficeHoursFormatterSchema.php contains a formatter which is used if above checkmark is set.

Do you think this is not needed?

johnv’s picture

johnv’s picture

Title: Add schema.org/OpeningHoursSpecification microdata via Metatag module » Add schema.org/OpeningHoursSpecification microdata via Metatag+Token module
Related issues: +#1848750: Add Token support

Your patch is committed here: #1848750-5: Add Token support

splash112’s picture

Oh, maybe a bit premature to commit... Not sure what will happen with multiple value fields, etc.
The date formats are now hardcoded. Might be better to either make them configurable or supply multiple.

splash112’s picture

Damn, exported the config from my local (and working like expected) site to production and the output went bad. Somehow the day moved down a day. (times for Friday are show as Thursday.

Will look into it.

splash112’s picture

StatusFileSize
new552 bytes

This patch should fix it

  • johnv committed 137b43a on 8.x-1.x authored by splash112
    Issue #3208978 by splash112: Add schema.org/OpeningHoursSpecification...
johnv’s picture

StatusFileSize
new907 bytes

Your fix was commtted in a slightly different way. See attached patch.

splash112’s picture

Thanks!

gumanist’s picture

StatusFileSize
new1.9 KB

I have updated the patch to support multivalues and a single item with 'pivot' option in metagag.
Usage:
1. [node:field:property] - all properties with ',' delimiter
2. [node:field:{delta}:property

Examples:
[node:field:day] -> Monday,Wednesday
[node:field:0:day] -> Monday

gumanist’s picture

Status: Active » Needs review

Changed status to Needs review

andypost’s picture

+++ b/office_hours.tokens.inc
@@ -21,26 +21,40 @@ function office_hours_tokens($type, $tokens, array $data, array $options, Bubble
+      switch ($parts[0]) {

should be switch ($property) instead

gumanist’s picture

StatusFileSize
new1.86 KB

Updated $property and removed unnecessary line

andypost’s picture

Status: Needs review » Reviewed & tested by the community

It could use tests but it will be tricky to setup

dmitriy.trt’s picture

Latest patch (#26) didn't apply for me. Attaching an updated one and an interdiff.

Changes on top of #26:

  • Add day-untranslated token, so that days of week never get translated in the metadata. I'm not 100% sure if it violates the standard, but Google reads Monday as http://schema.org/Monday and Понедельник (which is "Monday" in Russian) as-is, so it may be a good idea to always use untranslated day names.
  • Delete the type hint, as the code checks for the item list type.
dmitriy.trt’s picture

Status: Reviewed & tested by the community » Needs review
dmitriy.trt’s picture

Attaching a version that applies to 8.x-1.5 stable version, just in case it's useful for somebody. Otherwise, please ignore it.

dmitriy.trt’s picture

One more update on top of #28 to keep the $day_names variable name introduced by this commit.

  • johnv committed b26a68b on 8.x-1.x
    Issue #3208978 by Dmitriy.trt, splash112, gumanist, johnv: Add schema....
johnv’s picture

Version: 8.x-1.x-dev » 8.x-1.5

Thanks all, committed.

However, It is nice to have (general) token support in this module, but can someone please explain to me how this helps "Add schema.org/OpeningHoursSpecification microdata"?

splash112’s picture

StatusFileSize
new23.47 KB

Now you can easily add the opening hours to your metatags as structured data. See image attached.

explanatory image

johnv’s picture

Thanks,
It seems the above is the result. But how to add this? Is it accessible for a 'normal' sitebuilder using the Drupal UI?

See also my doubts/lack of knowledge on the several formats in #2109699: Add schema.org/openingHours(Specification) microdata for office_hours [META] (+D7 patch).
Ideally, it should work out of the box with a FieldFormatter.

gumanist’s picture

StatusFileSize
new46.21 KB

See an example of metatag configuration:

Second 'dayOfWeek' is typo in metatag module. Should read as 'closes'

johnv’s picture

Status: Needs review » Fixed

Thanks, but still cannot find it.

I added a Metatag reference on the project page.

The openingHoursSpecification functionality can benefit from #1998266: Add "Exception day" feature
The openingHours metadata was WIP and is now implemented here: #2720335: Add schema.org/openingHours Microdata, RDFa (D8)

splash112’s picture

Thanks! It's part of the organization schema metatags.

johnv’s picture

Thanks, I missed that. Added to the ticket and the project page.

Status: Fixed » Closed (fixed)

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