You are here

function atom_reference_textfield_process in Scald: Media Management made easy 6

Process an individual element, building the actual form api components needed for this widget.

1 string reference to 'atom_reference_textfield_process'
atom_reference_elements in atom_reference/atom_reference.module
Implements hook_elements.

File

atom_reference/atom_reference.module, line 228
Defines a new field type, allowing to directly reference Scald Atoms from a node.

Code

function atom_reference_textfield_process($element, $edit, $form_state, $form) {
  dnd_add_library();
  drupal_add_js(drupal_get_path('module', 'atom_reference') . '/atom_reference.js');
  drupal_add_css(drupal_get_path('module', 'atom_reference') . '/atom_reference.css');
  $default = isset($element['#value']['sid']) ? $element['#value']['sid'] : '';
  if ($default) {
    $prefix = '<div class="atom_reference_drop_zone">' . scald_render($default, 'sdl_editor_representation') . '</div>';
  }
  else {
    $placeholder = t('Drop a resource here');
    $prefix = '<div class="atom_reference_drop_zone"><em>' . $placeholder . '</em></div>';
  }
  $help = format_plural(count($element['#types']), 'Allowed resource format: %types', 'Allowed resource formats: %types', array(
    '%types' => implode(', ', $element['#types']),
  ));
  $element['sid'] = array(
    '#type' => 'textfield',
    '#default_value' => $default,
    '#title' => $element['#title'],
    '#description' => $element['#description'] . $help,
    '#required' => $element['#required'],
    '#field_name' => $element['#field_name'],
    '#type_name' => $element['#type_name'],
    '#delta' => $element['#delta'],
    '#columns' => $element['#columns'],
    '#attributes' => array(
      'atom:types' => implode(',', $element['#types']),
    ),
    '#field_prefix' => $prefix,
  );
  return $element;
}