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";}'));
Array
(
[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.