You are here

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

Same name in this branch
  1. 8.2 src/SchemaMetatagClient.php \Drupal\schema_metatag\SchemaMetatagClient::getLocalFile()
  2. 8.2 tests/modules/schema_metatag_test/src/SchemaMetatagClient.php \Drupal\schema_metatag_test\SchemaMetatagClient::getLocalFile()

Retrieve and decode data from a local schema.jsonld file.

The data comes from https://schema.org/version/latest/schema.jsonld and is stored at /data. This file can be updated periodically.

Return value

array A decoded array of Schema.org data.

Overrides SchemaMetatagClientInterface::getLocalFile

See also

http://schema.org/docs/developers.html

https://github.com/schemaorg/schemaorg

https://schema.org/version/latest/schema.jsonld

https://schema.org/version/latest/schemaorg-all-http.jsonld

2 calls to SchemaMetatagClient::getLocalFile()
SchemaMetatagClient::objectInfo in src/SchemaMetatagClient.php
Retrieve an array of object information from the raw data.
SchemaMetatagClient::propertyInfo in src/SchemaMetatagClient.php
Retrieve object properties.
1 method overrides SchemaMetatagClient::getLocalFile()
SchemaMetatagClient::getLocalFile in tests/modules/schema_metatag_test/src/SchemaMetatagClient.php
Retrieve and decode data from a local schema.jsonld file.

File

src/SchemaMetatagClient.php, line 75

Class

SchemaMetatagClient
Class SchemaMetatagClient.

Namespace

Drupal\schema_metatag

Code

public function getLocalFile() {
  $path = DRUPAL_ROOT . '/' . $this->moduleHandler
    ->getModule('schema_metatag')
    ->getPath();
  $uri = $path . '/data/schemaorg-all-http.jsonld';
  try {
    if ($response = file_get_contents($uri)) {
      $data = json_decode($response, TRUE);
      if (is_array($data) && array_key_exists('@graph', $data)) {
        return $data['@graph'];
      }
    }
  } catch (RequestException $e) {
    watchdog_exception('schema_metatag', $e);
  }
  return FALSE;
}