X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fphp%2Fsrc%2FPlugin%2Fviews%2Fargument_default%2FPhp.php;fp=web%2Fmodules%2Fcontrib%2Fphp%2Fsrc%2FPlugin%2Fviews%2Fargument_default%2FPhp.php;h=362272135aed47e4b7d1ece8d29bc740d933f3a7;hp=0000000000000000000000000000000000000000;hb=8acec36f19c470dfcda1ae2336826a782f41874c;hpb=e0411c4e83ba0d079034db83c3f7f55be24a0e35 diff --git a/web/modules/contrib/php/src/Plugin/views/argument_default/Php.php b/web/modules/contrib/php/src/Plugin/views/argument_default/Php.php new file mode 100644 index 000000000..362272135 --- /dev/null +++ b/web/modules/contrib/php/src/Plugin/views/argument_default/Php.php @@ -0,0 +1,72 @@ + '']; + + return $options; + } + + /** + * {@inheritdoc} + */ + public function buildOptionsForm(&$form, FormStateInterface $form_state) { + parent::buildOptionsForm($form, $form_state); + $form['code'] = [ + '#type' => 'textarea', + '#title' => $this->t('PHP contextual filter code'), + '#default_value' => $this->options['code'], + '#description' => $this->t('Enter PHP code that returns a value to use for this filter. Do not use <?php ?>. You must return only a single value for just this filter. Some variables are available: the view object will be "$view". The argument handler will be "$argument", for example you may change the title used for substitutions for this argument by setting "argument->validated_title".'), + ]; + + // Only do this if using one simple standard form gadget. + $this->checkAccess($form, 'code'); + } + + /** + * Only let users with PHP block visibility permissions set/modify this + * default plugin. + */ + public function access() { + return \Drupal::currentUser()->hasPermission('use PHP for settings'); + } + + /** + * {@inheritdoc} + */ + public function getArgument() { + // Set up variables to make it easier to reference during the argument. + $view = &$this->view; + $argument = &$this->argument; + ob_start(); + $result = eval($this->options['code']); + ob_end_clean(); + return $result; + } + +}