5 * Contains metatag_open_graph.module.
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;
16 * Implements template_preprocess_html().
18 function metatag_open_graph_preprocess_html(&$variables) {
19 if (!metatag_is_current_route_supported()) {
23 // Add XML namespaces if the RDF module is not enabled as it adds these two
25 if (!isset($variables['html_attributes'])) {
26 $variables['html_attributes'] = [];
29 if (!\Drupal::moduleHandler()->moduleExists('rdf')) {
31 'xmlns:dc' => 'http://purl.org/dc/terms/',
32 'xmlns:og' => 'http://ogp.me/ns#',
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#";
43 // Namespaces for Google+.
44 if (isset($variables['itemtype'])) {
45 $namespaces['itemscope'] = '';
46 $namespaces['itemtype'] = "http://schema.org/{$variables['itemtype']}";
49 // Append each namespace.
50 foreach ($namespaces as $namespace => $uri) {
51 $variables['html_attributes'][$namespace] = $uri;