Last active
August 29, 2015 14:07
-
-
Save dmouse/9c5b88a7aa7bb965a986 to your computer and use it in GitHub Desktop.
Drupal 8 Current User in Entity Resource Plugin #rest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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