3

I'm using Drupal 7 and have created a content type called abc. In abc there is a field called seller. When a logged in user creates a new piece of abc content, the value of the seller field would be the name of the person who is logged in.

So what I want is a default value for the seller field for a small piece of PHP code. But I am not able to find the place to enter this PHP. In Drupal 6 there is text area for the php code to enter, how can this be done with Drupal 7.

6
  • May I ask why would you use custom CCK field instead of default “Authored by” field available out of the box?
    – P4tient
    Commented Jun 21, 2011 at 12:23
  • Ya there is an option for author name. But how do I set this value as default for the seller field. The seller would be the person who is currently logged in. Commented Jun 21, 2011 at 13:34
  • I'm just curious what's the reason for storing duplicate field within database?
    – P4tient
    Commented Jun 21, 2011 at 13:40
  • I will explain to you my whole scenario. Iam developing a advertise site, In which any authenicated user can advertise about his item.For this I have created a content type named Advertise. In the advertise add form I have fields item name, description, price and address field. But when I show the items in view page I need there sellers name also. The sellers name would be the name of the person who has advertise for that item.So thats why I need sellers name as a default name in the field. Because I have sellers field in my content type but its not visible to the end users in the form. Commented Jun 22, 2011 at 4:02
  • So you need new cck field which always takes value of default author field. And then you wanted to display it within separate Views field, right? But isn't it's easier to display default author field? Everything you need to do that is to add Content: Author relationship and then the field The user or author name will be available.
    – P4tient
    Commented Jun 22, 2011 at 5:30

3 Answers 3

2

I don't know if there is an UI for it, but fields allows either an array as allowed values or an callback.

This means that you most likely will need to create a function in a module instead of hardcoding the php which then would be saved in the database. IMO this is a good thing.

In your field config array you want something like this:

....
'settings' => array(
    'allowed_values' => array(),
    'allowed_values_function' => 'callback_function',
),
...

If you are new to this, take a look at field_create_field and field_update_field.

2
  • I will explain to you my whole scenario. Iam developing a advertise site, In which any authenicated user can advertise about his item.For this I have created a content type named Advertise. In the advertise add form I have fields item name, description, price and address field. But when I show the items in view page I need there sellers name also. The sellers name would be the name of the person who has advertise for that item.So thats why I need sellers name as a default name in the field. Because I have sellers field in my content type but its not visible to the end users in the form. Commented Jun 22, 2011 at 4:06
  • @samir so the above method should work fine.
    – googletorp
    Commented Jun 22, 2011 at 5:47
1

I'm using User reference field to properly describe content made by few authors. It can be multi value, node author is only one out of the box. So if You have big article performed by few people user reference field is reasonable solution.


Sometimes User reference field is also needed, when you have real author of content and operator (person, who is posting content) and you need to know, who posted and when. If author is always operator, there is no need to use user reference field, because reference is already within Drupal core author stored.

0

If the content of this Field is the same as the Author of the Node, there is no need to make a seperate field.

Instead, you should add the already available Node:Author field to your View.

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.