Overriding profile2 user registration on 2 different urls

in your theme’s template.php add following code function bartik_theme() { $items = array(); $items[‘user_login’] = array( ‘render element’ => ‘form’, ‘path’ => drupal_get_path(‘theme’, ‘bartik’) . ‘/templates’, ‘template’ => ‘user-login’, ‘preprocess functions’ => array( ‘bartik_preprocess_user_login’ ), ); $items[‘user_register_form’] = array( ‘render element’ => ‘form’, ‘path’ =>[…]

Unset node edit link on node view page conditional drupal 8

function YOURMODULENAME_menu_local_tasks_alter(&$local_tasks) { $node = Drupal::routeMatch()->getParameter(‘node’); if ($node instanceof DrupalnodeNodeInterface) { // You can get nid and anything else you need from the node object. $nid = $node->id(); $node_modified = $node->YOURFIELDNAME->getValue(); $node_modified = $node_modified[0][‘value’]; if ($node_modified == 1) { unset($local_tasks[‘tabs’][0][‘entity.node.edit_form’]); } } } Drupal version: […]

ExternalAuth

— SUMMARY — ExternalAuth allows to configure & setup cookies, which could be used to check logged in user’s authentication of drupal for any external file/webservice, which is not possible to use within drupal. After enabling this module site administrators are then able to setup[…]

Overriding a custom content type D8

In your .module file add the following functions function YOURMODULENAME_theme() { $theme[‘node__YOURCONTENTTYPENAME’] = array( ‘render element’ => ‘content’, ‘base hook’ => ‘node’, ‘template’ => ‘node–YOURCONTENTTYPENAME’, ‘path’ => drupal_get_path(‘module’, ‘tm_YOURMODULENAME’) . ‘/templates’, ); return $theme; } put node–YOURCONTENTTYPENAME.html.twig in your modules /templates/ directory function YOURMODULENAME_preprocess_node(&$variables) {[…]

Overriding user login

For overriding user log in page, add a file “user-login.tpl.php” in your themes “template” directory then in your themes “template.php” file add code as follow function YOURTHEMENAME_theme() { $items = array(); $items[‘user_login’] = array( ‘render element’ => ‘form’, ‘path’ => drupal_get_path(‘theme’, ‘YOURTHEMENAME’) . ‘/templates’, ‘template'[…]

Overriding node add & user registration form

Put following code in your theme’s template.php file function YOURTHEMENAME_theme() { $items = array(); $items[‘user_login’] = array( ‘render element’ => ‘form’, ‘template’ => ‘user-login’, ‘path’ => drupal_get_path(‘theme’, ‘YOURTHEMENAME’) . ‘/templates’, ‘preprocess functions’ => array( ‘YOURTHEMENAME_preprocess_user_login’ ), ); $items[‘client_form_node_form’] = array( ‘render element’ => ‘form’, ‘template'[…]

D8 Populate og group & reference filed through form alter

use DrupalnodeEntityNode; use DrupalCoreFormFormStateInterface; /** * Implements hook_form_alter() */ function YOURMODULENAME_form_alter(&$form, FormStateInterface $form_state, $form_id) { if ($form_id == ‘your_form_id’) { $nid = Drupal::request()->query->get(‘nid’); $node = is_numeric($nid) ? Node::load($nid) : NULL; if ($node->getType() == ‘ABC’) { $form[‘og_audience’][‘widget’][0][‘target_id’][‘#default_value’] = $node; } elseif ($node->getType() == ‘XYZ’) { $form[‘your_filed_name’][‘widget’][0][‘target_id’][‘#default_value’][…]

D8 Load a twig template

Load and render a twig template $twig = Drupal::service(‘twig’); $template = $twig->loadTemplate(‘path/to/your_template.html.twig’); $response = $template->render([‘var1’ => $var1, ‘var2’ => $var2]); return $response; var1 & var2 will also be pass as variable to twig template which we can use as follow {{ var1 }} Drupal version: […]

D8 embed a view in template

// Render a template file $twig = Drupal::service(‘twig’); $view_content = views_embed_view(‘your view name’, ‘block_1’); $template = $twig->loadTemplate(‘/templates/your_block.html.twig’); $build[‘your_block’][‘#markup’] = $template->render([‘view_content’ => $view_content]); return $build; in your twig template u can embed view as follow {{ view_content }} Drupal version:  Drupal 8.x Source: https://www.drupal.org/taxonomy/term/2/feed

D8 form alter to auto populate a default value for og audience

use DrupalnodeEntityNode; use DrupalCoreFormFormStateInterface; /** * Implements hook_form_alter() on behalf of tm_sketch.module. */ function YOUR-MODULE-NAEM_form_alter(&$form, FormStateInterface $form_state, $form_id) { if ($form_id == ‘your form id’) { $nid = Drupal::request()->query->get(‘nid’); $node = is_numeric($nid) ? Node::load($nid) : NULL; $form[‘og_audience’][‘widget’][0][‘target_id’][‘#default_value’] = $node; } } Drupal version:  Drupal 8.x[…]