Drupal is a flexible, open-source content management system (CMS) for building complex websites and applications.

Create Node drupal 8 programmatically with image upload using custom module

As we know drupal 8 use symphony, so module structure of drupal 8 is change and workflow functionality of doing thing also change. we can make Drupal 7 module procedure oriented but in drupal 8 module needs to follow object oriented MVC architecture.

In this tutorail we learn how can we create the node programmatically in drupal 8 with image upload using custom module.

Let say module name is "nodecreator"

1) To Create a module we need a nodecreator.info.yml file

Print array or object in watchdog drupal 7

hey, For many purpose we have to print the array or object while making a custom modules or debuging any old module, we have to print the array or object to see the values are fine or not, drupal provide a way to see those using watchdog, But how we print array or object in watchdog function, Answer is below.

watchdog("any_word_you_like", '<pre>' . print_r( $your_object_variable, true) . '</pre>');

Now, execute your function or page whenever you right it.

Then go to - https://yourdomian/admin/reports/dblog

Send file as Email attachment using hook_mail_alter drupal 7 programmatically (example webform submit)

Hi guys,

In this tutorial we can see how we can send files as attachments in drupal 7 on webform submit using a hook_mail_alter 

1) For this we need Mime Mail module and webform module

2) Create a simple module and use hook_mail_alter like below, In my case "attach_web" is my module name

Render menu on page template in custom way Drupal 8

If you want to render the menu items in custom way in page or node twig template of drupal 8 then this article is for you :

 

At man place where you make the template in drupal theming you want to render your menu in different style, For example main menu at header shows in different style while in footer in different style, for that you need to code on twig template but you don't know much about twig the simply use this module called "simplify menu"

 

Render a drupal node d8 twig template

Render a Drupal node in drupal 8 twig template and module PHP code is a bit different from Drupal 7 because Drupal 8 uses Symfony and twig format, follow the step and you will available to render a node in Drupal 8 templates 

Step 1.

create hook_preprocess_page in your yourtheme.theme file 

and paste code (rename your theme name at the place of hook)

$nid = 130;
$entity_type = 'node';
$view_mode = 'teaser';

Render block and views block drupal 7 programmatically

This is article is for Drupal 7 to render block in templates and custom blocks using php codes

Actually there is very simple ways to render block pro-grammatically 

1) Module Invoke

$block = module_invoke('module_name', 'block_view', 'delta or machine name of block');
print render($block['content']);

Module invoke is most common way to render a block, above example is self explained or see the below example

How to Make a Simple Module with a Form and Menu Link Drupal 8

Hi guys, In this article we see how we can make custom form with a menu link in drupal 8. Some of criteria of creating is changed form drupal 7 but it is quiet to understand the new setup, so let's start

For this we need to create a custom module so create a folder and make info.yml file 

1) Create modulename.info.yml file

2) Create routing.yml file for menu link and define the form page

3) Create the src/form folder and under it create "CustomForm.php" that we define under our routing file.

Drupal 8 form Markup Element alternative

Hi Guys, today topic is markup element of form api drupal 8. As we know the form api is describe the how the actually it can we used under development process, but recetry I found that markup element is missing form drupal 8 form api, so what if we need to display custom html with custom form then we can use the alternative as i show below.

In Drupal 7 there is specfied element in form api for markup, many of you used this before 

Subscribe to Drupal