File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed
Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ public function __construct(StructuredDataParser $parser)
1717 $ this ->parser = $ parser ;
1818 }
1919
20- public function getJsonLdScripts ($ item ): array
20+ public function getJsonLdScripts ($ item, $ json = false ): array
2121 {
2222 $ templates = $ this ->getTemplates ($ item );
2323
@@ -43,7 +43,7 @@ public function getJsonLdScripts($item): array
4343 try {
4444 $ parsedSchemas = $ this ->parser ->parse ($ schemas , $ item );
4545 foreach ($ parsedSchemas as $ parsedSchema ) {
46- $ scripts [] = $ this ->formatJsonLd ($ parsedSchema );
46+ $ scripts [] = $ this ->formatJsonLd ($ parsedSchema, $ json );
4747 }
4848 } catch (\Exception $ e ) {
4949 continue ;
@@ -53,13 +53,17 @@ public function getJsonLdScripts($item): array
5353 return $ scripts ;
5454 }
5555
56- public function formatJsonLd (array $ schema ): string
56+ public function formatJsonLd (array $ schema, $ json = false ): string
5757 {
5858 $ transformedSchema = $ this ->transformSchema ($ schema );
59+ $ schema = json_encode ($ transformedSchema , JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
60+ if ($ json ) {
61+ return $ schema ;
62+ }
5963
6064 return sprintf (
6165 '<script type="application/ld+json">%s</script> ' ,
62- json_encode ( $ transformedSchema , JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE )
66+ $ schema
6367 );
6468 }
6569
You can’t perform that action at this time.
0 commit comments