CurrentContext.php in Config Pages 8.2
File
src/Plugin/views/argument_default/CurrentContext.php
View source
<?php
namespace Drupal\config_pages\Plugin\views\argument_default;
use Drupal\config_pages\Entity\ConfigPagesType;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase;
class CurrentContext extends ArgumentDefaultPluginBase implements CacheableDependencyInterface {
protected function defineOptions() {
$options = parent::defineOptions();
$options['config_page_type'] = [
'default' => '',
];
return $options;
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$config_pages_types = ConfigPagesType::loadMultiple();
$options = [];
foreach ($config_pages_types as $cp_type) {
$id = $cp_type
->id();
$label = $cp_type
->label();
$options[$id] = $label;
}
$form['config_page_type'] = [
'#type' => 'select',
'#title' => $this
->t('Select ConfigPage type to get Context for.'),
'#options' => $options,
'#default_value' => isset($this->options['config_page_type']) ? $this->options['config_page_type'] : '',
];
}
public function getArgument() {
$type = ConfigPagesType::load($this->options['config_page_type']);
$context = $type
->getContextData();
return $context;
}
public function getCacheMaxAge() {
return Cache::PERMANENT;
}
public function getCacheContexts() {
return [];
}
}