Im trying to display the last accessed field when a user logs in. For this I tried using User::getLastLoginTime() . But this returns a fatal error saying
PHP Fatal error: Call to undefined method Drupal\customize_block\Plugin\Block\ContractDetails::get() in /var/www/html/core/modules/user/src/Entity/User.php on line 265
Here is my block ,in my custom module:
/**
* Provides a 'Customized contract' Block
*
* @Block(
* id = "customer_info",
* label = @Translation("Customer and contract info"),
* module = "user",
* context = {
* "current_user" = @ContextDefinition("entity:user", label = @Translation("Current User"))
* }
* )
namespace Drupal\customize_block\Plugin\Block;
use Drupal\Core\Block\BlockBase;
class ContractInfo extends BlockBase {
public function build() {
$output='';
global $base_url;
$current_user = $this->getContext('current_user');
$output.='<div>' . $current_user -> contextData . '</div>';
return array(
'#markup' => $output,
'#cache' => array(
'contexts' => array('url'),
),
);
}
}
Am I calling this method correct way?