1

I would like to know how I can manually insert some PHP code inside a CCK node.

What I have is the following code for Drupal 6:

$output .= '<br>';
$mor = _pitch_detalle($cid, $previamente, $luego);
if (sizeof($mor) > 0) {
  $output .= theme('pitch', $mor);
}
return $output;

This code shows some information that changes from day to day, and each time the users view the page, the information changes. I want the user to see an unmodified version of that code, the same information that existed when the user created the page.

As the user cannot edit the page, I´m looking to insert a php snippet inside a CCK field that will remain unchanged. But that could lead to problems, so is there any way to do that in a safe way? Or maybe to insert code inside the template in other way?

4
  • I'm not sure if I understand your question. You want a CCK field to contain a certain value, and that value must not be changed after the node is saved. The code above returns the value for the CCK field - is that correct? Should the field be filled automatically? Nov 6, 2011 at 22:06
  • yes, is correct! Is there any way to do this? The output is some kind of programatic views, it´s some sort of view created using that code, and I need it to be pasted inside a node. If I simply paste it over the node it changes every time the values changes... THANKS!
    – Rosamunda
    Nov 8, 2011 at 3:09
  • 1
    Downvoted due to the last paragraph, because it's ambiguous and the way it's phrased could led other users down a dangerous path of "code in the database". Please remove or re-phrase, and I'll upvote instead.
    – Letharion
    Jan 7, 2012 at 11:05
  • Sorry about that. How about this way? I´ve rephrased it.
    – Rosamunda
    May 23, 2012 at 21:41

1 Answer 1

2

I haven't done this myself before, so I cannot give really detailed instructions. I think I would do something like this:

  • Create a CCK text field in the content type(s) of your choice
  • Create a custom module and implement hook_form_alter
  • In your form alter function:
    • Give your CCK text field a #disabled property and set it to true (this will grey out the field so it cannot be edited)
    • Check if the field is already populated; if not, set the #default_value to the return value of the code in your question

This means that when Drupal builds the form, your custom module will disable the CCK field and put your content in it if that has not been done before. Because we're just populating a form field, all Drupaly stuff like the 'Display Fields' page will keep working.

I hope that helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.