Skip to main content
changed the question back to its original revision
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

I'm trying to show a message for specific content type through a new module, on Drupal 8.3.0. (I'm a beginner.)

This is part of the code I am using.

File test_module.module (updated code, still not working)

/**
 * @file
 * Implementation of hook_node_view();
 */

function test_module_node_view($node, $view_mode) {
  if ($view_mode == 'full' && $node->getType()>type == 'test_content') {
      /*Message with current date and time*/
      $current_time = time();
      drupal_set_message(t('Hello! Today is '.format_date($current_time,'medium')));
    }
  }

As far as I know, this should work, but it doesn't and I don't know why. The message is not showing for a node of content type "test_content". How can I fix this? Is there another way to alter nodes of custom content types?

screenshot

screenshot

(Test_content_example is a node of type 'test_content', so there should be a system message displayed, but there's none.)

I'm trying to show a message for specific content type through a new module, on Drupal 8.3.0. (I'm a beginner.)

This is part of the code I am using.

File test_module.module (updated code, still not working)

/**
 * @file
 * Implementation of hook_node_view();
 */

function test_module_node_view($node, $view_mode) {
  if ($view_mode == 'full' && $node->getType() == 'test_content') {
      /*Message with current date and time*/
      $current_time = time();
      drupal_set_message(t('Hello! Today is '.format_date($current_time,'medium')));
    }
  }

As far as I know, this should work, but it doesn't and I don't know why. The message is not showing for a node of content type "test_content". How can I fix this? Is there another way to alter nodes of custom content types?

screenshot

screenshot

(Test_content_example is a node of type 'test_content', so there should be a system message displayed, but there's none.)

I'm trying to show a message for specific content type through a new module, on Drupal 8.3.0. (I'm a beginner.)

This is part of the code I am using.

File test_module.module (updated code, still not working)

/**
 * @file
 * Implementation of hook_node_view();
 */

function test_module_node_view($node, $view_mode) {
  if ($view_mode == 'full' && $node->type == 'test_content') {
      /*Message with current date and time*/
      $current_time = time();
      drupal_set_message(t('Hello! Today is '.format_date($current_time,'medium')));
    }
  }

As far as I know, this should work, but it doesn't and I don't know why. The message is not showing for a node of content type "test_content". How can I fix this? Is there another way to alter nodes of custom content types?

screenshot

screenshot

(Test_content_example is a node of type 'test_content', so there should be a system message displayed, but there's none.)

improved formatting
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

[Drupal 8.3.0] I'm trying to show a message for specific content type through a new module, on Drupal 8.3.0. (I'm a beginner). To illustrate, here's a piece)

This is part of the code I haveam using.

File test_module.module (updated code, still not working):

File test_module.module (updated code, still not working)

<?php

/**
 * @file
 * Implementation of hook_node_view();
 */

function test_module_node_view($node, $view_mode) {
 
  if ($view_mode == 'full' && $node->getType() == 'test_content') {
 
      /*Message with current date and time*/
      $current_time = time();
      drupal_set_message(t('Hello! Today is '.format_date($current_time,'medium')));
    }
  }

As far as I know, this should work, but it doesn't and I don't know why. The message is not showing for a node of content type "test_content". How can I fix this? Is there another way to alter nodes of custom content types?


 

screenshot

screenshot

[Update - some screenshots] enter image description here enter image description here (Test_content_example is a node of type 'test_content', so there should be a system message displayed, but there's none.)

[Drupal 8.3.0] I'm trying to show a message for specific content type through a new module (I'm a beginner). To illustrate, here's a piece of code I have.

File test_module.module (updated code, still not working):

<?php

/**
 * @file
 * Implementation of hook_node_view();
 */

function test_module_node_view($node, $view_mode) {
 
  if ($view_mode == 'full' && $node->getType() == 'test_content') {
 
      /*Message with current date and time*/
      $current_time = time();
      drupal_set_message(t('Hello! Today is '.format_date($current_time,'medium')));
    }
  }

As far as I know, this should work, but it doesn't and I don't know why. The message is not showing for a node of content type "test_content". How can I fix this? Is there another way to alter nodes of custom content types?


 

[Update - some screenshots] enter image description here enter image description here (Test_content_example is a node of type 'test_content', so there should be a system message displayed, but there's none)

I'm trying to show a message for specific content type through a new module, on Drupal 8.3.0. (I'm a beginner.)

This is part of the code I am using.

File test_module.module (updated code, still not working)

/**
 * @file
 * Implementation of hook_node_view();
 */

function test_module_node_view($node, $view_mode) {
  if ($view_mode == 'full' && $node->getType() == 'test_content') {
      /*Message with current date and time*/
      $current_time = time();
      drupal_set_message(t('Hello! Today is '.format_date($current_time,'medium')));
    }
  }

As far as I know, this should work, but it doesn't and I don't know why. The message is not showing for a node of content type "test_content". How can I fix this? Is there another way to alter nodes of custom content types?

screenshot

screenshot

(Test_content_example is a node of type 'test_content', so there should be a system message displayed, but there's none.)

Updated code, added screenshots, still not working
Source Link

[Drupal 8.3.0] I'm trying to show a message for specific content type through a new module (I'm a beginner). To illustrate, here's a piece of code I have.

File test_module.module (updated code, still not working):

<?php

/**
 * @file
 * Implementation of hook_node_view();
 */

function test_module_node_view($node, $view_mode) {

  if ($view_mode == 'full' && $node->type>getType() == 'test_content') {

      /*Message with current date and time*/
      $current_time = time();
      drupal_set_message(t('Hello! Today is '.format_date($current_time,'medium')));
    }
  }

As far as I know, this should work, but it doesn't and I don't know why. The message is not showing for a node of content type "test_content". How can I fix this? Is there another way to alter nodes of custom content types?


[Update - some screenshots] enter image description here enter image description here (Test_content_example is a node of type 'test_content', so there should be a system message displayed, but there's none)

[Drupal 8.3.0] I'm trying to show a message for specific content type through a new module (I'm a beginner). To illustrate, here's a piece of code I have.

File test_module.module

<?php

/**
 * @file
 * Implementation of hook_node_view();
 */

function test_module_node_view($node, $view_mode) {

  if ($view_mode == 'full' && $node->type == 'test_content') {

      /*Message with current date and time*/
      $current_time = time();
      drupal_set_message(t('Hello! Today is '.format_date($current_time,'medium')));
    }
  }

As far as I know, this should work, but it doesn't and I don't know why. The message is not showing for a node of content type "test_content". How can I fix this? Is there another way to alter nodes of custom content types?

[Drupal 8.3.0] I'm trying to show a message for specific content type through a new module (I'm a beginner). To illustrate, here's a piece of code I have.

File test_module.module (updated code, still not working):

<?php

/**
 * @file
 * Implementation of hook_node_view();
 */

function test_module_node_view($node, $view_mode) {

  if ($view_mode == 'full' && $node->getType() == 'test_content') {

      /*Message with current date and time*/
      $current_time = time();
      drupal_set_message(t('Hello! Today is '.format_date($current_time,'medium')));
    }
  }

As far as I know, this should work, but it doesn't and I don't know why. The message is not showing for a node of content type "test_content". How can I fix this? Is there another way to alter nodes of custom content types?


[Update - some screenshots] enter image description here enter image description here (Test_content_example is a node of type 'test_content', so there should be a system message displayed, but there's none)

added 15 characters in body
Source Link
Loading
Edited code
Source Link
Loading
Source Link
Loading