public function SchemaMetatagClient::objectInfo in Schema.org Metatag 8.2
Retrieve an array of object information from the raw data.
The raw data is a series of objects with information about each of them. Each class contains a list of its parent classes, but the data is not represented hierarchically.
Parameters
bool $clear: Whether to clear the cached array created by getObjects().
Return value
array An array of objects:
- object name:
- object: The name of the object class.
- description: The description of the object.
- parents: An array of objects this object is a subclass of.
Overrides SchemaMetatagClientInterface::objectInfo
1 call to SchemaMetatagClient::objectInfo()
- SchemaMetatagClient::getObjectTree in src/
SchemaMetatagClient.php - Reorganize the classes into a hierarchical tree.
File
- src/
SchemaMetatagClient.php, line 96
Class
- SchemaMetatagClient
- Class SchemaMetatagClient.
Namespace
Drupal\schema_metatagCode
public function objectInfo($clear = FALSE) {
$cid = "schema_metatag.objects";
if (!$clear && ($cache = $this->cacheBackend
->get($cid))) {
$items = $cache->data;
}
else {
$data = $this
->getLocalFile();
$items = [];
foreach ($data as $item) {
if ($this
->isIncludedClass($item)) {
$subobject_of = [];
$object = is_array($item['rdfs:label']) ? $item['rdfs:label']['@value'] : $item['rdfs:label'];
$description = $item['rdfs:comment'];
if (array_key_exists('rdfs:subClassOf', $item)) {
foreach ($item['rdfs:subClassOf'] as $value) {
if (!is_array($value)) {
$value = [
$value,
];
}
foreach ($value as $value_item) {
$subobject_of[] = str_replace(static::$prefix, '', $value_item);
}
}
}
$description = strip_tags($description);
$items[$object] = [
'object' => $object,
'description' => $description,
'parents' => $subobject_of,
];
}
}
// Cache permanently.
$this->cacheBackend
->set($cid, $items, CacheBackendInterface::CACHE_PERMANENT);
}
return $items;
}