WebTechKitchen; Your Web Technology Kitchen, contact us to create, or maintain your websites and other digital properties.

Getting the current user in Drupal 8

Submitted by barnettech on Tue, 12/17/2013 - 14:44

https://drupal.org/node/2017231

<?php
use Drupal\Core\Session\AccountInterface;
function mymodule_function() {
  $account = \Drupal::currentUser();
  if ($account->id()) {
    // User is logged in.
  }
}
function mymodule_needs_user(AccountInterface $user) {
}