Latest Articles

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

How can get client IP Address in Drupal 8

I want to know IP Address of my website so can who is visiting or I want to location where is website visited using IP address.

Soln,

Add this code at top like other header

use Symfony\Component\HttpFoundation;

Use this code to get IP Address

\Drupal::request()->getClientIp()

Getting Error "CSV Serialization requires the League\Csv library" in Drupal 8

When I want to installed Views Data Export module to export CSV then we getting error as "CSV Serialization requires the League\Csv library"
We follow this step then I have installed module
1. Install module "Ludwig" module and enable the module
2. open this path "/admin/reports/packages" that will show missing library then you can download that library.
3 Upload required library in given location
4. Unzip that files and upload their all files and directory in /modules/csv_seri…

Get user list by role programmatically in Drupal8

User this code before

use Drupal\user\Entity\User;

Thise code will be return user list of a given role (editor)

	$ids = \Drupal::entityQuery('user')
	->condition('status', 1)
	->condition('roles', 'editor')
	->execute();
	$users = User::loadMultiple($ids);
	foreach($users as $user){
		$username = $user->get('name')->value;
		$uid = $user->get('uid')->value;
		$userlist[$uid] = $username;
	}

Get URL parameters/argument in custom module Drupal 8

If you created URL with parameters in custom module as given example

http://localhost/drup/member/179

In example you need to access the value 179 in your code then follow these step

Use this line at top

Use \Drupal\Core\Routing;

You can use this code so its return all parameters but its return as object so again you need to load that object

You can use that code with named parameters as follows

$value = \Drupal::routeMatch()->getParameter…

Get URL by Node id Drupal 8

you have to use following class

Drupal\Core\Url

You can use folowing code to get URL Alias

		$options = ['absolute' => TRUE];
		$url = \Drupal\Core\Url::fromRoute('entity.node.canonical', ['node' => $nid], $options);
		$nodeurl = $url->toString();

Get or Set config value programmatically Drupal 8

Get value of variable from configuration form

You can get config value in any custom code using following method

Example 1

$phone = \Drupal::config('socialmedia.settings')->get('phone');

In above example "socialmedia.settings" is const which has been defined in configuration form and "phone" is variable where stored value

Will get value which have beed set through configuration form.

Example 2

$slogan = \Drupal::config('system.site')->ge…

Get node id of current node page Drupal 10

	$node = \Drupal::routeMatch()->getParameter('node');
	if ($node instanceof \Drupal\node\NodeInterface) {
	  // You can get nid and anything else you need from the node object.
	  $nid = $node->id();
	}

Get installed a POS system to improve the business and manage accurately

A small store to a large retail store is advisable to use Point of Service systems to easily customize their routine operations. It increases productivity, business, revenue, relationship with customers, and also saves time efficiently. Free POS applications can be used in simple business procedures using existing tools where advanced system is not affordable. POS is connected with multiple computers, printers, scanners at the administrator, sales counter, and many more locations. If addition…

Get field value of reference node on node twig template Drupal 8 and 9

In following example field_course_ref is a field which reference with other node, field_course_type is a field of the reference content type which is a term so we get term name

{{ node.field_course_ref.entity.field_course_type.entity.name.value }}

Get error undefined method File::url() in Drupal 9

I was trying to create a custom banner based on user uploaded image in node then I got following error in Drupal 9 but it was workiing in Drupal 8

 

Following code I was using

$img_url = $file->url();

Getting this error

Error: Call to undefined method Drupal\file\Entity\File::url() in theme_preprocess_page() 

I found the solution its working fine in simply use createFileUrl(); instead of url();

 

Functions file_create_url() not working in Drupal 10

Functions file_create_url() was using to create url of images and files drupal 9 but now its not working in Drupal 10 so its deprecated now you can use code as follow to create url in Drupal 10

 

\Drupal::service('file_url_generator')->generateAbsoluteString($uri);

 

Used in Drupal 9 and beforeUsing Drupal 10
file_create_url($uri)\Drupal::service('file_url_generator…

FTP or FileZilla not working with Airtel Broadband

Sometime we face FTP connection issue with AIrtel Broadband so follow this step to resolved this issue.

Open the IP Address 192.168.1.1 in browser
Login with password given by Airtel
Go to Services Tab

Service Tab Airtel
Click on Left Menu of Firewall then Firewal menu will d…