Version 1
[yaffs-website] / web / modules / contrib / metatag / metatag_hreflang / src / Plugin / metatag / Tag / HreflangBase.php
diff --git a/web/modules/contrib/metatag/metatag_hreflang/src/Plugin/metatag/Tag/HreflangBase.php b/web/modules/contrib/metatag/metatag_hreflang/src/Plugin/metatag/Tag/HreflangBase.php
new file mode 100644 (file)
index 0000000..c19eaa5
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+
+namespace Drupal\metatag_hreflang\Plugin\metatag\Tag;
+
+use \Drupal\metatag\Plugin\metatag\Tag\LinkRelBase;
+
+/**
+ * This base plugin allows "link hreflang" tags to be further customized.
+ */
+abstract class HreflangBase extends LinkRelBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function output() {
+    $element = parent::output();
+
+    if ($element) {
+      // Rewrite the attributes so the hreflang value is before the href value.
+      $element['#attributes'] = [
+        'rel' => 'hreflang',
+        'hreflang' => $this->name(),
+        'href' => $element['#attributes']['href'],
+      ];
+    }
+
+    return $element;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function name() {
+    return str_replace('hreflang_', '', parent::name());
+  }
+
+}