public static function SchemaMetatagManager::encodeJsonld in Schema.org Metatag 8.2
Same name and namespace in other branches
- 8 src/SchemaMetatagManager.php \Drupal\schema_metatag\SchemaMetatagManager::encodeJsonld()
Convert a metatags-style data array to JSON LD.
Parameters
array $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.
- SchemaMetatagManagerTest::testEncodeJsonld in tests/
src/ Unit/ SchemaMetatagManagerTest.php - @covers ::encodeJsonld
File
- src/
SchemaMetatagManager.php, line 50
Class
- SchemaMetatagManager
- The SchemaMetatag Manager.
Namespace
Drupal\schema_metatagCode
public static function encodeJsonld(array $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 '';
}
}