logo

Blog

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:

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.

Create a custom_login.info.yml file in your module directory with the following…

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 the @variable syntax.

The $value_to_save variable…

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 as their username (user.name),…

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 example of how you might use this in a Drupal 8 Twig…

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.

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…