Token for schema in Drupal 7
A small note on schema.org micro-markup in Drupal 7.
If we have a website with products and we need to set the availability of schema.org microdata for product types, we do the following.
We create a new field for availability statuses of the text(list) type and add, for example, two options - in stock and on order. In the field settings and types of valid values, set
in_stock|In stock
unde_the_order|Unde the stock
Now go to custom tokens and create a new token with php code
<?php
$output = '';
if (arg(0) !== 'node') return;
$node = node_load(arg(1));
$aviable = $node->field_aviable['und']['0']['value'];
if ($aviable == 'in_stock'){
$output = 'http://schema.org/InStock';
} else if ($aviable == 'unde_the_order'){
$output = 'https://schema.org/PreOrder';
}
return $output;
?>
where "field_aviable" is our node availability field. Thus, we are comparing the set value and applying the schema value to the token.
Now you can go to the content meta tags and open the Schema product tab and in the offers / availability section we insert our custom token
We save and now in the output schema parameters we will display the value that is being validated.
General list of available values for the accessibility field, schema markup
https://schema.org/Discontinued
https://schema.org/InStock
https://schema.org/InStoreOnly
https://schema.org/LimitedAvailability
https://schema.org/OnlineOnly
https://schema.org/OutOfStock
https://schema.org/PreOrder
https://schema.org/PreSale
https://schema.org/SoldOut