You are here

public static function SchemaMetatagManager::encodeJsonld in Schema.org Metatag 7

Convert a metatags-style data array to JSON LD.

Parameters

$items: Array of Schema metatag tags, ready to be turned into JSON LD.

Return value

string Json-encoded representation of the structured data.

Overrides SchemaMetatagManagerInterface::encodeJsonld

2 calls to SchemaMetatagManager::encodeJsonld()
SchemaMetatagManager::getRenderedJsonld in src/SchemaMetatagManager.php
Render JSON LD for a specific entity.
schema_metatag_html_head_alter in ./schema_metatag.module
Implements hook_html_head_alter().

File

src/SchemaMetatagManager.php, line 72
A generic substitution for Drupal 8 Random utility.

Class

SchemaMetatagManager
Class SchemaMetatagManager.

Code

public static function encodeJsonld($items) {

  // If some group has been found, render the JSON LD,
  // otherwise return nothing.
  if (!empty($items)) {
    return json_encode($items, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_UNESCAPED_UNICODE);
  }
  else {
    return '';
  }
}