function twig_field_default_context in Twig Field 8
Returns default Twig context.
Return value
array Twig context.
3 calls to twig_field_default_context()
- TwigFormatter::viewElements in src/
Plugin/ Field/ FieldFormatter/ TwigFormatter.php - Builds a renderable array for a field value.
- TwigWidget::formElement in src/
Plugin/ Field/ FieldWidget/ TwigWidget.php - Returns the form for a single field widget.
- TwigWidget::validateTemplate in src/
Plugin/ Field/ FieldWidget/ TwigWidget.php - Validation callback for a Template element.
File
- ./
twig_field.module, line 20 - Primary module hooks for Twig field module.
Code
function twig_field_default_context() {
$context = [];
$theme = \Drupal::theme()
->getActiveTheme();
$context['theme'] = $theme
->getName();
$context['theme_directory'] = $theme
->getPath();
$context['base_path'] = base_path();
$context['front_page'] = Url::fromRoute('<front>');
$context['is_front'] = \Drupal::service('path.matcher')
->isFrontPage();
$context['language'] = \Drupal::languageManager()
->getCurrentLanguage();
$user = \Drupal::currentUser();
$context['is_admin'] = $user
->hasPermission('access administration pages');
$context['logged_in'] = $user
->isAuthenticated();
return $context;
}