Blog

blog-img

1 April

How to create or manage configuration form in Drupal 8
By: admin | Published On: Thu, 04/01/2021 - 18:15

How to create or manage configuration form in Drupal 8


Create configuration form

create path in routing.yml, here my module name is "mymodule" so I am using it, you can use your module name.

mymodule.Myfiguration:
  path: 'myconf'
  defaults:
    _form: '\Drupal\mymodule\Form\MyConfigurationForm'	// I have created form "MyConfigurationForm.php" 
    _title: 'My API Configuration'
  requirements:
    _permission: 'mymodule dashboard_admin'		// this is…
                        Read More...
                      
blog-img

24 March

How can get client IP Address in Drupal 8
By: admin | Published On: Wed, 03/24/2021 - 22:12

I want to know IP Address of my website so can who is visiting or I want to location where is website visited using IP address.

Soln,

Add this code at top like other header

use Symfony\Component\HttpFoundation;

Use this code to get IP Address

\Drupal::request()->getClientIp()
Read More...
blog-img

3 March

Install razorpay library using composer for payment gateway integration
By: admin | Published On: Wed, 03/03/2021 - 13:29

I was doing integrate razorpay payment gateway in Drupal 8 using custom code but we getting error like “Class 'Razorpay\Api\Api' not found” because razorpay library is not installed on server so follow this step to install using putty to run composer command.

putty to composer

In putty enter Server IP and port click on open

Then you… Read More...

blog-img

1 March

Page Template for Views Page
By: admin | Published On: Mon, 03/01/2021 - 12:13

If you want to create template for views page like page.tpl.twig so you follow these step.

  1. Create copy of page.tpl.twig
  2. If your views machine name is ‘myblog’ then rename file as ‘page--myblog’.html.twig’ and upload in your themes folder

After clear cache current template will work for this views instead of page.tpl.twig.

Read More...
blog-img

22 April

How to create user programatically in DRUPAL 8
By: admin | Published On: Wed, 04/22/2020 - 22:13
$language = \Drupal::languageManager()->getCurrentLanguage()->getId();
$user = \Drupal\user\Entity\User::create();

// Mandatory.
$user->setPassword('password');
$user->enforceIsNew();
$user->setEmail('email');
$user->setUsername('user_name');

// Optional.
$user->set('init', 'email');
$user->set('langcode', $language);
$user->set('preferred_langcode', $language);
$user->set('preferred_admin_langcode', $language);
$user->set('setting_name', 'setting_value');
$user->addRole('rid');
$user->…
                        Read More...
                      
blog-img

22 April

Query according to field condition in DRUPAL 8
By: admin | Published On: Wed, 04/22/2020 - 22:13

Code to query for getting node according to field condition in DRUPAL 8

$query = \Drupal::entityQuery('node')
  ->condition('status', NODE_PUBLISHED)
  ->condition('type', 'custom_type');
$and = $query->andConditionGroup();
$and->condition('custom_taxonomy', 2);
$query->condition($and);
$and = $query->andConditionGroup();
$and->condition('custom_taxonomy', 8);
$query->condition($and);
$result = $query->execute();
Read More...
blog-img

22 April

Set current date in custom form element in DRUPAL8
By: admin | Published On: Wed, 04/22/2020 - 22:13

Set current date in custom form element in DRUPAL8

Add this line at top

 use Drupal\Core\Datetime\DrupalDateTime; 

Add the following code to your form

function HOOK_form_alter(…
                        Read More...
                      
blog-img

22 April

How to add Captcha in Webform in Drupal 8
By: admin | Published On: Wed, 04/22/2020 - 22:13

If you have already created a webform then you can follow thi step
1. Open this url /admin/structure/webform (Structure -> Webform)
2. Click on "Build" in OPERATIONS column

3. Click on "+Add element" button, there will be seen a list form element

4. You can select Captcha from available list.

Read More...
blog-img

22 April

Programatically add content to webform DRUPAL
By: admin | Published On: Wed, 04/22/2020 - 22:13
global $user;
$nid = 4; //nid is the node id of your webform.

$node = node_load($nid); 

The values to save. Take case about array indexes! (see below)

$data = array(
    '1' => array('0' => $type),
    '2' => array('0' => $method),
    '5' => array('0' => $volume),
    '6' => array('0' => $comment),
    '7' => array('0' => $phone),
    '8' => array('0' => $length)
);

$submission = (object) array(
    'nid' => $nid,
    'uid…
                        Read More...
                      
blog-img

22 April

Custom code to add meta tag in Drupal 7
By: admin | Published On: Wed, 04/22/2020 - 22:13

In your theme's template.php file, you could add something like

/**
 * Implements hook_preprocess_html
 */
function THEME_NAME_preprocess_html(&$vars) {

  if (current_path() == 'my/custom/path') {
    $description = array(        
      '#type' => 'html_tag',
      '#tag' => 'meta',
      '#attributes' => array(
        'name' => 'description',
        'content' => 'here all description goes',
      )
    );
    drupal_add_html_head($description, 'description');
  }

}
Read More...