function mvf_instance_mockup in Measured Value Field 7
Supportive function.
Mock up instance array of a subfield instance of the supplied $instance array based on the parameter $subfield.
Parameters
array $field: Field array. It is used to extract info and mock up the instance array
array $instance: Instance array. It is used to extract info and mock up the instance array
string $subfield: Subfield name for which the sub field instance should be mocked up
Return value
array Array of mocked up subfield instance
16 calls to mvf_instance_mockup()
- mvf_entityreference_field_instance_settings_validate in ./
mvf.module - Supportive validation function.
- mvf_field_delete in ./
mvf.module - Implements hook_field_delete().
- mvf_field_formatter_prepare_view in ./
mvf.module - Implements hook_field_formatter_prepare_view().
- mvf_field_formatter_settings_form in ./
mvf.module - Implements hook_field_formatter_settings_form().
- mvf_field_formatter_settings_summary in ./
mvf.module - Implements hook_field_formatter_settings_summary().
File
- ./
mvf.module, line 1386 - Define a field type of measured value.
Code
function mvf_instance_mockup($field, $instance, $subfield) {
// We need to figure out what module supplies the widget selected for this
// instance.
$info = _field_info_collate_types();
$widget = $info['widget types'][$field['settings']['meta_info'][$subfield]['widget']];
$mocked_instance = array(
'label' => $instance['label'],
'widget' => array(
'type' => $field['settings']['meta_info'][$subfield]['widget'],
'weight' => $instance['widget']['weight'],
'settings' => isset($instance['widget']['settings'][$subfield]) ? $instance['widget']['settings'][$subfield] : $widget['settings'],
'module' => $widget['module'],
),
'settings' => isset($instance['settings'][$subfield]) ? $instance['settings'][$subfield] : array(),
// Display will be defined later on.
'display' => array(),
'required' => $instance['required'],
'description' => $instance['description'],
'entity_type' => $instance['entity_type'],
'bundle' => $instance['bundle'],
);
if (isset($instance['deleted'])) {
$mocked_instance['deleted'] = $instance['deleted'];
}
if (isset($instance['display']) && is_array($instance['display'])) {
foreach ($instance['display'] as $view_mode => $display) {
$formatter_type = isset($display['settings'][$subfield]['formatter']) ? $display['settings'][$subfield]['formatter'] : $field['settings']['meta_info'][$subfield]['formatter'];
$formatter = $info['formatter types'][$formatter_type];
unset($display['settings'][$subfield]['formatter']);
$mocked_instance['display'][$view_mode] = array(
'label' => $display['label'],
'type' => $formatter_type,
'settings' => isset($display['settings'][$subfield]) && !empty($display['settings'][$subfield]) ? $display['settings'][$subfield] : $formatter['settings'],
'module' => $formatter['module'],
'weight' => $display['weight'],
);
}
}
return $mocked_instance;
}