Skip to content

Instantly share code, notes, and snippets.

@dmouse
Last active August 29, 2015 14:07
Show Gist options
  • Select an option

  • Save dmouse/9c5b88a7aa7bb965a986 to your computer and use it in GitHub Desktop.

Select an option

Save dmouse/9c5b88a7aa7bb965a986 to your computer and use it in GitHub Desktop.
Drupal 8 Current User in Entity Resource Plugin #rest
<?php
// ...
use Drupal\Core\Session\AccountProxyInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Psr\Log\LoggerInterface;
class EntityResource extends ResourceBase {
public function __construct(
array $configuration,
$plugin_id,
$plugin_definition,
array $serializer_formats,
LoggerInterface $logger,
AccountProxyInterface $current_user) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $serializer_formats, $logger);
$this->currentUser = $current_user;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->getParameter('serializer.formats'),
$container->get('logger.factory')->get('rest'),
$container->get('current_user')
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment