- Issue created by @tyler-durden
- π³π±Netherlands borisr
Can you show a bit more of your code? That would make it easier to debug.
Also, note there is a difference between a MetatagTag plugin and a SchemaPropertyType (you'll likely need both un your case). - πΊπΈUnited States tyler-durden
I'm not understanding the question, which may be part of my issue. The complete code of the file is above for the file:
schema_vehicle ->src ->Plugin ->metatag ->Tag ->SchemaProductMiles.phpThe code below works fine as a single field, so in trying to understand your message it looks like I need to somehow have a new SchemaPropertyType documented somewhere? I'm trying to find documentation for that now, if you have any insights on where to find this?
<?php namespace Drupal\schema_vehicle\Plugin\metatag\Tag; use Drupal\schema_metatag\Plugin\metatag\Tag\SchemaNameBase; /** * Provides a plugin for the 'schema_product_VIN' meta tag. * * - 'id' should be a globally unique id. * - 'name' should match the Schema.org element name. * - 'group' should match the id of the group that defines the Schema.org type. * * @MetatagTag( * id = "schema_product_VIN", * label = @Translation("VIN Number"), * description = @Translation("Vehicle ID number."), * name = "VehicleIdentificationNumber", * group = "schema_product", * weight = 10, * type = "string", * secure = FALSE, * multiple = FALSE, * property_type = "text", * tree_parent = {}, * tree_depth = -1, * ) */ class SchemaProductVIN extends SchemaNameBase { }
- πΊπΈUnited States tyler-durden
ok I found the 8.2 documentation and this subject is only touched on. Looks like that is stored in "/src/Plugin/schema_metatag/PropertyType".
Would this be the proper place to create a new file for that? I want this safe from updates and not being overwritten when updated.
- π³π±Netherlands borisr
Hi Tyler,
Thank you for providing some more context. I played around for a bit and it seems you will need both a SchemaPropertyType (something like your first provided example) and a MetatagTag plugin (something like your second example).
The MetatagTag plugin then will need to use the new SchemaPropertyType as 'property_type' property. The SchemaPropertyType plugin can be placed in the 'src/Plugin/schema_metatag/PropertyType' directory of your custom module.
Also see these plugins for reference:
- https://git.drupalcode.org/project/schema_metatag/-/blob/3.0.3/src/Plugi...
- https://git.drupalcode.org/project/schema_metatag/-/blob/3.0.3/schema_jo...I hope this will point you in the right direction but feel free to reach out if you need more help (or if my assumptions where incorrect).
- π³π±Netherlands borisr
Some example code might be easier to follow.
File: schema_vehicle/src/Plugin/metatag/Tag/SchemaProductMileage.php
Code:
<?php namespace Drupal\schema_vehicle\Plugin\metatag\Tag; use Drupal\schema_metatag\Plugin\metatag\Tag\SchemaNameBase; /** * Provides a plugin for the 'mileageFromOdometer' meta tag. * * - 'id' should be a globally unique id. * - 'name' should match the Schema.org element name. * - 'group' should match the id of the group that defines the Schema.org type. * * @MetatagTag( * id = "schema_product_mileage", * label = @Translation("Mileage From Odometer"), * name = "mileageFromOdometer", * group = "schema_product", * weight = 10, * type = "string", * secure = FALSE, * multiple = FALSE, * property_type = "product_vehicle_mileage", * tree_parent = { * "QuantitativeValue", * }, * tree_depth = -1, * ) */ class SchemaProductMileage extends SchemaNameBase { }
File: schema_vehicle/src/Plugin/schema_metatag/PropertyType/ProductVehicleMileage.php
Code:
<?php namespace Drupal\schema_vehicle\Plugin\schema_metatag\PropertyType; use Drupal\schema_metatag\Plugin\schema_metatag\PropertyTypeBase; /** * Provides a plugin for the 'mileageFromOdometer' Schema.org property. * * @SchemaPropertyType( * id = "product_vehicle_mileage", * label = @Translation("Mileage From Odometer"), * tree_parent = { * "QuantitativeValue", * }, * tree_depth = 0, * property_type = "QuantitativeValue", * sub_properties = { * "@type" = { * "id" = "type", * "label" = @Translation("@type"), * "description" = @Translation("The Schema.org type of this sub-object."), * }, * "value" = { * "id" = "number", * "label" = @Translation("value"), * "description" = @Translation("The numeric measurement value."), * }, * "unitCode" = { * "id" = "text", * "label" = @Translation("unitCode"), * "description" = @Translation("The unit of measurement, e.g. βSMIβ for statute miles."), * }, * }, * ) */ class ProductVehicleMileage extends PropertyTypeBase { }
Note: the code above is just an example, to further clarify previous comments. If you plan to contribute the 'schema_vehicle' module, the property type should probably be placed in the main 'schema_metatag' module.
- πΊπΈUnited States tyler-durden
Thank you for all the explanations, I think I understand it now however I need to put this project on the back burner for a few months as I found bigger issues that need to be addressed with my site first. I'm closing this ticket so it does not clog up the system, and will reopen if I move forward with this and share with the community for vehicles if so.
Automatically closed - issue fixed for 2 weeks with no activity.