Frage

Okay lets say I have a basic demographic content type (Client) that I am saving as a node.

I need to make a key for an external database that we occasionally need to work with.

I want Drupal to take the fragments of three fields being collected in the Client content type and join them into a single field to be saved within the Client content type. Ideally this should be done when I create a new (Client) node.

The new field should contain the following First 3 letters of firstname First 3 letters of lastname and last 4 digits of Social Security Number.

For example
firstname: John
lastname: Doe
SSN: 123-45-6789

A new field should be created, let’s call it fk_database. Using the example above the field >created would be -> johdoe6789

Can this be done via Rules module, or should I approach this in a different way? If I need to do this via a PHP script where exactly should that be added in the Drupal structure?

War es hilfreich?

Lösung

The easiest way would probably be to use the Computed Field module, it's pretty much built for exactly what you want to do:

Computed Field is a very powerful CCK field module that lets you add a custom "computed fields" to your content types. These computed fields are populated with values that you define via PHP code. You may draw on anything available to Drupal, including other fields, the current user, database tables, you name it.

If you do need to do it in code though, have a look into hook_entity_presave() which would probably be the best place to run your code from.

Andere Tipps

I personally would build a custom module to handle this and make use of the node API to handle the custom fields if you want to build them on the fly?

Modules could be created either in the modules directory on the 'root' or really they should be in sites > all > modules

You'll have to switch it on in the backend under site building > modules to enable it

You will be able to hook into the API and handle requests via the case statements e.g.

function hook_node_load($node, $types) {
    //do something on node load
}

function hook_node_update($node) {
    //do something on node update
}

function hook_node_insert($node) {
    //do something on node insert
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top