You are here

public function SchemaMetatagClient::propertyInfo in Schema.org Metatag 8.2

Retrieve object properties.

This data constains detailed property information for each object.

Parameters

bool $clear: Whether to clear the cached array created by getProperties().

Return value

array An array of objects and their properties:

  • Object class name:

    • property name:

      • property: The name of the property.
      • description: The description of the property.
      • expected_types: An array of the expected types of the property.

Overrides SchemaMetatagClientInterface::propertyInfo

File

src/SchemaMetatagClient.php, line 140

Class

SchemaMetatagClient
Class SchemaMetatagClient.

Namespace

Drupal\schema_metatag

Code

public function propertyInfo($clear = FALSE) {
  $cid = "schema_metatag.properties";
  if (!$clear && ($cache = $this->cacheBackend
    ->get($cid))) {
    $items = $cache->data;
  }
  else {
    $data = $this
      ->getLocalFile();
    $items = [];
    foreach ($data as $item) {
      if ($this
        ->isIncludedProperty($item)) {
        $expected_types = $belongs_to = [];
        $property = $item['rdfs:label'];
        $description = $item['rdfs:comment'];
        foreach ($item[static::$prefix . 'rangeIncludes'] as $value) {
          foreach ((array) $value as $value_item) {
            $expected_types[] = str_replace(static::$prefix, '', $value_item);
          }
        }
        if (!empty($expected_types)) {
          foreach ($item[static::$prefix . 'domainIncludes'] as $value) {
            foreach ((array) $value as $value_item) {
              $class = str_replace(static::$prefix, '', $value_item);
              $belongs_to[] = $class;
            }
          }
          foreach ($belongs_to as $parent) {
            $items[$parent][$property] = [
              'property' => $property,
              'description' => strip_tags($description),
              'expected_types' => array_unique($expected_types),
            ];
          }
        }
      }

      // Cache permanently.
      $this->cacheBackend
        ->set($cid, $items, CacheBackendInterface::CACHE_PERMANENT);
    }
  }
  return $items;
}