logo

Blog

28 May

Select Query to get users of empty fields
By: alam | Published On: Fri, 05/28/2021 - 23:30

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);
	$…
				  

26 May

How to create or manage configuration form in Drupal 8
By: alam | Published On: Wed, 05/26/2021 - 19:16

Create configuration form

create path in routing.yml, here my module name is "mymodule" so I am using it, you can use your module name.

I have created form "MyConfigurationForm.php" in folder src/Form

_permission: 'mymodule dashboard_admin' command is used to set permission for the rout path, We create a separate file  name "mymodule.permissions.yml"  where permission related code will be appear on URL based 

 

mymodule.…
				  

30 April

Add External CSS in Drupal 8
By: admin | Published On: Fri, 04/30/2021 - 11:15

How can add externalcss in Drupal 8 ?

Post following format in libraries.yml, for example my theme name is customtheme so the file will be 'customtheme.libraries.yml'  in theme folder

css:
    theme:
      'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css': { type: external, minified: true }
      'https://fonts.googleapis.com/css2?family=Noto+Sans:ital,wght@0,400;0,700;1,400;1,700&display=swap': { type: external, minified:…
				  

1 April

How to create or manage configuration form in Drupal 8
By: admin | Published On: Thu, 04/01/2021 - 18:15

How to create or manage configuration form in Drupal 8

Create configuration form

create path in routing.yml, here my module name is "mymodule" so I am using it, you can use your module name.

mymodule.Myfiguration:
  path: 'myconf'
  defaults:
    _form: '\Drupal\mymodule\Form\MyConfigurationForm'	// I have created form "MyConfigurationForm.php" 
    _title: 'My API Configuration'
  requirements:
    _permission: 'mymodule dashboard_admin'		// this is permission…
				  

24 March

How can get client IP Address in Drupal 8
By: admin | Published On: Wed, 03/24/2021 - 22:12

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()

3 March

Install razorpay library using composer for payment gateway integration
By: alam | Published On: Wed, 03/03/2021 - 13:29

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

Then you need to enter those folder where your website exist for example I have website in public_html then I run following command

cd public_html…
				  

1 March

Page Template for Views Page
By: admin | Published On: Mon, 03/01/2021 - 12:13

If you want to create template for views page like page.tpl.twig so you follow these step. Whole page template for views page.

Create copy of page.tpl.twig If your views url is ‘news-and-articles’ then rename file as ‘page--news_and_articles.html.twig’ and upload in your themes folder. If url has dash then replace dash with underscore.

After clear cache current template will work for this views instead of page.tpl.twig.

22 April

Get user list by role programmatically in Drupal8
By: admin | Published On: Wed, 04/22/2020 - 22:13

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;
	}
				  

22 April

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 /…

22 April

How to form alter of node page in DRUPAL 8
By: admin | Published On: Wed, 04/22/2020 - 22:13

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',
		 '#…