logo

Blog

1 June

What is the purpose of Ctools in Drupal 9
By: admin | Published On: Thu, 06/01/2023 - 17:53

In Drupal 9, Ctools (Chaos tools) is a suite of developer tools and APIs that provide various functionalities to enhance and simplify module development. Ctools is not specific to Drupal 9 and has been widely used in previous versions as well.

The primary purpose of Ctools is to provide a set of reusable utilities and APIs that help developers build complex and interactive features in Drupal. Some of the key features and purposes of Ctools in Drupal 9 include:

1 June

What are the benefits of using Drupal
By: admin | Published On: Thu, 06/01/2023 - 17:18

Drupal is a powerful and flexible open-source content management system (CMS) that offers numerous benefits for website development and management. Here are some of the key benefits of using Drupal:

  1. Flexibility: Drupal provides a highly flexible and extensible framework that allows developers to build websites and applications tailored to specific needs. It offers a wide range of modules, themes, and APIs, enabling the creation of custom functionalities and designs.…

1 June

Show Related Content by Category Using Views Drupal 8 or 9
By: admin | Published On: Thu, 06/01/2023 - 11:20

Follow these step to make block using views to show the related content according to category of the current content page.

Edit the views and open Advance section

  1. Add the  'Content: Has taxonomy term ID' in CONTEXTUAL FILTERS.
  2. Check 'Provide default value' option and then select the 'Taxonomy term ID from URL'.

 …

24 March

How can run my code on user login Drupal 8
By: admin | Published On: Fri, 03/24/2023 - 15:50

In Drupal 8, you can execute code before user login by implementing a custom module and using a hook to execute the code. Here are the steps you can follow:

  1. Create a custom module by creating a directory in the modules directory of your Drupal installation. For example, if you want to name your module "custom_login", create a directory named "custom_login" in the modules directory.

  2. Create a custom_login.info.yml

20 March

Custom code to save value in error log in Drupal 9
By: admin | Published On: Mon, 03/20/2023 - 15:40

To save values in the error log in Drupal 8, you can use the following custom code:

\Drupal::logger('my_module')->error('The error message: @variable', [
  '@variable' => $value_to_save,
]);

In the code above, replace my_module with the name of your module, and replace The error message with the message you want to include in the log entry. You can include any number of placeholders in the message using…

14 March

In views template how can check user is logged in drupal 8
By: admin | Published On: Tue, 03/14/2023 - 18:20

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…

14 March

Using custom code disable cache from menu block in drupal 8
By: admin | Published On: Tue, 03/14/2023 - 14:47

To disable caching for a specific menu block in Drupal 8 using custom code, you can implement the hook_block_view_alter hook in your custom module or theme. Here's an example implementation:

/**
 * Implements hook_block_view_alter().
 */
function mymodule_block_view_alter(array &$build, \Drupal\Core\Block\BlockPluginInterface $block) {
  if ($block->getPluginId() === 'system_menu_block:my-menu') {
    // Disable caching for the menu block.
    $build['#cache']['max-age…
				  

15 February

CUstom code if else condition in twig template drupal 8
By: admin | Published On: Wed, 02/15/2023 - 20:55

In Drupal 8, you can use the {% if %} statement to create if-else conditions in Twig templates. Here's an example:

{% if condition %}
  // Code to execute if the condition is true.
{% else %}
  // Code to execute if the condition is false.
{% endif %}

Replace "condition" with your desired condition to evaluate. You can use logical operators such as and, or, and not to create more complex conditions.

Here's an…

12 February

code to create custom form in Drupal 8 and 9
By: admin | 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
By: admin | 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
By: admin | 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.

Redirect domain to WWW in Wordpress

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.

1

  • Select your account.

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('…
				  

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

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

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