You are here

function blockreference_field_widget_form in Block reference 7.2

Same name and namespace in other branches
  1. 7 blockreference.module \blockreference_field_widget_form()

Implements hook_field_widget_form().

File

./blockreference.field.inc, line 278

Code

function blockreference_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
  switch ($instance['widget']['type']) {
    case 'blockreference_autocomplete':
      $eid = 0;
      if (!empty($element['#entity'])) {
        list($eid) = entity_extract_ids($instance['entity_type'], $element['#entity']);
      }
      $ac_string = '';
      if (!empty($items[$delta])) {
        $item = $items[$delta];
        list($module, $delta) = explode(':', $item['moddelta']);
        $ac_string = _blockreference_block_string(_blockreference_block($module, $delta));
      }
      $element += array(
        '#type' => 'textfield',
        '#default_value' => $ac_string,
        '#autocomplete_path' => $instance['widget']['settings']['autocomplete_path'] . '/' . $instance['entity_type'] . '/' . $instance['bundle'] . '/' . $instance['field_name'] . '/' . (int) $eid,
        '#size' => $instance['widget']['settings']['size'],
        '#element_validate' => array(
          'blockreference_autocomplete_validate',
        ),
        '#value_callback' => 'blockreference_autocomplete_value',
        '#maxlength' => 999,
      );
      $element = array(
        'moddelta' => $element,
      );
      break;
  }
  return $element;
}