Drupal 10 Interview Question List

 

General Drupal Knowledge

  1. What are the key differences between Drupal 9 and Drupal 10? Click Here
  2. What are some of the major improvements in Drupal 10’s performance compared to earlier versions? Click Here
  3. How do you approach a Drupal site migration from an earlier version to Drupal 10?
  4. Explain the significance of the Symfony framework in Drupal 10.
  5. What is the purpose of the Configuration Management System (CMI) in Drupal? How do you use it in your projects?

Custom Module Development

  1. How do you create a custom module in Drupal 10?
  2. What’s the best practice for working with Drupal hooks in custom modules? Can you give examples of hooks you commonly use?
  3. Explain how services and dependency injection work in Drupal 10 custom module development. Click Here
  4. How do you create and define custom routes in Drupal 10?
  5. What are plugins in Drupal, and how would you create a custom plugin?
  6. How do you work with the Drupal 10 Entity API to create or alter content entities? 
           Click Here

Theming & Frontend

  1. What is the role of Twig in Drupal theming, and how has Twig improved over previous templating engines?
  2. How do you override a template file in Drupal 10, and what steps do you follow to debug theming issues?
  3. What is the purpose of libraries in Drupal theming, and how do you use them to include CSS and JavaScript files?
  4. Can you explain what a Twig extension is and how to create one for a custom project?
  5. What’s your approach to implementing responsive design in Drupal 10?

Configuration Management & Deployment

  1. How does the Drupal 10 Configuration Management system differ from earlier versions?
  2. How do you manage configuration synchronization between different environments (local, dev, production)?
  3. What tools do you use for continuous integration and automated deployment in a Drupal project?
  4. Can you explain how Drupal's Update API works, and how do you handle database updates?

Caching & Performance

  1. What caching mechanisms are available in Drupal 10? How do you optimize a Drupal site’s performance?
  2. How would you diagnose and fix slow database queries in a Drupal environment?
  3. Explain Drupal’s render cache system and how you manage cache invalidation.
  4. How do you use Varnish or Redis to enhance performance in a Drupal project?

Security Best Practices

  1. What steps do you take to secure a Drupal 10 site?
  2. How do you handle user roles, permissions, and access control in Drupal?
  3. Can you explain how you would prevent CSRF, XSS, and SQL Injection attacks in Drupal?
  4. How do you keep your Drupal site up to date with security patches?

Webforms & APIs

  1. How do you create and manage custom webforms in Drupal 10?
  2. Explain how you would integrate third-party APIs with Drupal 10 using REST, JSON
    , or GraphQL.
  3. How do you use Drupal's Queue API to handle deferred or asynchronous tasks?

Multilingual & Localization

  1. What’s the process for configuring a multilingual Drupal 10 website?
  2. How do you manage translations for content entities, config entities, and strings in Drupal 10?

Composer & Dependency Management

  1. What role does Composer play in Drupal 10 project management?
  2. How do you handle module updates and core updates using Composer in a project?

Testing & Debugging

  1. What testing frameworks are integrated with Drupal 10? How do you perform automated testing?
  2. Can you walk through how you debug issues in Drupal (e.g., using Xdebug, Drupal’s watchdog log, etc.)?
  3. What is PHPUnit, and how do you write unit tests for Drupal 10 custom modules?

Decoupled Drupal

  1. What is Decoupled Drupal? Have you worked on a decoupled or headless Drupal project? If so, what technologies did you use?
  2. How do you use JSON
    or GraphQL to expose Drupal data to an external frontend?

Leadership & Architecture

  1. How do you approach large-scale Drupal projects and ensure high code quality?
  2. What’s your process for performing a site audit and identifying bottlenecks or areas for improvement?
  3. Have you led a team in a Drupal development project? How do you manage code reviews, team coordination, and project milestones?

Drupal Ecosystem

  1. What contributed modules do you commonly use and why?
  2. How do you contribute to the Drupal community (e.g., patches, custom modules, etc.)?
  3. How do you manage custom code while still leveraging Drupal's contributed modules ecosystem?
For PHP Interviews Question  Click Here

