2

In content type = Person, I have these fields:
- First Name [node:field_person_first_name]
- Middle Name [node:field_person_middle_name]
- Last Name [node:field_person_last_name]
- Suffix [node:field_person_suffix]

In views, I have successfully concatenated the full name by adding Global: Custom text and using Replacement Patterns to build the fields. However, this is time consuming.

These fields will always be put together in both of these two ways:
- full name, last first
- full name, first first

Is there a way that I can create two computed fields for these which I could store in the content type? If so, how do I do this? Note: I don't want to modify the original data.

Update:
I have Entity Token and Token already. I loaded Token Filter. I found, but have not yet loaded Token Field.

Token Field suggests that it might be nice if one could define a field "without needing to know any PHP" but the samples on this page indicate otherwise. My HTML knowledge is slight and PHP is non-existent.

I did follow a training video which gave me access to some tokens when creating a new field in Person, but these did not include tokens for fields within the Person content type.

Will this be possible (without PHP) if I install Token Field?

Update 2:
The site simplytest.me is excellent. Token Field loaded. Unfortunately in a real test, I'm getting "Cath [node:field_person_middle_name] Staincliffe [node:field_person_suffix]" because author Cath Staincliffe doesn't have a middle name or suffix. Do you know how to instruct the module to only use a name if one exists?

1 Answer 1

2

The Concat Field module looks like it can do what you want. From the README:

This module provides a new field type that allows you to select other fields from that content type (or any bundle), and it will concatenate their display values into a single field on save.

The example use case is then using the field as an exposed filter in a View.

Or you can write some code to do it via a custom module that calls the hook_node_presave function. In your content type definition, create the fields you want, and set their display type to Hidden. Then, in your function, set the values. See the answer to this question for more info:

How to use hook_node_presave to change field's value

Edit:

While it looks useful at first glance, the Concat Field module is very limited. You can't change the order of the fields, and it requires patches in order to generate any kind of output.

Another option would be to use the Token Field module. With this module, you can create a field into which you can enter tokens. This will give you a lot more flexibility - you can place the fields in whatever order you want, and specify punctuation or other characters around them.

2nd edit to answer updated question

Token Field suggests that it might be nice if one could define a field "without needing to know any PHP" but the samples on this page indicate otherwise.

My interpretation of the Token Field page is you only need to know PHP if you want to use conditional tokens, and that's what the sample code illustrates.

Will this be possible (without PHP) if I install Token Field?

In theory, yes, but the only way to know for sure is to try it. If you're worried about compromising your site or database, install Token Field on simplytest.me and set up your content type there.

12
  • This looks like a great module, I'll take a look. Need to keep away from the code myself. Thanks.
    – TdeV
    Apr 29, 2016 at 17:25
  • 1
    Don't rush to revert to your last backup if it will cause you to lose time or data. It looks like the Concat Field module simply creates a field, and doesn't modify other fields. More than likely, you can delete the field(s) created by the module without affecting anything else but if you are nervous about it, leave them be and ignore them.
    – Frank H.
    Apr 29, 2016 at 23:50
  • 1
    Replacement patterns are more limited. The available patterns depend on the fields you are using in your view, there are limitations as to the order in which they can be used, and they are only useful when your view is showing fields. Tokens, when used with the Token Field module, are available in other view formats such as tables and Display Suite, and they allow you to store concatenated fields in your content type.
    – Frank H.
    May 5, 2016 at 16:41
  • 1
    Changing the goalposts like this doesn't exactly fit the StackExchange model :-) but just to quickly answer... I don't think it's possible to hide empty tokens without resorting to code, which you've said is not an option for you. Replacement patterns in the view might work better in this instance because you can hide empty fields. Alternatively, rethink your data model: is it really necessary to display the middle name and suffix?
    – Frank H.
    May 7, 2016 at 13:12
  • 1
    My questions are still in search of an answer for my original question ;) but I'll take it that the answer, in the end, is "No". Thanks for all your efforts.
    – TdeV
    May 7, 2016 at 15:08

Your Answer

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

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