Skip to content

Instantly share code, notes, and snippets.

@geraldvillorente
Created June 24, 2016 05:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geraldvillorente/1f8bd3d3c603ea9b191831283d344809 to your computer and use it in GitHub Desktop.
Save geraldvillorente/1f8bd3d3c603ea9b191831283d344809 to your computer and use it in GitHub Desktop.
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
Copy link

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
Copy link

so tell me, how well do you know Drupal?

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

@geraldvillorente
Copy link
Author

@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
Copy link
Author

@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
Copy link

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
Copy link
Author

@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