For MySQL Interviews Question  Click Here

Drupal 10 Interview Question Bank (With Answers)

 Multiple databases can be connected to Drupal using the Database API and configuring settings.php file.

     Use the Database API to connect to additional databases

     Add the database connection details to settings.php file

     Use the db_set_active() function to switch between databases

     Use the db_query() function to execute queries on the selected database


#Drupal 8

#Adding additional databases to your configuration

Preferably you would add your configuration to the settings.php file for your site so that all modules can interact with the new database.

In your settings.php:

$databases['default']['default'] = array (
  'database' => 'drupal8_default',
  'username' => 'root',
  'password' => 'root',
  'prefix' => '',
  'host' => 'localhost',
  'port' => '3306',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
  'driver' => 'mysql',
);

$databases['second']['default'] = array (
  'database' => 'drupal8_second',
  'username' => 'root',
  'password' => 'root',
  'prefix' => '',
  'host' => 'localhost',
  'port' => '3306',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
  'driver' => 'mysql',
);

#Connect to the correct data base:

//To get the default database key "default"
$con = \Drupal\Core\Database\Database::getConnection();

//To get another database (here : 'second')
$con = \Drupal\Core\Database\Database::getConnection('default','second');

//To set the active connection
$conn = \Drupal\Core\Database\Database::setActiveConnection('second');

What is Patch and How to create a patch in Drupal

A patch is a software update comprised code inserted (or patched) into the code of an executable program. Typically, a patch is installed into an existing software program. Patches are often temporary fixes between full releases of a software package.

Patch is a file that consists of a list of differences and is usually created with the help of the git diff command. In the Drupal community, developers make use of this patch file as a contribution to fix an issue or enhance a feature in a module, theme, or even for Drupal core.

Below are the step for creating a patch

1 - Create and set up a repository on GitHub specifically for creating patch files. It is best to maintain a single git repository for the patch files that you will be applying to your drupal project.

2 - Move the module/theme or core files that you need to generate patches to the newly created git repository

3 - Make the necessary changes to a file on your local

4 - Verify that the “git status” command shows the file that you have modified.

5 - To generate the patch, use the following command:
      
        git diff --no-prefix [file-name] > ./file-name.patch
 

drupal 8 how i create a custom form to programmatically created block and assign to it in variable in preprocess

Preprocess page assign a custom block to variables code

$customblock = \Drupal::service('plugin.manager.block')-  >createInstance('custom_block_id', []);

 $variables['home_meal_plan'] = $customblock->build(); 

*******************************************************************************

1 - Creating custom form

goto - custom_module\src\Form and create a customform.php

<?php

namespace Drupal\meal_plan\Form;

use Drupal\Core\Form\FormBase;

use Drupal\Core\Form\FormStateInterface;

use Symfony\Component\HttpFoundation\RedirectResponse;

use Drupal\cms_pages\Controller\CommonFunc;

/**

 * Provides meal plan form.

 *

 * @internal

 */

class HomeMealForm extends FormBase {

  /**

   * {@inheritdoc}

   */

  public function getFormId() {

    return 'home_meal_form';

  }

  /**

   * {@inheritdoc}

   */

