- Issue created by @samundrasharma
- πΊπΈUnited States DamienMcKenna NH, USA
This is an issue for the Schema.org Metatag module, rather than Metatag itself.
- πΊπΈUnited States eojthebrave Minneapolis, MN
I was able to work around this by adding a new hasCourseInstance field to the Course type and then populating in an implementation of hook_metatags_alter(). My solution adds the 'hasCourseInstance' field, and via the module UI you can add a 'CourseInstance' to the field. But I haven't yet been able to figure out how to add CourseInstance specific fields to the type. Right now it just uses those defined by the Event type.
Do I need to create a new PropertyType of CourseInstance that duplicates the existing Event type and adds the custom fields? Or is there a better way to handle the CourseInstance specific fields like 'courseMode' and 'instructor'?
Here's the plugin code I used for the hasCourseInstance field:
namespace Drupal\dme\Plugin\metatag\Tag; use Drupal\schema_metatag\Plugin\metatag\Tag\SchemaNameBase; /** * Provides a plugin for the 'schema_course_hasCourseInstance' meta tag. * * Custom schema.org field for CourseInstance data. Can be removed when * https://www.drupal.org/project/schema_metatag/issues/3410151 is resolved. * * @MetatagTag( * id = "schema_course_hasCourseInstance", * label = @Translation("hasCourseInstance"), * description = @Translation("RECOMMENDED BY GOOGLE. The course instance(s)."), * name = "hasCourseInstance", * group = "schema_course", * weight = "0", * type = "string", * secure = FALSE, * multiple = TRUE, * property_type = "event", * tree_parent = { * "CourseInstance" * }, * tree_depth = 0, * ) */ class SchemaCourseHasCourseInstance extends SchemaNameBase { }
And the code I used to fill it in with the custom fields:
/** * Implements hook_metatags_alter(). */ function dme_metatags_alter(array &$metatags, array &$context) { $courseInstance = [ '@type' => 'CourseInstance', 'courseMode' => 'online', ]; $metatags['schema_course_hasCourseInstance'] = serialize($courseInstance); } }
In case this is helpful for anyone else.
- π«π·France Arono974
Hello,
Can you give me more details about the implementation of your solution?
I've created a "hasCourseInstance" field on the content type and activated the module with your code but I get the error
"Undefined array key "entity_type" in dme_metatags_alter() (line 7 of modules/dme/dme.module)."
I'm using schema metatag version 3.0.3Thanks in advance and have a nice day,
- π¬π§United Kingdom the_g_bomb
I think this should be closed in favour of using β¨ Missing schema tags for courses Active which will be a part of the module and won't require custom code.