logo

Blog

1 July

Page template for Content Type, Node ID

Published On: Thu, 07/01/2021 - 12:43

function mythemename_theme_suggestions_page_alter(array &$suggestions, array $variables) {
  // Get Request Object.
  $request = \Drupal::request();
  // If there is HTTP Exception..
  if ($exception = $request->attributes->get('exception')) {
    // Get the status code.
    $status_code = $exception->getStatusCode();
    if (in_array($status_code, array(401, 403, 404))) {
      $suggestions[] = 'page__' . $status_code;
    }
  }
  if ($node = \Drupal::routeMatch()->getParameter('node…
				  

28 June

Node field twig template multiple images/item

Published On: Mon, 06/28/2021 - 14:07

Node field twig template to display multiple images/item. We can theme/design each item for that field

I am using node template as follow,

node--mycontenttype.html.twig

For example my content type name is "banner" then template name as.

node--banner.html.twig

I added field as below and its display all images but Its not able to wrap each images with div so that you can add classes to create slider.

{{ content.field_gallery_images }} //…
				  

22 June

Return error on Zoom API with custom_questions in Drupal 8

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

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

"[code] => 300 [message] => The parameter is required in custom_questions: Referred By."

 

Soln: If you added a custom question then you have to pass their title and value in parameter,…

12 June

Essential Modules in Drupal 8

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

View Detail

Download Zip 8.x-3.6 Released 12 May 2021

Token

Provides additional tokens not supported by core (most notably fields),…

3 June

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

Display Title of node

{{ node.title.value }}

Print node url

{{ url }}

Show Term Reference Field

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

28 May

Select Query to get users of empty fields

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

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

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,wght@0,400;0,700;1,400;1,700&display=swap': { type: external, minified:…
				  

1 April

How to create or manage configuration form in Drupal 8

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

24 March

How can get client IP Address in Drupal 8

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