You are here

function rate_menu_local_tasks_alter in Rate 8

Same name and namespace in other branches
  1. 8.2 rate.module \rate_menu_local_tasks_alter()

Implements hook_menu_local_tasks_alter().

This unsets Voting Results tab for non-voting-enabled node types.

File

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

Code

function rate_menu_local_tasks_alter(&$data, $route_name) {
  if (isset($data['tabs'][0]) && isset($data['tabs'][0]['entity.node.canonical'])) {
    $node = Drupal::request()->attributes
      ->get('node');
    if (!$node instanceof NodeInterface) {
      $node = Drupal::entityTypeManager()
        ->getStorage('node')
        ->load($node);
    }
    if ($node) {
      $config = \Drupal::config('rate.settings');
      $enabled_types_widgets = $config
        ->get('enabled_types_widgets');
      if (!empty($enabled_types_widgets)) {
        foreach ($enabled_types_widgets as $entity_type_id => $entity_types) {
          foreach ($entity_types as $bundle => $settings) {
            if ($entity_type_id !== 'node') {
              continue;
            }
            if (!in_array($node
              ->bundle(), array_keys($entity_types))) {
              unset($data['tabs'][0]['rate.results_page']);
              break;
            }
          }
        }
      }
      elseif (isset($data['tabs'][0]['rate.results_page'])) {
        unset($data['tabs'][0]['rate.results_page']);
      }
    }
  }
}