Php.php in PHP 8
File
src/Plugin/views/argument_default/Php.php
View source
<?php
namespace Drupal\php\Plugin\views\argument_default;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase;
class Php extends ArgumentDefaultPluginBase {
protected function defineOptions() {
$options = parent::defineOptions();
$options['code'] = [
'default' => '',
];
return $options;
}
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".'),
];
$this
->checkAccess($form, 'code');
}
public function access() {
return \Drupal::currentUser()
->hasPermission('use PHP for settings');
}
public function getArgument() {
$view =& $this->view;
$argument =& $this->argument;
ob_start();
$result = eval($this->options['code']);
ob_end_clean();
return $result;
}
}
Classes
Name |
Description |
Php |
Default argument plugin to provide a PHP code block. |