Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Drupal\user\Plugins\core\tokens;
- use Drupal\Component\Plugin\PluginAbstract;
- class UserTokens extends PluginAbstract {
- public function __construct(array $data) {
- $this->account = $data['user'];
- $this->url_options = array('absolute' => TRUE);
- $this->language_code = $this->getLangCode($data);
- $this->sanitize = !empty($options['sanitize']);
- }
- protected function getLangCode(array $data) {
- if (isset($options['language'])) {
- $this->url_options['language'] = $options['language'];
- $this->language_code = $options['language']->language;
- }
- else {
- $this->language_code = NULL;
- }
- }
- public function uidToken() {
- return !empty($this->account->uid) ? $this->account->uid : t('not yet assigned');
- }
- public function nameToken() {
- $name = format_username($this->account);
- return $this->sanitize ? check_plain($name) : $name;
- }
- public function mailToken() {
- return $this->sanitize ? check_plain($this->account->mail) : $this->account->mail;
- }
- public function urlToken() {
- return !empty($this->account->uid) ? url("user/$this->account->uid", $this->url_options) : t('not yet assigned');
- }
- public function editUrlToken() {
- return !empty($this->account->uid) ? url("user/$this->account->uid/edit", $this->url_options) : t('not yet assigned');
- }
- public function lastLoginToken() {
- return !empty($this->account->login) ? format_date($this->account->login, 'medium', '', NULL, $this->language_code) : t('never');
- }
- public function createdToken() {
- return !empty($this->account->created) ? format_date($this->account->created, 'medium', '', NULL, $this->language_code) : t('not yet created');
- }
- public function __call($string, $arguments) {
- // This portion of the method should likely exist on an abstract for tokens
- $method = $string . 'Token';
- if (method_exists($this, $method)) {
- return call_user_method_array($method, $this, $arguments);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment