You are here

function scald_gallery_field_widget_atom_reference_textfield_form_alter in Scald: Gallery 7.2

Implements hook_field_widget_WIDGET_TYPE_form_alter().

File

./scald_gallery.module, line 102
Scald Gallery is a Scald Atom Provider for image galleries.

Code

function scald_gallery_field_widget_atom_reference_textfield_form_alter(&$element, &$form_state, $context) {

  // Only alter gallery field gallery_items.
  if (!isset($context['form']['#entity'])) {
    return;
  }
  if ($context['instance']['entity_type'] !== 'scald_atom') {
    return;
  }
  $atom = $context['form']['#entity'];
  if ($atom->type !== 'gallery' || !isset($atom->provider) || $atom->provider !== 'scald_gallery') {
    return;
  }
  if ($context['delta'] >= count($context['items'])) {

    // New empty element.
    $data = array(
      'title_overriden' => 0,
      'title' => '',
      'description' => '',
    );
  }
  else {
    $data = $atom->data['items'][$context['items'][$context['delta']]['sid']];
  }
  $element['sid']['#weight'] = -99;
  $element['title_overriden'] = array(
    '#title' => t('Override this atom title'),
    '#type' => 'checkbox',
    '#default_value' => $data['title_overriden'],
    '#weight' => 20,
  );
  $langcode = !isset($context['langcode']) ? $context['langcode'] : LANGUAGE_NONE;
  $element['title'] = array(
    '#title' => t('Title'),
    '#type' => 'textfield',
    '#default_value' => $data['title'],
    '#states' => array(
      'visible' => array(
        ':input[name="atom0[gallery_items][' . $langcode . '][' . $context['delta'] . '][title_overriden]"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
    '#size' => 90,
    '#maxlength' => 255,
    '#weight' => 21,
  );
  $element['description'] = array(
    '#title' => t('Description'),
    '#type' => 'textarea',
    '#default_value' => $data['description'],
    '#maxlength' => 1000,
    '#rows' => 2,
    '#weight' => 22,
  );
}