function emfield_field in Embedded Media Field 6.3
Implementation of hook_field().
File
- ./
emfield.module, line 89 - Embedded Media Field is a CCK-based framework for embedding media files.
Code
function emfield_field($op, &$node, $field, &$items, $teaser, $page) {
$return = array();
switch ($op) {
case 'presave':
foreach ($items as $delta => $item) {
// Save the media to the database.
$item['media'] = emapi_media_from_uri($item['uri']);
emapi_media_save($item['media']);
}
break;
case 'validate':
foreach ($items as $delta => $item) {
if ($field['required'] && !emapi_get_provider_class($item['uri'])) {
$error_field = $field['multiple'] ? $field['field_name'] . '][' . $delta . '][uri' : $field['field_name'];
form_set_error($error_field, t('You have specified an invalid media URI.'));
}
}
break;
}
// Ensure our $op is callable.
$op = str_replace(' ', '_', $op);
foreach ($items as $delta => $item) {
if ($class_name = emapi_get_provider_class($item['uri'])) {
$class = emapi_get_provider_class_by_class_name($class_name);
if (module_hook($class['module'], 'emfield_field_' . $op)) {
$args = array(
&$node,
$field,
&$items,
$teaser,
$page,
$item,
$delta,
);
$ret = call_user_func_array($class['module'] . '_emfield_field_' . $op, $args);
if (is_array($ret)) {
$return = array_merge($return, $ret);
}
}
}
}
foreach (module_implements('emfield_field_extra_' . $op) as $module) {
$args = array(
&$node,
$field,
&$items,
$teaser,
$page,
);
$ret = call_user_func_array($module . '_emfield_field_extra_' . $op, $args);
if (is_array($ret)) {
$return = array_merge($return, $ret);
}
}
return $return;
}