Latest Articles

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

Node field twig template multiple images/item

Node field twig template to display multiple images/item. We can theme/design each item for that field

I am using node template as follow,

node--mycontenttype.html.twig

For example my content type name is "banner" then template name as.

node--banner.html.twig

I added field as below and its display all images but Its not able to wrap each images with div so that you can add classes to create slider.

{{ content.field_gallery_images…

Method to Get Username Programmatically Drupal 8

There are several ways to get the user's name programmatically.

$uid = 1;	// For example I have get detail of user ID 1
$account = \Drupal\user\Entity\User::load($uid); // pass your uid

Method 1

drupal_set_message($account->name->value);  

Method 2

drupal_set_message($account->get("name")->value); 

Method 3

drupal_set_message($account->getUsername());

Method 4

drupal_set_message($account->name->ge…

Message Format in Drupal 8

Error Message Format

 

use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Form\FormStateInterface;
drupal_set_message(t('Something wrong!'),'error');
$form_state->setErrorByName('error',$message);	
		if ($this->validEmailAddress($form_state->getValue('email_address'))) {
			$form_state->setErrorByName('email_address', t('User exist with given Email address.'));
		}


Load taxonomy detail by term id in Drupal 10

If you have already term then you can get all other tern detail by given term ID

$term = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->load(TID);
$field_value = $term->FIELD_MACHINENAME->value;
$term_name= $term->name->value;

List of currency code with country code in PHP Array

		$currency = array(
			'AF' => 'AFN',
			'AL' => 'ALL',
			'DZ' => 'DZD',
			'AS' => 'USD',
			'AD' => 'EUR',
			'AO' => 'AOA',
			'AI' => 'XCD',
			'AQ' => 'XCD',
			'AG' => 'XCD',
			'AR' => 'ARS',
			'AM' => 'AMD',
			'AW' => 'AWG',
			'AU' => 'AUD',
			'AT' => 'EUR',
			'AZ' => 'AZN',
			'BS' => 'BSD',
			'BH' => 'BHD',
			'BD' => 'BDT',
			'BB' => 'BBD',
			'BY' => 'BYR',
			'BE' => 'EUR',
			'BZ' => 'BZD',
			'BJ' =…

List of common Node Variables in node.html.twig in Drupal 10

In Drupal 10, when working with the node.html.twig file, there are several useful variables available for rendering nodes. These variables provide access to the node entity, fields, metadata, and other useful information, making it easier to customize the way content is displayed.

Here’s a list of common Node Variables in node.html.twig in Drupal 10:

Core Node Variables

  1. node:
    • The full node…

Install razorpay library using composer for payment gateway integration

I was doing integrate razorpay payment gateway in Drupal 8 using custom code but we getting error like “Class 'Razorpay\Api\Api' not found” because razorpay library is not installed on server so follow this step to install using putty to run composer command.

In putty enter Server IP and port click on open

T…

Install PDF using mPDF module using mpdf library in Drupal

Step 1
Download module "PDF using mPDF" from https://www.drupal.org/project/pdf_using_mpdf and install this module as normal process to installing module in drupal.

First you need to install library "mPDF" using compser to enable module "PDF using mPDF"

Step 2
start putty and connect through composer login detail

Now start command line
type cd public_html and press enter, if your project in any other folder then again have to use sa…

In views template how can check user is logged in drupal 8

In a Drupal 8 views template, you can check if a user is logged in by using the following code

{% if logged_in %}
  Welcome, {{ user.name }}
{% else %}
  {{ path('user.login') }}
{% endif %}

Explanation:

  •     The logged_in variable is a boolean that is set to true if the user is logged in, and false if they are not.
  •    The user variable contains information about the currently logged-in user, such as their username…

In Google Index API get an error private://google_index_api/ is invalid

Google Index API module installed but on configuration screen get following error when upload jason file. "The file could not be uploaded because the destination private://google_index_api/ is invalid"

 

Google Index API

So I have found the solution

In sett…

How to remove trailing slash from URL Drupal 10

You can remove trailing slashes from URLs using the .htaccess file and mod_rewrite

Add the following code to your .htaccess file to Remove Trailing slashes from all URL of website.

 

RewriteRule ^(.*)\/(\?.*)?$ $1$2 [R=301,L]

This code will remove the trailing slash from URLs and issue a 301 redirect, so if someone accesses a URL with a trailing slash, they will be redirected to the same URL without the trailing slash.

Make sure…

How to form alter of node page in DRUPAL 8

I want to change select list value in my state field so we follow the step My content type is 'project' so we can get the form id as 'node_project_form' I have a feild 'state' in my content type so field machine name is 'field_state'

function MODULENAME_form_alter(&$form, FormStateInterface $form_state, $form_id) {
	$dropdown_array = array('DL'=>'Delhi');
	if ($form_id == 'node_project_form') {
		$form['field_state']['widget'] = array(     
		 '#type' => 'select',
		 '#defau…