You are here

function rate_theme_suggestions_alter in Rate 8.2

Implements hook_theme_suggestions_alter().

File

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

Code

function rate_theme_suggestions_alter(array &$suggestions, array $variables, $hook) {
  if ($hook == 'rate_widgets_summary') {
    $entity = $variables['vote'];
    $content = \Drupal::service('entity_type.manager')
      ->getStorage($entity
      ->getVotedEntityType())
      ->load($entity
      ->getVotedEntityId());
    $plugin = \Drupal::service('entity_type.manager')
      ->getStorage('rate_widget')
      ->load($entity->rate_widget->value)
      ->get('template');
    $suggestions[] = $hook . '__' . $plugin;
    $suggestions[] = $hook . '__' . $plugin . '__' . $entity->rate_widget->value;

    // During undo we don't have the entity anymore that the vote was cast on.
    if (isset($content)) {
      $suggestions[] = $hook . '__' . $plugin . '__' . $content
        ->getEntityTypeId();
      $suggestions[] = $hook . '__' . $plugin . '__' . $content
        ->getEntityTypeId() . '__' . $content
        ->bundle() . '__' . $entity->rate_widget->value;
      $suggestions[] = $hook . '__' . $plugin . '__' . $content
        ->getEntityTypeId() . '__' . $content
        ->bundle();
    }
  }
}