Created
April 30, 2014 16:09
-
-
Save damiankloip/11431385 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/argument_default/QueryParameter.php b/core/modules/views/lib/Drupal/views/Plugin/views/argument_default/QueryParameter.php | |
new file mode 100644 | |
index 0000000..551d827 | |
--- /dev/null | |
+++ b/core/modules/views/lib/Drupal/views/Plugin/views/argument_default/QueryParameter.php | |
@@ -0,0 +1,82 @@ | |
+<?php | |
+ | |
+/** | |
+ * @file | |
+ * Contains \Drupal\views\Plugin\views\argument_default\QueryParameter. | |
+ */ | |
+ | |
+namespace Drupal\views\Plugin\views\argument_default; | |
+ | |
+use Symfony\Component\DependencyInjection\ContainerInterface; | |
+use Symfony\Component\HttpFoundation\RequestStack; | |
+ | |
+/** | |
+ * A query parameter argument default handler. | |
+ * | |
+ * @ingroup views_argument_default_plugins | |
+ * | |
+ * @ViewsArgumentDefault( | |
+ * id = "query_parameter", | |
+ * title = @Translation("Query parameter") | |
+ * ) | |
+ */ | |
+class QueryParameter extends ArgumentDefaultPluginBase { | |
+ | |
+ /** | |
+ * The request stack. | |
+ * | |
+ * @var \Symfony\Component\HttpFoundation\RequestStack | |
+ */ | |
+ protected $requestStack; | |
+ | |
+ /** | |
+ * Constructs a Plugin object. | |
+ */ | |
+ public function __construct(array $configuration, $plugin_id, $plugin_definition, RequestStack $request_stack) { | |
+ parent::__construct($configuration, $plugin_id, $plugin_definition); | |
+ | |
+ $this->requestStack = $request_stack; | |
+ } | |
+ | |
+ /** | |
+ * {@inheritdoc} | |
+ */ | |
+ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { | |
+ return new static($configuration, $plugin_id, $plugin_definition, $container->get('request_stack')); | |
+ } | |
+ | |
+ /** | |
+ * {@inheritdoc} | |
+ */ | |
+ protected function defineOptions() { | |
+ $options = parent::defineOptions(); | |
+ $options['query_param'] = array('default' => ''); | |
+ | |
+ return $options; | |
+ } | |
+ | |
+ /** | |
+ * {@inheritdoc} | |
+ */ | |
+ public function buildOptionsForm(&$form, &$form_state) { | |
+ parent::buildOptionsForm($form, $form_state); | |
+ $form['query_param'] = array( | |
+ '#type' => 'textfield', | |
+ '#title' => t('Query parameter'), | |
+ '#default_value' => $this->options['query_param'], | |
+ '#required' => TRUE, | |
+ ); | |
+ } | |
+ | |
+ /** | |
+ * {@inheritdoc} | |
+ */ | |
+ public function getArgument() { | |
+ $current_request = $this->requestStack->getCurrentRequest(); | |
+ | |
+ if ($current_request->query->has($this->options['query_param'])) { | |
+ return $current_request->query->get($this->options['query_param']); | |
+ } | |
+ } | |
+ | |
+} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment