21 September

Get error undefined method File::url() in Drupal 9
By: admin | Published On: Thu, 09/21/2023 - 16:44

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


31 July

Update node field value of a content type using batch process in Drupal 9
By: admin | Published On: Mon, 07/31/2023 - 17:02

To update the text field value of a content type in Drupal 9 using a batch process, you can follow these steps:

Create a custom module: If you don't have one already, create a custom module in the 'modules/custom' directory of your Drupal installation.

Define a form to receive the user input: Create a form in your custom module that takes the new value for the text field as input from the user. This form will be used to trigger the batch process.

Implement the batch…

27 July

How render term field on node template in drupal 9
By: admin | Published On: Thu, 07/27/2023 - 16:56

In Drupal 9, you can render a term field on a node template using the field_view_field() function. This function takes the following parameters:

Entity type: The type of the entity (in this case, it's "node").
Entity: The node object that contains the term field.
Field name: The machine name of the term field you want to render.
Display mode: The view mode you want to use to render the field (e.g., "full", "teaser", "default", etc.).

Here's an example of how…

23 June

Set default value user name in user login form using form alter drupal 8
By: admin | Published On: Fri, 06/23/2023 - 08:53

To set a default value for the username field in a user login form using a form alter hook in Drupal 8, you can use the following code:

 * Implements hook_form_alter().
function yourmodule_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  if ($form_id === 'user_login_form') {
    // Set the default value for the username field.
    $form['name']['#default_value'] = 'your_default_username';

Replace 'yourmodule'…

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


  •     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.

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.


  • 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


Method 2


Method 3


Method 4


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