Skip to content

Instantly share code, notes, and snippets.

View lincoln-chawora's full-sized avatar

Lincoln Chawora lincoln-chawora

  • TPX Impact
View GitHub Profile
@lincoln-chawora
lincoln-chawora / menu_local_tasks_alter.php
Created September 2, 2019 12:03
How to remove a menu tab from a content type in drupal 8
/**
* Implements hook_menu_local_tasks_alter().
*
* Remove replicate menu tab.
*/
function YOUR_THEME_menu_local_tasks_alter(&$data, $route_name, RefinableCacheableDependencyInterface &$cacheability) {
$routes = &$data['tabs'][0];
if ($routes['replicate_ui.local_tasks:entity.node.replicate']) {
unset($routes['replicate_ui.local_tasks:entity.node.replicate']);
}
@lincoln-chawora
lincoln-chawora / load_node.php
Last active January 10, 2020 18:48
How load a node in drupal 8
$route_name = \Drupal::routeMatch()->getRouteName();
if ($route_name == 'entity.node.canonical') {
node = \Drupal::routeMatch()->getParameter('node');
$node_type = $node->getType();
$title = $node->getTitle();
$visible = $node->isPublished();
$node->setPromoted(TRUE);
$uid = $node->getOwnerId();
// $author will be user object of the person who created the node.
@lincoln-chawora
lincoln-chawora / paragraph_id_from_field_template.php
Created August 23, 2019 17:51
How to get paragraphs ID from inside a field template using a field preprocessor
$field['#object']->entity_id();