I am writing a module to convert serialized value stored in database by the Composed Field Module. The serialized value is like:

a:3:{i:1;s:14:"First Subfield";i:2;s:15:"Second Subfield";i:3;s:14:"Third Subfield";}

The PHP Unserialize value of above serialized data returns the following array:

print_r(unserialize('a:3:{i:1;s:14:"First Subfield";i:2;s:15:"Second Subfield";i:3;s:14:"Third Subfield";}'));
    [1] => First Subfield
    [2] => Second Subfield
    [3] => Third Subfield

I called the Module as composed_views

So far I have made few files like: composed_views.info, composed_views.module,

composed_views_handler_subfields.inc contains:

class composed_views_handler_subfields extends views_handler_field {
  * Render the unserialized value.
  public function render($values, $index) {
    $uns = unserialize($values) // $values = serialized data from database
    return $this->get_value($uns[$index]); // $index = array index of serialized data

In composed_views.views.inc

For eg: The table names are field_one, field_two
The data column are field_one-composed, field_two-composed respectively

  • I want to Query those tables
  • and send the serialized data to render function defined in composed_views_handler_subfields.inc file

So, far the structure is like this:

function composed_views_views_data() {
  $data['composed_views_table'] = array();
  // The actual code I am seeking help with
  return $data;

Any help how to do with this with views would be appreciated.

  • With views GUI or views API? Could you create entities from the data? drupal.org/project/entity
    – Christian
    Mar 23, 2014 at 11:03
  • With ViewsAPI, I cannot create entity from the data, as the reason of using composed_field is to define the field directly in the content type.
    – user12947
    Mar 25, 2014 at 11:01

2 Answers 2


There is some discussion in several places about this, including an issue in the Composed Field issues queue.

The module author writes;

I haven't investigated the mechanics behind it but theoretically all that needs to be done is to somehow implements the process that those modules do on retrieving the field value from the database and then unserialize and concatenate the retrieved value.

The problem of course with storing serialised data is the inability to effectively query it using any type of relational db (No indexes.)

You can always build a query using a LIKE on the serialised data ...

WHERE field_one-composed LIKE '%query%'; 

But that's horrible. :(

My comment on the initial question stands; do you want to achieve this using the GUI or through code? I'll update this answer based on your response.

While I appreciate this is not the question, I'm curious about why you chose this module for your use case?

  • Hi, it doesn't really matter if you could guide me to use this via GUI or ViewsAPI. In GUI, I don't want to use ViewsPHP as it has security implications, but if you have some solutions using GUI then I guess it'd be great to hear
    – user12947
    Mar 23, 2014 at 19:53

As I mentioned in your other question, once views is able to fetch the data, you can change what it takes as a result by modifying the handler's set_items method.

However, the field handler is meant to display fields. If you're looking to change how Views filters behave, you'll have to extend and modify the filter handler.

Your Answer

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