Group.php in Organic groups 8
File
src/Plugin/views/argument_default/Group.php
View source
<?php
declare (strict_types=1);
namespace Drupal\og\Plugin\views\argument_default;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\Context\ContextProviderInterface;
use Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
class Group extends ArgumentDefaultPluginBase implements CacheableDependencyInterface {
protected $ogContext;
public function __construct(array $configuration, $plugin_id, $plugin_definition, ContextProviderInterface $og_context) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->ogContext = $og_context;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('og.context'));
}
protected function defineOptions() {
$options = parent::defineOptions();
$options['og_group_context'] = [
'default' => '',
];
return $options;
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$form['og_group_context'] = [];
}
public function getArgument() {
$group = $this
->getGroup();
if ($group instanceof ContentEntityInterface) {
return $group
->id();
}
}
public function getCacheMaxAge() {
return Cache::PERMANENT;
}
public function getCacheContexts() {
return [];
}
public function getCacheTags() {
$group = $this
->getGroup();
if ($group instanceof ContentEntityInterface) {
return Cache::buildTags('og-group-content', $group
->getCacheTagsToInvalidate());
}
return [];
}
protected function getGroup() {
$contexts = $this->ogContext
->getRuntimeContexts([
'og',
]);
if (!empty($contexts['og']) && ($group = $contexts['og']
->getContextValue())) {
if ($group instanceof ContentEntityInterface) {
return $group;
}
}
}
}
Classes
Name |
Description |
Group |
Default argument plugin to provide the group from the current context. |