function template_preprocess_support_ticket in Support Ticketing System 8
Prepares variables for support ticket templates.
Default template: support-ticket.html.twig.
Themes can use their own copy of support-ticket.html.twig. The default is located inside "support/modules/support_ticket/templates/support-ticket.html.twig". Look in there for the full list of variables.
Parameters
array $variables: An associative array containing:
- elements: An array of elements to display in view mode.
- support_ticket: The support ticket object.
- view_mode: View mode; e.g., 'full', 'teaser', etc.
File
- modules/
support_ticket/ support_ticket.module, line 499 - Enables use of support tickets with optional time tracking.
Code
function template_preprocess_support_ticket(&$variables) {
$variables['view_mode'] = $variables['elements']['#view_mode'];
// Provide a distinct $teaser boolean.
$variables['teaser'] = $variables['view_mode'] == 'teaser';
$variables['support_ticket'] = $variables['elements']['#support_ticket'];
/** @var \Drupal\support_ticket\SupportTicketInterface $support_ticket */
$support_ticket = $variables['support_ticket'];
$variables['date'] = drupal_render($variables['elements']['created']);
unset($variables['elements']['created']);
$variables['author_name'] = drupal_render($variables['elements']['uid']);
unset($variables['elements']['uid']);
$variables['url'] = $support_ticket
->url('canonical', array(
'language' => $support_ticket
->language(),
));
$variables['label'] = $variables['elements']['title'];
unset($variables['elements']['title']);
// The 'page' variable is set to TRUE in two occasions:
// - The view mode is 'full' and we are on the 'support_ticket.view' route.
// - The support ticket is in preview and view mode is either 'full' or 'default'.
$variables['page'] = $variables['view_mode'] == 'full' && support_ticket_is_page($support_ticket) || isset($support_ticket->in_preview) && in_array($support_ticket->preview_view_mode, array(
'full',
'default',
));
// Helpful $content variable for templates.
$variables += array(
'content' => array(),
);
foreach (Element::children($variables['elements']) as $key) {
$variables['content'][$key] = $variables['elements'][$key];
}
// Display post information only on certain support ticket types.
$support_ticket_type = $support_ticket->support_ticket_type->entity;
// Used by RDF to add attributes around the author and date submitted.
$variables['author_attributes'] = new Attribute();
$variables['display_submitted'] = $support_ticket_type
->displaySubmitted();
}