logo

Blog

12 February

code to create custom form in Drupal 8 and 9

Published On: Sun, 02/12/2023 - 22:51

Here is an example of a custom form with an email and message field in Drupal 8 or 9

use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;

/**
 * Class CustomForm.
 */
class CustomForm extends FormBase {

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'custom_form';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $form['email'] = [
      '#type' => 'email',
      '#…
				  

21 November

Colorbox image gallery not working on Mobile in Drupal

Published On: Mon, 11/21/2022 - 10:57

Step 1 - Go to configuration

Step 2 - Open Colorbox settings

Step 3 - Click on Advance setting

There is an option of Mobile detection if its "On" now it should be "Off"

Now clear cache I hope its work now.

There is setting screenshot image

 

10 November

Redirect domain to WWW in Wordpress

Published On: Thu, 11/10/2022 - 13:14

Set site address correctly in your admin Settings -> General section

You can see in following example. You can set domain with www or without www.

22 September

Step to Configure Gmail Id in Microsoft Outlook

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

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

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

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

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

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

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