logo

Blog

22 September

Step to Configure Gmail Id in Microsoft Outlook
By: admin | Published On: Thu, 09/22/2022 - 23:00
Go to Gmail from your browser, then select the Google apps icon in the upper right corner of the screen.

Select your account.     On the left, select Security.   Under Signing into Google, if 2-Step Verification is OFF, click the>next to OFF to turn it ON. Otherwise, skip to step 4.     On the first screen, click CONTINUE.     If prompted, enter your Gmail password and then click NEXT.     Enter your phone number and select whether you want to receive your…

21 September

Get or Set config value programmatically Drupal 8
By: alam | Published On: Wed, 09/21/2022 - 13:56
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…
				  

26 August

Method to Get Username Programmatically Drupal 8
By: admin | Published On: Fri, 08/26/2022 - 19:46

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…
				  

13 August

Programmatically get term list by Vocabulary in Drupal 8
By: admin | Published On: Sat, 08/13/2022 - 20:37
	$vid = 'Vocabulary machine name';	// Vocabulary machine name for example city, state etc. 
	$terms =\Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree($vid);
	foreach ($terms as $term) {
	 $termlist[$term->tid] = $term->name;
	}

19 January

FTP or FileZilla not working with Airtel Broadband
By: admin | Published On: Wed, 01/19/2022 - 10:22

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

Click on Left Menu of Firewall then Firewal menu will drop down. Click on ALG Menu under Firewall

There will be appear screen of ALG Type now you can enable FTP from the list

Now Click on Apply Change

28 December

Query for user reference field Drupal 8
By: admin | Published On: Tue, 12/28/2021 - 14:28
    $query = \Drupal::database()->select('node', 'n');
    $query->fields('n', ['nid','type']);
	$query->condition('type', array('basic'), 'IN');		// Basic is content type
	$query->leftJoin('node__field_user_ref', 'UID', "n.nid = UID.entity_id");	// field_user_ref is entity field for user reference 
	$query->condition('UID.field_user_ref_target_id', NULL, 'IS NOT NULL');
    $pager = $query->extend('Drupal\Core\Database\Query\PagerSelectExtender')->limit(50);
    $results = $pager->…
				  

16 December

Programmatically get user picture/image in Drupal 8 or 9
By: admin | Published On: Thu, 12/16/2021 - 07:53

Following code can be used to get user picture or image by loading user data in Drupal 8

$user = \Drupal\user\Entity\User::load($uid);
$imgpath = $user->get('user_picture')->entity->uri->value;
if(!empty($imgpath)){
	$user_pic = file_create_url($picurl);
}

6 December

Programmatically add comment drupal 8
By: admin | Published On: Mon, 12/06/2021 - 16:10

Add this line in head

use Drupal\comment\Entity\Comment;

These are following code format which can use to add comment through custom code in Drupal 8 or 9

		$values = [
			'entity_type' => 'node',            	// required. 
			'entity_id'   => $nid,                	// required.       
			'field_name'  => 'comment', 			// required.
			'uid' => $uid,                         	// required.
			'comment_type' => 'comment',        	// required.
			'…
				  

22 November

Get URL by Node id Drupal 8
By: alam | Published On: Mon, 11/22/2021 - 17:31

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

12 November

Custom code to disable or hide Node Attribute or Tabs in Drupal 8 or 9
By: alam | Published On: Fri, 11/12/2021 - 19:36

When you create or edit a node there is some default option or attribute in Node Form so we can disable or hide through custom code by using following code in our custom module.

In my example trying to to through folrm_alter hook. Following code using hide URL Aliasing for the content type of Article.

	function MODULENAME_form_alter(&$form, FormStateInterface $form_state, $form_id) {
		
		if ($form_id == 'node_article_edit_form' || $form_id == '…