by Subhojit Paul

D8 Training - Site-building and module development

Hello World module

  • Append "hello world" text to node content

hello_world.info.yml file

name: 'Hello world'
description: 'Hello World Drupal 8'
type: module
core: 8.x

hello_world.module file

<?php

/**
 * @file
 * Implements hello_world module.
 */

use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;

/**
 * Implements hook_node_view_alter().
 */
function hello_world_node_view_alter(&$build, $node, $display, $view_mode, $langcode) {
  if ($node->getType() == 'article') {
    $build['hello_world_new_content'] = array(
      '#markup' => t('Hello World!'),
    );
  }
}
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;

Classes imported

function hello_world_node_view_alter(&$build, $node, $display, $view_mode, $langcode) {
 // My code.
}
Drupal\Core\Entity\EntityInterface
Drupal\Core\Entity\Display\EntityViewDisplayInterface

Want to know more?

We want a DEMO!

Check out more!!

Thank You!!

subhojitpaul21@gmail.com

Drupal 8 training

By Subhojit Paul

Drupal 8 training

  • 453