ProfileOwner.php in Profile 8
File
src/Plugin/views/argument_default/ProfileOwner.php
View source
<?php
namespace Drupal\profile\Plugin\views\argument_default;
use Drupal\profile\Entity\ProfileInterface;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ProfileOwner extends ArgumentDefaultPluginBase implements CacheableDependencyInterface {
protected $routeMatch;
public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteMatchInterface $route_match) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->routeMatch = $route_match;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('current_route_match'));
}
public function getArgument() {
if (($profile = $this->routeMatch
->getParameter('profile')) && $profile instanceof ProfileInterface) {
return $profile
->getOwnerId();
}
}
public function getCacheMaxAge() {
return Cache::PERMANENT;
}
public function getCacheContexts() {
return [
'url',
];
}
}
Classes
Name |
Description |
ProfileOwner |
Default argument plugin to extract a user from a profile. |