Skip to main content
2 of 4
edited title
Elin Y.
  • 7.4k
  • 1
  • 41
  • 65

Which hook to use to reorder multi-value field values before saving content

I have a multi-value field added to my content type. It is actually a field collection.

The users can add unlimited items to this field, and rearrange the items using Drupal's drag-and-drop utility.

However, I want to add some custom logic to the arrangement of field values according to the content.

Which hook should I use, to modify the arrangement of field values before the node saved into the database.

For example, I have the following structure:

My Content Type
|
|-- Field Collection Field // unlimited values
    |
    |-- Name // Text field
    |-- Surname // Text field
    |-- Company // Select list

Let's say a user created a content with the following values:

  • John - Doe - ACME
  • Jane - Doe - Ace
  • Bob - X - ACME
  • Fred - Something - Ace

I want to sort them with a custom logic in a hook, so that they are arranged like that:

  • Bob - X - ACME
  • John - Doe - ACME
  • Fred - Something - Ace
  • Jane - Doe - Ace

My question is NOT how to write the logic, BUT which hook to use to modify the arrangements so that I can put my function into it.

Elin Y.
  • 7.4k
  • 1
  • 41
  • 65