Version 1
[yaffs-website] / web / core / modules / views / src / Plugin / views / argument / LanguageArgument.php
diff --git a/web/core/modules/views/src/Plugin/views/argument/LanguageArgument.php b/web/core/modules/views/src/Plugin/views/argument/LanguageArgument.php
new file mode 100644 (file)
index 0000000..2eb1870
--- /dev/null
@@ -0,0 +1,48 @@
+<?php
+
+namespace Drupal\views\Plugin\views\argument;
+
+/**
+ * Defines an argument handler to accept a language.
+ *
+ * @ingroup views_argument_handlers
+ *
+ * @ViewsArgument("language")
+ */
+class LanguageArgument extends ArgumentPluginBase {
+
+  /**
+   * Overrides \Drupal\views\Plugin\views\argument\ArgumentPluginBase::summaryName().
+   *
+   * Gets the user-friendly version of the language name.
+   */
+  public function summaryName($data) {
+    return $this->language($data->{$this->name_alias});
+  }
+
+  /**
+   * Overrides \Drupal\views\Plugin\views\argument\ArgumentPluginBase::title().
+   *
+   * Gets the user friendly version of the language name for display as a
+   * title placeholder.
+   */
+  public function title() {
+    return $this->language($this->argument);
+  }
+
+  /**
+   * Returns the language name for a given langcode.
+   *
+   * @param string $langcode
+   *   The language code.
+   *
+   * @return string
+   *   The translated name for the language, or "Unknown language" if the
+   *   language was not found.
+   */
+  public function language($langcode) {
+    $languages = $this->listLanguages();
+    return isset($languages[$langcode]) ? $languages[$langcode] : $this->t('Unknown language');
+  }
+
+}