Latest Articles

Our latest news updates and insightful blog posts, designed to empower you with the knowledge and strategies you need to succeed.

Theming drupal commerce product page in Drupal 10

Theming a Drupal Commerce product page involves customizing the Twig templates, CSS, and possibly preprocess functions to control the look and feel of the product display. Here’s a structured approach:

Identify the Template to Override

Drupal uses Twig templates to render product pages. The most relevant template for product pages is:

 

commerce-product--[product-type].html.tw…

Templates Example and Template Name Drupal 8 and 9

Drupal loads templates based on certain naming conventions. This allows you to override templates by adding them to your theme and giving them specific names.

HTML Template for Head Tag

The HTML template provides markup for the basic structure of the HTML-page including the ,and tags.

Base template: html.html.twig (base location: core/modules/system/templates/html.html.twig)

Example

html--[internalviewpath].html.twig 
html--node--[nodeid].html.twig 
html.html…

Successful Drupal Websites Around the World

For over 20 years, Drupal, the open-source content management system (CMS), has formed the foundation for building powerful, scalable, and flexible website solutions. Flexible in nature, Drupal supports websites for governments, schools, non-profits, and enterprises across the globe. This article takes a look at some of the most popular Drupal sites across the globe and how well this excellent platform has been utilized.

1. The White House (USA)

White House, The…

Step to Configure Gmail Id in Microsoft Outlook

  • Go to Gmail from your browser, then select the Google apps icon in the upper right corner of the screen.

1

  • Select your account.

Show Related Content by Category Using Views Drupal 8 or 9

Follow these step to make block using views to show the related content according to category of the current content page.

Edit the views and open Advance section

  1. Add the  'Content: Has taxonomy term ID' in CONTEXTUAL FILTERS.
  2. Check 'Provide default value' option and then select the 'Taxonomy term ID from URL'.

 …

Set default value user name in user login form using form alter drupal 8

To set a default value for the username field in a user login form using a form alter hook in Drupal 8, you can use the following code:

/**
 * Implements hook_form_alter().
 */
function yourmodule_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  if ($form_id === 'user_login_form') {
    // Set the default value for the username field.
    $form['name']['#default_value'] = 'your_default_username';
  }
}

Replace 'yourmodule' wi…

Set current date in custom form element in DRUPAL8

Set current date in custom form element in DRUPAL8

Add this line at top

 use Drupal\Core\Datetime\DrupalDateTime; 

Add the following code to your form

function HOOK_form_alter(&$form, FormStateInterface $form_state, $form_id) {
	if ($form_id == 'node_article_form') {

		$form['field_date']['widget'] = array(     
        '#type' => 'datetime',
        '#title' => 'Enter Date',
        '#required' => TRUE,
		'#default_value' => DrupalDateTime::cre…

Select Query to get users of empty fields

Select those users which name (Custom field) is empty

In the following I have created a custom field (name) in user profile, field machine name as field_name

I want get user list where name field is blank

 

$uids = \Drupal::entityQuery('user')
    ->condition('field_name', NULL, 'IS NULL')
    ->execute();
echo count($uids);

If you want to get more user through user id

foreach($uids as $uid){
	$users = User::load($uid);
	$users->get('na…

Return error on Zoom API with custom_questions in Drupal 8

Prob:


in Drupal 8 I have created custom code to post data in Zoom using ZOOM API.

I have added custom question in Zoom Dashboard as below

custom question ZOOM


Zoom API was working but when I added a custom question in Event then is showing an error as below…

Render Field Variable In Node Twig Template (Node.html.twig) Drupal 8

Render Field Variable In Node Twig Template (Node.html.twig) Drupal 8

Show Node Created Date

If you want to show node created date on template you can use code as below

{{ node.getCreatedTime|date("d/m/Y")}}

You change date format as your requirement

Display Title of node

{{ node.title.value }}

Print node url

{{ url }}

Show Term Reference Field

To display reference term name the you can use code as below

{{ node.f…

Redirect website to HTTPS Drupal

Forcely redirect the website URL to SSL

If your website is opening with both form With HTTPS and without HTTPS but you want to redirect URL to with HTTPS URL then following step you can use. I have applied this method in Drupal 8 and Drupal 9 website

If SSL enabled in your website then you can use following code in htaccess file

# Redirect to HTTPS
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L…

Redirect Method in DRUPAL8

To redirect on node add form or node creation form

$form_state->setRedirectUrl(Url::fromUri('internal:' . '/node/add/business'));

If you want to pass argument with URL

Example:

        $params['query'] = [
            'name' => $name,
            'id' => $id,
        ];
$form_state->setRedirectUrl(Url::fromUri('internal:' . '/node/add/business', $params));

Method to redirect on node id url

$url = Url::fromRoute('entity.node.canonical…