function _workflowfield_metadata_property_get in Workflow 7.2
Getter callback for Workflow defined in hook_entity_property_info_alter.
This is different from the default, because 'value' is not always set and 'workflow' may be set, but is not in the field data.
1 string reference to '_workflowfield_metadata_property_get'
- workflowfield_property_info_callback in workflow_field/
workflowfield.field.inc - Implements property_callbacks for hook_field_info().
File
- workflow_field/
workflowfield.field.inc, line 83 - Defines a Workflow field, widget and formatter. (copied from list field).
Code
function _workflowfield_metadata_property_get($entity, array $options, $name, $entity_type, $info) {
$values = array();
// return entity_metadata_field_property_get($entity, array $options, $name, $entity_type, $info);
$field = field_info_field($name);
$columns = array_keys($field['columns']);
$langcode = isset($options['language']) ? $options['language']->language : LANGUAGE_NONE;
$langcode = entity_metadata_field_get_language($entity_type, $entity, $field, $langcode, TRUE);
if (isset($entity->{$name}[$langcode])) {
foreach ($entity->{$name}[$langcode] as $delta => $data) {
// In workflowfield_property_info_callback(), we needed to set a column 'value'.
// This is now filled from the widget data.
// Sometimes that is not widget, or the submit function has not been processed yet.
// On a normal widget:
$sid = isset($data['value']) ? $data['value'] : 0;
// On a workflow form widget:
$sid = isset($data['workflow']['workflow_sid']) ? $data['workflow']['workflow_sid'] : $sid;
// The workflow widget was not loaded properly. @see #2597307.
// So we need to reload the entity to extract the correct value.
if (!$sid && isset($data['workflow'])) {
// $new_entity = $entity->original; // is NULL :-(
list($entity_id, , ) = entity_extract_ids($entity_type, $entity);
if (!empty($entity_id)) {
$new_entity = entity_load_single($entity_type, $entity_id);
$workflow = $new_entity->{$name}[$langcode][$delta];
$sid = isset($workflow['value']) ? (int) $workflow['value'] : 0;
}
}
$data[$columns[0]] = $sid;
$values[$delta] = $sid;
}
}
// For an empty single-valued field, we have to return NULL.
return $field['cardinality'] == 1 ? $values ? reset($values) : NULL : $values;
}