You are here

function _rate_get_undo_link in Rate 8

Helper function to return an undo link.

5 calls to _rate_get_undo_link()
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 373
Hook implementation code for the Rate module.

Code

function _rate_get_undo_link(&$variables) {
  if (!$variables['entity_id']) {
    $variables['can_vote'] = FALSE;
    return;
  }
  $variables['undo'] = '';
  $variables['undo_attributes'] = new Attribute();
  $variables['undo_attributes']['class'] = [];
  $variables['undo_attributes']['class'][] = 'rate-undo-vote';
  $undo_link_class = 'rate-undo';
  if ($variables['use_ajax']) {
    $undo_link_class .= ' use-ajax';
  }
  if ($variables['has_voted']) {
    $variables['undo'] = Link::fromTextAndUrl(t('Undo'), Url::fromRoute('rate.undo_vote', [
      'entity_type_id' => $variables['entity_type_id'],
      'entity_id' => $variables['entity_id'],
      'widget_type' => $variables['widget_type'],
      'destination' => \Drupal::destination()
        ->getAsArray()['destination'],
    ], [
      'attributes' => [
        'class' => $undo_link_class,
      ],
    ]));
  }
}