Browse Source

Merge branch '3280199-user-data-2.x' into '8.x-2.x'

Issue #3280199: Drupal User Data addition

See merge request project/twig_tweak!13
merge-requests/13/merge
hanoii 3 years ago
parent
commit
fc23699a1a
  1. 29
      src/TwigExtension.php

29
src/TwigExtension.php

@ -178,6 +178,14 @@ class TwigExtension extends AbstractExtension {
// @endcode
new TwigFunction('drupal_config', [$this, 'drupalConfig']),
// - Drupal User Data -
//
// @code
// {{ drupal_userdata('my_module', 'name') }}
// {{ drupal_userdata('my_module', 'name', 1) }}
// @endcode
new TwigFunction('drupal_userdata', [$this, 'drupalUserData']),
// - Drupal Dump -
//
// @code
@ -865,6 +873,27 @@ class TwigExtension extends AbstractExtension {
return \Drupal::config($name)->get($key);
}
/**
* Retrieves data from a given user.
*
* @param string $module
* The name of the module the data is associated with.
* @param string $name
* The name of the data key.
* @param int $uid
* (optional) The user account ID the data is associated with if present,
* otherwise the current user will be used.
*
* @return mixed
* The data that was requested.
*/
public function drupalUserData($module, $name, $uid = NULL) {
if (!$uid) {
$uid = \Drupal::currentUser()->id();
}
return \Drupal::service('user.data')->get($module, $uid, $name);
}
/**
* Dumps information about variables.
*

Loading…
Cancel
Save