logo

Blog

22 June

Return error on Zoom API with custom_questions in Drupal 8
By: alam | Published On: Tue, 06/22/2021 - 13:28

Prob:


in Drupal 8 I have created custom code to post data in Zoom using ZOOM API.

I have added custom question in Zoom Dashboard as below

custom question ZOOM


Zoom API was working but when I added a custom question in Event then is showing an error as below…

12 June

Essential Modules in Drupal 8
By: alam | Published On: Sat, 06/12/2021 - 11:14

Pathauto

The Pathauto module automatically generates URL/path aliases for various kinds of content (nodes, taxonomy terms, users)

Requirements Token CTools

View Detail

8.x-1.8 Released 28 April 2020

ctools

ctools (Chaos Tool Suite (ctools))

Tools to make it easy for modules to let other modules

3 June

Render Field Variable In Node Twig Template (Node.html.twig) Drupal 8
By: alam | Published On: Thu, 06/03/2021 - 19:19

Render Field Variable In Node Twig Template (Node.html.twig) Drupal 8

Show Node Created Date

If you want to show node created date on template you can use code as below

{{ node.getCreatedTime|date("d/m/Y")}}

You change date format as your requirement

Show Term Reference Field

To display reference term name the you can use code as below

{{ node.field_company_name.entity.name.value}}

In example "company_name" is term…

28 May

Select Query to get users of empty fields
By: alam | Published On: Fri, 05/28/2021 - 23:30

Select those users which name (Custom field) is empty

In the following I have created a custom field (name) in user profile, field machine name as field_name

I want get user list where name field is blank

 

$uids = \Drupal::entityQuery('user')
    ->condition('field_name', NULL, 'IS NULL')
    ->execute();
echo count($uids);

If you want to get more user through user id

foreach($uids as $uid){
	$users = User::load($uid);
	$…
				  

26 May

How to create or manage configuration form in Drupal 8
By: alam | Published On: Wed, 05/26/2021 - 19:16

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.

I have created form "MyConfigurationForm.php" in folder src/Form

_permission: 'mymodule dashboard_admin' command is used to set permission for the rout path, We create a separate file  name "mymodule.permissions.yml"  where permission related code will be appear on URL based 

 

mymodule.…
				  

30 April

Add External CSS in Drupal 8
By: admin | Published On: Fri, 04/30/2021 - 11:15

How can add externalcss in Drupal 8 ?

Post following format in libraries.yml, for example my theme name is customtheme so the file will be 'customtheme.libraries.yml'  in theme folder

css:
    theme:
      'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css': { type: external, minified: true }
      'https://fonts.googleapis.com/css2?family=Noto+Sans:ital,[email protected],400;0,700;1,400;1,700&display=swap': { type: external, minified:…
				  

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…
				  

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

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…

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. Whole page template for views page.

  1. Create copy of page.tpl.twig
  2. If your views url is ‘news-and-articles’ then rename file as ‘page--news_and_articles.html.twig’ and upload in your themes folder. If url has dash then replace dash with underscore.

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

22 April

Online Reputation Management
By: admin | Published On: Wed, 04/22/2020 - 22:13

Online popularity control known as Online Reputation Management Company too is a key to success in online company. Why so? It is because it removes possibility for your company to earn bad name on the world wide web and increases your good picture through advertising good material relevant to your company. Under online popularity control assistance, everything published on the world wide web about you is considerably supervised. Content which contain harmful pieces of details are hidden on…

22 April

Set up Google plus login process Drupal 7
By: admin | Published On: Wed, 04/22/2020 - 22:13

Pre-requisites: Google Developer Account Go to developers.google.com Open the api console From the drop down menu in the top left: Select Create Give the project a name Press Create Project The Project will be created and set to active Select API Access from the left menu Click the button marked Create an oauth 2.0 client ID Give the product a name and logo (whatever you want here) Select web application enter your site address click create client id You will need to edit settings here once…

22 April

How to design OMR Sheets using the OMR Software?
By: admin | Published On: Wed, 04/22/2020 - 22:13

With the advancement of science and technology, the OMR industry too has experienced a major enhancement of the provided features. The traditionally developed OMR software was just used to read the OMR sheets that would be contributing to the effective checking and calculation of final scorecards. The user can conduct exams on a specific pattern of OMR sheets only.
Now, with the modification to the OMR software the user can easily design a vivid range of OMR sheets. OMR sheet scanning…

22 April

Get installed a POS system to improve the business and manage accurately
By: admin | Published On: Wed, 04/22/2020 - 22:13

A small store to a large retail store is advisable to use Point of Service systems to easily customize their routine operations. It increases productivity, business, revenue, relationship with customers, and also saves time efficiently. Free POS applications can be used in simple business procedures using existing tools where advanced system is not affordable. POS is connected with multiple computers, printers, scanners at the administrator, sales counter, and many more locations. If…

22 April

CKEditor automatically strips classes from div in Drupal
By: admin | Published On: Wed, 04/22/2020 - 22:13


Using CKEditor as a back end editor on my website. It is driving me round the bend though as it seems to want to change the code to how it sees fit whenever I press the source button.

Soln 1.
Follow this given step to resolve this issue.
Go to "Admin >> Configuration >> CKEditor"; under Profiles, choose your profile (e.g. Full).
Edit that profile, and on "Advanced Options >> Custom JavaScript configuration" add config.…

22 April

Can't save or submit anything after enable Boost in Drupal 7
By: admin | Published On: Wed, 04/22/2020 - 22:13

I got the problem. After enabled and configured Boost, I cant change any single setting on the site, nothing gets saved. When hitting "Save" button on node edit form or any other submit form, the page just gets reloaded submit not working.

Solution.

This problem occurs only in the dev-version or Version 1.1. Version 1.0 is working well.

1. First install version 1.0 of the module. Activate that module. Go to admin/config/system/boost/htaccess/generator and take…

22 April

Cache exclusion in Drupal - Disable cache for certain pages or template
By: admin | Published On: Wed, 04/22/2020 - 22:13

These below code you can put on your template pages, you can apply condition according to requirement so so caching will exclude for those pages where apply this code.

$GLOBALS['conf']['cache'] = FALSE;
$GLOBALS['do_not_cache'] = 1;

We can use CacheExclude module to manage caching for perticular page or condition https://www.drupal.org/project/cacheexclude

22 April

How to access field value for a node in Drupal 8
By: admin | Published On: Wed, 04/22/2020 - 22:13

Use this code at the top of your coding

use Drupal\node\Entity\Node		//Working with nodes Load a node by NID:
	$nid = 123;     // example value

Method 1

	$node_storage = \Drupal::entityTypeManager()->getStorage('node');
	$node = $node_storage->load($nid);

Method 2

$node = \Drupal\node\Entity\Node::load($nid);

Get node's NID:

echo $node->id();  // 123Get node's bundle type:

	echo $node->bundle…
				  

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');
  }

}

