Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh
Category:

How to override a local task in Drupal 8

 

For Drupal 8, this is what worked for me. I also adjusted the weights so I could re-order the items.

/**
 * Implements hook_local_tasks_alter().
 *
 * @inheritdoc
*/
function mymodule_local_tasks_alter(&$local_tasks) {

  $local_tasks['entity.user.canonical']['title'] = 'Account Details';
  $local_tasks['entity.user.canonical']['weight'] = -3;

  $local_tasks['entity.user.edit_form']['title'] = 'Edit Account';
  $local_tasks['entity.user.edit_form']['weight'] = -2;

}

 

Example 2:

/* mycomment.module */

/**
 * Set the unapproved comments count.
 *
 * Implements hook_menu_local_tasks_alter().
 */
function mycomment_menu_local_tasks_alter(&$data, $route_name, &$cacheability) {
  if ($route_name == 'comment.admin' ||
    $route_name == 'comment.admin_approval' ||
    $route_name == 'mycomment.admin_comment_spam'
   ) {
    $data['tabs'][1]['comment.admin_approval']['#link']['title'] =
      t('Unapproved comments (@count)', [
        '@count' => get_actual_unapproved_comments(),
    ]);
  }
}

 

/* mycomment.module */

/**
 * Get the number of unapproved comments.
 *
 * @return int
 *   The number of unapproved comments excluding the spam comments.
 */
function get_actual_unapproved_comments() {
  $query = \Drupal::entityQuery('comment');
  $query->condition('status', 0);
  $orCondition = $query->orConditionGroup();
  $orCondition->condition('field_spam', NULL, 'IS NULL');
  $orCondition->condition('field_spam', FALSE, '=');
  $query->condition($orCondition);
  $ids = $query->execute();
  return count($ids);
}

Comments

Add new comment

Restricted HTML

Search

Page Facebook

Become a patron

If you need some help or you search a Drupal freelancer don't hesitate to contact us.

 

Contact Us

All the content is FREE but I still need your help

 

Become a patreon