Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Answer for Drupal Stackexchange #204841

So this is the hook for node view later.

function hook_node_view_alter(&$build) {
 // Code
}

To use that hook...

/**
 * Implements hook_node_view_alter().
 */
function my_module_node_view_alter(&$build) {
 // Example of how to create a variable.
 $vid = $build['body']['#object']['vid’];
 // Create a placeholder for original vid value.
 $build['body']['#object']['original_vid'] = $vid;
 // Reset the value of vid.
 $build['body']['#object']['vid’] = NEW_VALUE;
}
@toptomatotwo

This comment has been minimized.

Copy link

toptomatotwo commented Jun 25, 2016

thanks for answering my post. i trying to hard w/ this theming stuff but it's not easy.

see the screen snaps here. that generates an error
code
error
dpm

in this example i'm hacking bartik core theme i know that's not best practice but this is sandbox site

@toptomatotwo

This comment has been minimized.

Copy link

toptomatotwo commented Jun 25, 2016

so tell me, how well do you know Drupal?

there are no Drupal meet ups where i live unfortunately. going it alone!

@geraldvillorente

This comment has been minimized.

Copy link
Owner Author

geraldvillorente commented Jun 25, 2016

@toptomatotwo my example is wrong since the parent of vid is object. That said it should be

/**
 * Implements hook_node_view_alter().
 */
function my_module_node_view_alter(&$build) {
 // Example of how to create a variable.
 $vid = $build['body']['#object']->vid;
 // Create a placeholder for original vid value.
 $build['body']['#object']->original_vid = $vid;
 // Reset the value of vid.
 $build['body']['#object']->vid = NEW_VALUE;
}
@geraldvillorente

This comment has been minimized.

Copy link
Owner Author

geraldvillorente commented Jun 25, 2016

@toptomatotwo its very challenging to learn alone. Fortunately, there are plenty of medium you can use such as Drupal Stackexchange, Drupal forum, Github, and IRC. You can invite some people to have a Google hangout if you want. I am happy to participate in a virtual discussion to learn and help.

@toptomatotwo

This comment has been minimized.

Copy link

toptomatotwo commented Jun 25, 2016

Yes! that's it, thank you!
i had tried something like that earlier but not exactly. something like
$myVar = $build['body']['#object']->'vid';

honestly since starting Drupal 2 years ago my PHP hand coding has gotten worse since all the work i've done is within the admin almost,

i'm forgetting OOP PHP!

i'm now starting to work on making modules too.

where are you located? thanks for the help, maybe we can stay in touch

@geraldvillorente

This comment has been minimized.

Copy link
Owner Author

geraldvillorente commented Jul 19, 2016

@toptomatotwo I am here in Manila, Philippines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.