Version 1
[yaffs-website] / web / modules / contrib / metatag / metatag_open_graph / metatag_open_graph.module
1 <?php
2
3 /**
4  * @file
5  * Contains metatag_open_graph.module.
6  */
7
8 use Drupal\Core\Entity\ContentEntityInterface;
9 use Drupal\Core\Entity\EntityInterface;
10 use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
11 use Drupal\Core\Form\FormStateInterface;
12 use Drupal\Core\Routing\RouteMatchInterface;
13 use Drupal\Core\Url;
14
15 /**
16  * Implements template_preprocess_html().
17  */
18 function metatag_open_graph_preprocess_html(&$variables) {
19   if (!metatag_is_current_route_supported()) {
20     return;
21   }
22
23   // Add XML namespaces if the RDF module is not enabled as it adds these two
24   // automatically.
25   if (!isset($variables['html_attributes'])) {
26     $variables['html_attributes'] = [];
27   }
28   $namespaces = [];
29   if (!\Drupal::moduleHandler()->moduleExists('rdf')) {
30     $namespaces = [
31       'xmlns:dc' => 'http://purl.org/dc/terms/',
32       'xmlns:og' => 'http://ogp.me/ns#',
33     ];
34   }
35
36   // Namespaces for OpenGraph.
37   $namespaces['xmlns:article'] = "http://ogp.me/ns/article#";
38   $namespaces['xmlns:book'] = "http://ogp.me/ns/book#";
39   $namespaces['xmlns:product'] = "http://ogp.me/ns/product#";
40   $namespaces['xmlns:profile'] = "http://ogp.me/ns/profile#";
41   $namespaces['xmlns:video'] = "http://ogp.me/ns/video#";
42
43   // Namespaces for Google+.
44   if (isset($variables['itemtype'])) {
45     $namespaces['itemscope'] = '';
46     $namespaces['itemtype'] = "http://schema.org/{$variables['itemtype']}";
47   }
48
49   // Append each namespace.
50   foreach ($namespaces as $namespace => $uri) {
51     $variables['html_attributes'][$namespace] = $uri;
52   }
53 }