Closed (fixed)
Project:
Automatic Nodetitles
Version:
5.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
9 Mar 2007 at 08:18 UTC
Updated:
21 Apr 2007 at 15:32 UTC
I just can't find the right magic to set my node-title with php-code using the data in the other cck-fields of my node.
Could you please post a simple sample, I need something really urgent.
Thank you.
Comments
Comment #1
fagoI've never tried getting the node data with some php code.
Related issue: http://drupal.org/node/121216
However, I think you could get the global $form_values, which should do it in most cases. However, these are "raw form data" and not processed in any way.
I'll suggest you use the token module instead.. For sure it's the easier way.
Comment #2
ray007 commentedUsing the token-module is definitely easier for the simple things you can do with it.
But, if I want different title-setting depending on some input-values, I need to use php-control structures ("if" and/or "switch" statement), and so far I haven't found a way to combine those with tokens ...
Comment #3
fagohm, yes that would be a nice feature. However I see currently no way for it, for this I would need a not existing option for the token module, which allows to replace the values without any tags..
So for now, that's not possible.
So yes, you would need php..
try something like that: (untested)
Comment #4
ray007 commentedThank a lot, that got me almost to where I want to be.
Question: do you invoke the php-code at a different time than the token replacement?
The reason I ask is that content_format(...) on a date field brings me back to the old problem of returning "January 1. 2007" while that's already working now when using the token module ...
Is it possible to call this php-code in a context with variables according to the possible cck-fields in this node-type available?
Comment #5
fagono, it gets called exactly at the same time. First the tokens are replaced then the php code is evaled. Have a look at _auto_nodetitle_patternprocessor() if you are interested.
It would be great if you could share a working example with us!
Comment #6
ray007 commentedI still think a context providing the variables would make life easier, but I got it working now:
Depending on the value of field_heimspiel (integer - checkbox), the home-team or the visitor-team is printed first in the title, followed by the date (field_datum_0) the match is to be played on.
Instead of evaluating 'field_gegner' myself I could also have changed context to html and printed the token:
You only have to take care the place of the token could be replaced by a php print-statement.
Getting the right incantation
$node['field_heimspiel']['keys'];took me some print_r(...) debugging since the devel-module shows different properties for then node there, but otherwise it's quite straight-forward since you can use the tokens outside of php-context.Comment #7
moshe weitzman commentedfago said: "First the tokens are replaced then the php code is evaled"
thats what i expected, but the code does it backwards. see _auto_nodetitle_patternprocessor()
Comment #8
fagoah, damn of course, I've changed that some time ago, sry. (commit )
So now: php is evaled, then tokens are replaced.
so there is still no bug in the module..
Comment #9
fagoI've just changed the execution order again: Now first tokens are replaced then php is evaluated, and then tags are stripped. This enables one to combine token replacement with php evaluation.
I've put an example for this into the README and also I've added a note how to get $node...
Comment #10
(not verified) commented