public static function SchemaItemListElementBreadcrumbBase::getItems in Schema.org Metatag 7
Process the input value into an array of items.
Each type of ItemList can extend this to process the input value into a list of items. The default behavior will be a simple array from a comma-separated list.
Overrides SchemaItemListElementBase::getItems
File
- src/
SchemaItemListElementBreadcrumbBase.php, line 55
Class
- SchemaItemListElementBreadcrumbBase
- All Schema.org Breadcrumb tags should extend this class.
Code
public static function getItems($input_value) {
$values = [];
if (!empty($input_value)) {
$breadcrumbs = drupal_get_breadcrumb();
// Methods on DrupalDefaultMetaTag can't be called statically, and we
// can't use $this from a static method, so create an empty instance.
$data = $info = [];
$processor = new DrupalDefaultMetaTag($data, $info);
$key = 1;
foreach ($breadcrumbs as $item) {
$text = strip_tags($item);
$url = '';
$matches = [];
if (preg_match('/href="([^"]*)"/', $item, $matches)) {
if (!empty($matches[1])) {
$url = $matches[1];
$url = $processor
->convertUrlToAbsolute($url);
}
}
$values[$key] = [
'@id' => $url,
'name' => $text,
'item' => $url,
];
$key++;
}
}
return $values;
}