0

I created a link to personal contact form in page content, and I want to remove it from tabs. How to do that without breaking functionality?

1

I didn't test the following example code though, but you will be able to remove tabs using hook_menu_local_tasks_alter() in a custom module (replace mymodule by the name of your custom module):

/**
 * Implements hook_menu_local_tasks_alter().
 */
function mymodule_menu_local_tasks_alter(&$data, $route_name) {
  // Whether the personal contact form tab is present. You
  // can fine-tune your conditions here. The tab route was
  // taken from ./core/modules/contact/contact.links.task.yml.
  if (isset($data['tabs'][0]['entity.user.contact_form']) {
    unset($data['tabs'][0]['entity.user.contact_form']);
  }
}

As mentioned before, I did not really try the above code. You might have to check the contents of the $data array to find the right plugin id and correct position of the tab definition when visiting a user's page.

Also note, that the tabs information will be cached. So you will have to rebuild your caches for the changes to take effect and the above hook to being triggered.

The functionality will be kept, as the route behind the tab is still active when you alter the local tasks array only.

  • but I haven't "module", only theme – Crantisz Mar 4 '18 at 0:02
  • Then you should create a custom module. drupal.org/docs/8/creating-custom-modules It's not hard and really handy for all kind of hook implementations and customizations. Place above hook in the .module file. The theme allows for theming hooks only. So having at least one custom module is your best bet. – Mario Steinitz Mar 4 '18 at 0:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.