Version 1
[yaffs-website] / web / modules / contrib / metatag / metatag_open_graph / metatag_open_graph.module
diff --git a/web/modules/contrib/metatag/metatag_open_graph/metatag_open_graph.module b/web/modules/contrib/metatag/metatag_open_graph/metatag_open_graph.module
new file mode 100644 (file)
index 0000000..fd7338a
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+
+/**
+ * @file
+ * Contains metatag_open_graph.module.
+ */
+
+use Drupal\Core\Entity\ContentEntityInterface;
+use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
+use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Routing\RouteMatchInterface;
+use Drupal\Core\Url;
+
+/**
+ * Implements template_preprocess_html().
+ */
+function metatag_open_graph_preprocess_html(&$variables) {
+  if (!metatag_is_current_route_supported()) {
+    return;
+  }
+
+  // Add XML namespaces if the RDF module is not enabled as it adds these two
+  // automatically.
+  if (!isset($variables['html_attributes'])) {
+    $variables['html_attributes'] = [];
+  }
+  $namespaces = [];
+  if (!\Drupal::moduleHandler()->moduleExists('rdf')) {
+    $namespaces = [
+      'xmlns:dc' => 'http://purl.org/dc/terms/',
+      'xmlns:og' => 'http://ogp.me/ns#',
+    ];
+  }
+
+  // Namespaces for OpenGraph.
+  $namespaces['xmlns:article'] = "http://ogp.me/ns/article#";
+  $namespaces['xmlns:book'] = "http://ogp.me/ns/book#";
+  $namespaces['xmlns:product'] = "http://ogp.me/ns/product#";
+  $namespaces['xmlns:profile'] = "http://ogp.me/ns/profile#";
+  $namespaces['xmlns:video'] = "http://ogp.me/ns/video#";
+
+  // Namespaces for Google+.
+  if (isset($variables['itemtype'])) {
+    $namespaces['itemscope'] = '';
+    $namespaces['itemtype'] = "http://schema.org/{$variables['itemtype']}";
+  }
+
+  // Append each namespace.
+  foreach ($namespaces as $namespace => $uri) {
+    $variables['html_attributes'][$namespace] = $uri;
+  }
+}