You are here

function block_upload_form in Block Upload 7

Block upload form.

Return value

array Form.

See also

block_upload_form_validate()

block_upload_form_submit()

1 string reference to 'block_upload_form'
block_upload_block_view in ./block_upload.module
Implements hook_block_view().

File

./block_upload.module, line 193
Block Upload module.

Code

function block_upload_form($form, &$form_state, $node, $buid) {
  $submit = FALSE;
  $field = variable_get('block_upload_' . $buid . '_field', '');
  $field_limit = field_info_field($field);
  $field_info = field_info_instance('node', $field, $node->type);
  if (isset($node->{$field}[LANGUAGE_NONE])) {
    $field_files_exists = count($node->{$field}[LANGUAGE_NONE]);
  }
  else {
    $field_files_exists = 0;
  }
  if (user_access('block remove') && $field_files_exists > 0) {
    $title_remove_form = t('Remove files');
    $form['remove_files_title'] = array(
      '#markup' => '<h3>' . $title_remove_form . '</h3>',
    );
    $form['remove_files'] = block_upload_remove_form($field_limit, $node, $field);
    $submit = TRUE;
  }
  if ($field_limit['cardinality'] > $field_files_exists || $field_limit['cardinality'] == FIELD_CARDINALITY_UNLIMITED) {
    $title_upload_form = t('Upload file');
    $form['upload_files_title'] = array(
      '#markup' => '<h3>' . $title_upload_form . '</h3>',
    );
    $form['block_upload_file'] = array(
      '#type' => 'managed_file',
      '#upload_location' => block_upload_get_upload_destination($field_info),
      '#upload_validators' => block_upload_get_validators($field, $field_info),
    );
    $submit = TRUE;
    $settings = variable_get('block_upload_' . $buid . '_settings', array());
    if (isset($settings['alt']) && $settings['alt']) {
      $form['block_upload_' . $buid . '_alt'] = array(
        '#type' => 'textfield',
        '#title' => t('Alt'),
      );
    }
    if (isset($settings['title']) && $settings['title']) {
      $form['block_upload_' . $buid . '_title'] = array(
        '#type' => 'textfield',
        '#title' => t('Title'),
      );
    }
    if (isset($settings['desc']) && $settings['desc']) {
      $form['block_upload_' . $buid . '_desc'] = array(
        '#type' => 'textfield',
        '#title' => t('Description'),
      );
    }
  }
  else {
    $form[] = array(
      '#type' => 'item',
      '#description' => t('Exceeded limit of files'),
    );
  }
  if ($submit) {
    $module_path = drupal_get_path('module', 'block_upload');
    $form['#attached']['js'] = array(
      $module_path . '/theme/block_upload.js',
    );
    $form['#attached']['css'] = array(
      $module_path . '/theme/block_upload.css',
    );
    $form['block_upload_nid'] = array(
      '#type' => 'textfield',
      '#access' => FALSE,
      '#value' => $node->nid,
    );
    $form['block_upload_node_type'] = array(
      '#type' => 'textfield',
      '#access' => FALSE,
      '#value' => $node->type,
    );
    $form['buid'] = array(
      '#type' => 'value',
      '#value' => $buid,
    );
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Save'),
    );
  }
  return $form;
}