Closed folbert closed 7 years ago
Improved version allowing you to pass an multidimensional array to save a field name under another name in the returned array.
/**
* @param array $field_names ['field_name_1', 'field_name_2', ['field_name_3' => 'name_to_save_as']]
* @return array
*/
protected function get_field_values($field_names)
{
$values = [];
foreach($field_names AS $field_name) {
if(is_array($field_name)) {
$key = key($field_name);
$values[$field_name[$key]] = $this->get_field($key);
} else {
$values[$field_name] = $this->get_field($field_name);
}
}
return $values;
}
Also add way to pass if value should be fetched from options. Or maybe implement separate function for that.
This will allow for writing
$data = $this->get_field_values(['field_name', 'another_field_name]);
instead of
Code: