Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / metatag / metatag_hreflang / src / Plugin / Derivative / HreflangDeriver.php
1 <?php
2
3 namespace Drupal\metatag_hreflang\Plugin\Derivative;
4
5 use Drupal\Component\Plugin\Derivative\DeriverBase;
6 use Drupal\Core\Language\Language;
7 use Drupal\Core\Language\LanguageInterface;
8
9 /**
10  * Create a new hreflang tag plugin for each enabled language.
11  */
12 class HreflangDeriver extends DeriverBase {
13
14   /**
15    * {@inheritdoc}
16    */
17   public function getDerivativeDefinitions($base_plugin_definition) {
18     // Get a list of all defined languages.
19     $languages = \Drupal::languageManager()
20       ->getLanguages(LanguageInterface::STATE_ALL);
21
22     // Now we loop over them and declare the derivatives.
23     /** @var \Drupal\Core\Language\LanguageInterface $language */
24     foreach ($languages as $langcode => $language) {
25       // Ignore the global values.
26       if ($langcode == Language::LANGCODE_NOT_SPECIFIED) {
27         continue;
28       }
29       elseif ($langcode == Language::LANGCODE_NOT_APPLICABLE) {
30         continue;
31       }
32
33       // The base definition includes the annotations defined in the plugin,
34       // i.e. HreflangPerLanguage. Each one may be overridden.
35       $derivative = $base_plugin_definition;
36
37       // Here we fill in any missing keys on the layout annotation.
38       $derivative['weight']++;
39       $derivative['id'] = 'hreflang_' . $langcode;
40       // The 'name' value is used as the value of the 'hreflang' attribute on
41       // the HTML tag.
42       $derivative['name'] = $langcode;
43       $derivative['label'] = t("URL for a version of this page in %langcode", ['%langcode' => $language->getName()]);
44       $derivative['description'] = '';
45
46       // Reference derivatives based on their UUID instead of the record ID.
47       $this->derivatives[$derivative['id']] = $derivative;
48     }
49
50     return $this->derivatives;
51   }
52
53 }