function flickrfield_widget in Flickr 5
Same name and namespace in other branches
- 6 field/flickrfield.module \flickrfield_widget()
Implementation of hook_widget().
File
- field/
flickrfield.module, line 78 - Defines a Flickr field type.
Code
function flickrfield_widget($op, &$node, $field, &$items) {
switch ($op) {
case 'form':
$form = array();
$form['flickr']['#type'] = 'fieldset';
$form['flickr']['#title'] = t('Flickr Photos');
$form['flickr']['#description'] = t($field['widget']['description']);
$options = array();
$options['photo_id'] = t("Photo");
$options['set_id'] = t("Photoset");
$delta = 0;
$range = $field['multiple'] ? sizeof($items) + 2 : 0;
foreach (range($delta, $range) as $delta) {
$form['flickr']['field_' . $delta][$field['field_name']] = array(
'#tree' => TRUE,
);
if ($field['multiple']) {
$form['flickr']['field_' . $delta][$field['field_name']]['#type'] = 'fieldset';
$form['flickr']['field_' . $delta][$field['field_name']]['#title'] = t('Item #@no', array(
'@no' => intval($delta + 1),
));
$form['flickr']['field_' . $delta][$field['field_name']]['#collapsible'] = 1;
$form['flickr']['field_' . $delta][$field['field_name']]['#collapsed'] = $delta == 0 || !empty($items[$delta]['type']) ? 0 : 1;
}
$form['flickr']['field_' . $delta][$field['field_name']][$delta]['type'] = array(
'#type' => 'select',
'#title' => t('Item Type'),
'#default_value' => $items[$delta]['type'],
'#options' => $options,
'#required' => $delta == 0 && $field['required'] ? TRUE : FALSE,
);
$form['flickr']['field_' . $delta][$field['field_name']][$delta]['id'] = array(
'#type' => 'textfield',
'#title' => t('Id'),
'#default_value' => $items[$delta]['id'],
'#description' => t("The photo or photoset id."),
'#required' => $delta == 0 && $field['required'] ? TRUE : FALSE,
);
$form['flickr']['field_' . $delta][$field['field_name']][$delta]['nsid'] = array(
'#type' => 'textfield',
'#title' => t('User Id'),
'#default_value' => !empty($items[$delta]['nsid']) ? $items[$delta]['nsid'] : variable_get('flickr_default_userid', ''),
'#description' => t("The user id of the Flickr user who owns the photos. If this is left blank, the sites's default user will be used. Current default id is @id.", array(
'@id' => variable_get('flickr_default_userid', ''),
)),
'#required' => $delta == 0 && $field['required'] ? TRUE : FALSE,
);
}
return $form;
case 'process form values':
// Don't save empty fields except the first value
foreach ($items as $delta => $item) {
if ($item['id'] == '' && $delta > 0) {
unset($items[$delta]);
}
}
break;
}
}