  public function buildForm(array $form, FormStateInterface $form_state) {

    global $base_url;

    $hindi = CommonFunc::isHindi();

    if (\Drupal::currentUser()->isAnonymous()) {

      $footer_content = CommonFunc::getCmsContent('field_meal_plan_footer_content');

      $meal_plan_heading = CommonFunc::getCmsContent('field_meal_plan_heading');

        $form['age'] = [

          '#type' => 'textfield',

  '#attributes' => array('class' => array('inptFld'), 'id' => array('home-meal-age') ,'autocomplete' => array('off')),

          '#default_value' => '',

          '#placeholder' => 'Eg. 7',

          '#required' =>TRUE

        ];

      $query = \Drupal::entityQuery('taxonomy_term');

      $query->condition('vid', 'food_type');

      $query->sort('name');

      $tids = $query->execute();

      $options = [];

      $options = [

    'Vegan' => t('Vegan'),

        'Veg' => t('Veg'),

'Eggetarian' => t('Eggetarian'),

'Pescatarian' => t('Pescatarian'),

        'Nonveg' => t('Non-Veg'),

      ];

  $options1 = [

    '2-12' => t('2-12'),

        '13-17' => t('13-17'),

'18-25' => t('18-25'),

'25-50' => t('25-50'),

      ];


      $form['food_type'] = [

        '#type' => 'radios',

        '#options' => $options,

        '#default_value' => 'Vegan',

        '#required' => TRUE,

      ];

  

  $form['age_range'] = [

        '#type' => 'radios',

        '#options' => $options1,

        '#default_value' => '2-12',

        '#required' => TRUE,

      ];  

      $form['footer_content'] =[

        '#markup' => $footer_content,

      ];

      $form['submit'] = [

        '#type' => 'submit',

        '#value' => t("Apply"),

'#attributes' => array('class' => array('primary-button hvr-ripple-out')),

        '#validate' => ['::submitValidateMeal'],

      ];

      $form['#theme'] = 'HomeMealForm';

      $form['#meal_plan_heading'] = $meal_plan_heading;

      $form['#attached']['library'][] = 'meal_plan/meal_style';

      return $form;

    }

  }

  /**

   * {@inheritdoc}

   */

  public function submitValidateMeal(array &$form, FormStateInterface $form_state) {

    if ($form_state->getValue('age') == '') {

        $form_state->setErrorByName('age', 'Please select date of birth');

    } 

    elseif ($form_state->getValue('age') < 1) {

      $form_state->setErrorByName('age', 'Minimum required age is 1 year.');

    } 

    elseif ($form_state->getValue('age') > 12) {

      $form_state->setErrorByName('age', 'The recommendations are for healthy children between 1 year to 12 years of age. Please enter appropriate age.');

    }

  }

  /**

   * {@inheritdoc}

   */

  public function submitForm(array &$form, FormStateInterface $form_state) {

    global $base_url;

    $age = $form_state->getValue('age');

    $food_type = $form_state->getValue('food_type');

   $age_range = $form_state->getValue('age_range');

    $meal_data = ['age' => $age, 'food_preference' => $food_type];

    $session = \Drupal::request()->getSession();

    $session->set('meal_data', $meal_data);

    $form_state->setRedirect('meal_plan.unreg_routine');

  }

}

2- creating a custom block

Goto - custom_module\src\Plugin\Block

create a php file customblock.php

<?php

namespace Drupal\meal_plan\Plugin\Block;

use Drupal\Core\Block\BlockBase;

/**
 * @Block(
 *   id = "home_custom_meal_form_block",
 *   admin_label = @Translation("Custom Meal Plan Block"),
 *   category = @Translation("Custom Meal Plan Block")
 * )
 */
 
class customblock extends BlockBase {
  /**
   * {@inheritdoc}
   */
  public function build() {
    $form = \Drupal::formBuilder()->getForm('Drupal\meal_plan\Form\HomeMealForm');
    return $form;

  }
}

3- assign custom create Block to a variable in preprocess : in theme.theme file

/**

 * Implements hook_preprocess().

 */

function theme_new_preprocess(array &$variables, $hook) {

$variables['base_path'] = base_path();

$variables['is_front'] = \Drupal::service('path.matcher')->isFrontPage();

$current_path = \Drupal::service('path.current')->getPath();

$variables['current_path'] = $current_path;

$alised_path = \Drupal::service('path_alias.manager')->getAliasByPath($current_path);

$alised_path = ltrim($alised_path, '/');

$variables['alised_path'] = $alised_path;

$current_url = explode("/", $alised_path);

if($variables['is_front']) {

$customblock = \Drupal::service('plugin.manager.block')->createInstance('home_custom_meal_form_block', []);

        $variables['home_meal_plan'] = $customblock->build();

}

}


Write a program in PHP to reverse a number

A number can be written in reverse order. For example 12345 = 54321 <?php   $ num = 23456;   $ revnum = 0;   while ($ num > 1)   {   $...