22 April

User related methods in DRUPAL 8
By: admin | Published On: Wed, 04/22/2020 - 22:13

Get user role of current loggedin user

$user_roles = \Drupal::currentUser()->getRoles();

Get user detail of curent loggedin user

$user = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id());
user_delete(uid);

$user_roles = \Drupal::currentUser()->getRoles();
$user = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id());
$uid = $user->get('uid')->value;	

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…
				  

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.

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

22 April

Redirect Method in DRUPAL8
By: admin | Published On: Wed, 04/22/2020 - 22:13

Method to redirect on node id url

$url = Url::fromRoute('entity.node.canonical', ['node' => $nid]);
$form_state->setRedirectUrl($url);

Method to redirect on custom url

$url = Url::fromRoute('olsys.mycustom_dashboard');
$form_state->setRedirectUrl($url);

Redirect on user view page of loggedin user

use Drupal\Core\Controller\ControllerBase; // Use this on top
return $this->redirect('user.page');	// use this as your code 

$url = \Drupal\…
				  

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

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

22 April

Apply coupon to Regular Price in Woocommerce
By: admin | Published On: Wed, 04/22/2020 - 22:13

When we apply coupon for discount its applied for sale price by default but we need to apply discount coupon on regular price so you can use this code on function.php By default cart and product show sale price after applying this code Regular price will be update on cart.

add_action( 'woocommerce_before_calculate_totals', 'add_custom_price', 10, 1);
function add_custom_price( $cart_object) {

    global $woocommerce;

    if ( is_admin()…
				  

22 April

How to add condition in views with custom field in DRUPAL 8
By: admin | Published On: Wed, 04/22/2020 - 22:13

If you want to add if condition in my "global custom text" field in views Drupal 8

Example 1: Check node status and put conditional link according to publish status

{% if  status  %}
   put your HTML as condition
{% endif %}

Example 2: In this example we are checking a field value is empty or not. according to value in we are showing link or status

{% if  field_final_layout_date is empty %}

put your HTML as condition

{% else…
				  

22 April

How to form alter of node page in DRUPAL 8
By: admin | Published On: Wed, 04/22/2020 - 22:13

I want to change select list value in my state field so we follow the step My content type is 'project' so we can get the form id as 'node_project_form' I have a feild 'state' in my content type so field machine name is 'field_state'

function MODULENAME_form_alter(&$form, FormStateInterface $form_state, $form_id) {
	$dropdown_array = array('DL'=>'Delhi');
	if ($form_id == 'node_project_form') {
		$form['field_state']['widget'] = array(     
		 '#type' => 'select',
		 '#…
				  

22 April

When I want to installed Views Data Export module to export CSV then we getting error as "CSV Serialization requires the League\Csv library"
We follow this step then I have installed module
1. Install module "Ludwig" module
2. open this path "/admin/reports/packages" that will show missing library then you can download that library.
3 Upload required library in given location
4. Unzip that files and upload their all files and…

22 April

Get user list by role programmatically in Drupal8
By: admin | Published On: Wed, 04/22/2020 - 22:13

User this code before

use Drupal\user\Entity\User;

Thise code will be return user list of a given role (editor)

	$ids = \Drupal::entityQuery('user')
	->condition('status', 1)
	->condition('roles', 'editor')
	->execute();
	$users = User::loadMultiple($ids);
	foreach($users as $user){
		$username = $user->get('name')->value;
		$uid = $user->get('uid')->value;
		$userlist[$uid] = $username;
	}
				  

21 April

Custom code to add meta tag in Drupal 7
By: admin | Published On: Tue, 04/21/2020 - 23:45

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'); 
	} 
 }
 

21 April

Redirect Method in DRUPAL8
By: admin | Published On: Tue, 04/21/2020 - 23:44

Method to redirect on node id url

$url = Url::fromRoute('entity.node.canonical', ['node' => $nid]); $form_state->setRedirectUrl($url);

Method to redirect on custom url

$url = Url::fromRoute('olsys.mycustom_dashboard'); $form_state->setRedirectUrl($url);

Redirect on user view page of loggedin user

use Drupal\Core\Controller\ControllerBase; // Use this on top return $this->redirect('user.page'); // use this as your code