/** * Retrieve the complex field data for a certain field. * * @param string $type Datastore type. * @param string $name Name of the field. * @param int $id ID of the entry (optional). * @return array Complex data entries. */ public static function get_complex_fields($type, $name, $id = null) { $datastore = Datastore::factory($type); if ($id !== null) { $datastore->set_id($id); } $group_rows = $datastore->load_values($name); $input_groups = array(); foreach ($group_rows as $row) { if (!preg_match(self::get_complex_field_regex($name), $row['field_key'], $field_name)) { continue; } $row['field_value'] = maybe_unserialize($row['field_value']); // backward compatibility for Relationship field $row['field_value'] = self::parse_relationship_field($row['field_value']); $input_groups[$field_name['index']]['_type'] = $field_name['group']; if (!empty($field_name['trailing'])) { $input_groups = self::expand_nested_field($input_groups, $row, $field_name); } else { if (!empty($field_name['sub'])) { $input_groups[$field_name['index']][$field_name['key']][$field_name['sub']] = $row['field_value']; } else { $input_groups[$field_name['index']][$field_name['key']] = $row['field_value']; } } } // create groups list with loaded fields self::ksort_recursive($input_groups); return $input_groups; }