You are here

function _rate_set_common_theme_variables in Rate 8

Helper function to set common themeing variables.

5 calls to _rate_set_common_theme_variables()
template_preprocess_rate_template_fivestar in ./rate.module
Implements hook_preprocess_HOOK() for rate-template-fivestar.html.twig.
template_preprocess_rate_template_number_up_down in ./rate.module
Implements hook_preprocess_HOOK() for rate-template-number-up-down.html.twig.
template_preprocess_rate_template_thumbs_up in ./rate.module
Implements hook_preprocess_HOOK() for rate-template-thumbs_up.html.twig.
template_preprocess_rate_template_thumbs_up_down in ./rate.module
Implements hook_preprocess_HOOK() for rate-template-thumbs_up_down.html.twig.
template_preprocess_rate_template_yesno in ./rate.module
Implements hook_preprocess_HOOK() for rate-template-yes_no.html.twig.

File

./rate.module, line 405
Hook implementation code for the Rate module.

Code

function _rate_set_common_theme_variables(&$variables, $generate_links = TRUE) {
  $destination = \Drupal::destination()
    ->getAsArray();
  if (!$variables['entity_id']) {
    $variables['can_vote'] = FALSE;
    return;
  }
  if ($generate_links) {
    $variables['up_url'] = Url::fromRoute('rate.vote', [
      'entity_type_id' => $variables['entity_type_id'],
      'vote_type_id' => 'updown',
      'value' => 1,
      'entity_id' => $variables['entity_id'],
      'widget_type' => $variables['widget_type'],
      'destination' => $destination['destination'],
    ]);
    $variables['down_url'] = Url::fromRoute('rate.vote', [
      'entity_type_id' => $variables['entity_type_id'],
      'vote_type_id' => 'updown',
      'value' => -1,
      'entity_id' => $variables['entity_id'],
      'widget_type' => $variables['widget_type'],
      'destination' => $destination['destination'],
    ]);
  }
  $output['info_description'] = [
    // @Todo: Add info and description to to settings form.
    '#theme' => 'info_description',
    '#info' => '',
    '#description' => '',
  ];
  $variables['destination'] = $destination['destination'];
  $variables['widget_attributes'] = new Attribute();
  $variables['widget_attributes']['data-drupal-selector'] = 'rate-' . $variables['entity_type_id'] . '-' . $variables['entity_id'];
  $variables['widget_attributes']['class'] = [];
  $class = str_ireplace('rate_template_', '', $variables['theme_hook_original']);
  $variables['widget_attributes']['class'][] = 'rate-widget-' . str_ireplace('_', '-', $class);
}