You are here

function flashnode_form in Flash Node 5.6

Same name and namespace in other branches
  1. 5.2 flashnode.module \flashnode_form()
  2. 5.3 flashnode.module \flashnode_form()
  3. 6.3 flashnode.module \flashnode_form()
  4. 6.2 flashnode.module \flashnode_form()

Implementation of hook_form

File

./flashnode.module, line 235

Code

function flashnode_form(&$node, &$param) {

  // Need to access user object to determine visibility of basic and advanced settings
  global $user;

  // Check folders exist and are writable
  _flashnode_check_settings();

  // Begin form construct
  $form['#attributes'] = array(
    "enctype" => "multipart/form-data",
  );
  $form['flashnode']['#tree'] = TRUE;

  // Lifted from image.module to handle upload and previews - not sure why this works!
  if ($node->new_file) {
    $form['new_file'] = array(
      '#type' => 'value',
      '#value' => TRUE,
    );
  }
  if ($node->new_file) {
    $form['flashnode']['_flashnode'] = array(
      '#type' => 'hidden',
      '#value' => $node->flashnode['_flashnode'],
    );
    $form['flashnode']['filemime'] = array(
      '#type' => 'hidden',
      '#value' => $node->flashnode['filemime'],
    );
    $form['flashnode']['_height'] = array(
      '#type' => 'hidden',
      '#value' => $node->flashnode['_height'],
    );
    $form['flashnode']['_width'] = array(
      '#type' => 'hidden',
      '#value' => $node->flashnode['_width'],
    );
  }
  else {
    $form['flashnode']['_flashnode'] = array(
      '#type' => 'hidden',
      '#default_value' => $node->flashnode['_flashnode'],
    );
    $form['flashnode']['filemime'] = array(
      '#type' => 'hidden',
      '#default_value' => $node->flashnode['filemime'],
    );
    $form['flashnode']['_height'] = array(
      '#type' => 'hidden',
      '#default_value' => $node->flashnode['_height'],
    );
    $form['flashnode']['_width'] = array(
      '#type' => 'hidden',
      '#default_value' => $node->flashnode['_width'],
    );
  }

  // Title and body fields - this code from node_content_form() in node.module
  $type = node_get_types('type', $node);
  if ($type->has_title) {
    $form['title'] = array(
      '#type' => 'textfield',
      '#title' => check_plain($type->title_label),
      '#required' => TRUE,
      '#default_value' => $node->title,
      '#weight' => -5,
    );
  }
  if ($type->has_body) {
    $form['body_filter']['body'] = array(
      '#type' => 'textarea',
      '#title' => check_plain($type->body_label),
      '#default_value' => $node->body,
      '#rows' => 20,
      '#required' => $type->min_word_count > 0,
    );
    $form['body_filter']['format'] = filter_form($node->format);
  }

  // Flash node upload field
  $form['flashnode']['flashfile'] = array(
    '#type' => 'file',
    '#title' => t('Flash file'),
    '#description' => t('Click "Browse..." to select a swf, flv or mp3 file to upload.'),
    '#tree' => FALSE,
    '#after_build' => array(
      '_flashnode_form_after_build',
    ),
  );

  // Put other settings in a collapsible set for a clean input form
  // We actually create two sections - basic and advance to shield basic users from complex stuff
  // that they don't need to see!
  $form['flashnode']['options1'] = array(
    '#type' => 'fieldset',
    '#title' => t('Basic flash node options'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#tree' => FALSE,
    '#access' => user_access('use basic options') || user_access('use display options') || $user->uid == 1,
  );

  // We over-ride the #parents setting here to strip out ['options']
  $form['flashnode']['options1']['display'] = array(
    '#type' => 'radios',
    '#title' => t('Display in'),
    '#default_value' => isset($node->flashnode['display']) ? $node->flashnode['display'] : variable_get('flashnode_default_display', 0),
    '#options' => array(
      0 => t('Teaser and body'),
      1 => t('Teaser only'),
      2 => t('Body only'),
      3 => t('Do not display'),
    ),
    '#parents' => array(
      'flashnode',
      'display',
    ),
    '#access' => user_access('use display options') || $user->uid == 1,
  );

  // We over-ride the #parents setting here to strip out ['options']
  $form['flashnode']['options1']['width'] = array(
    '#type' => 'textfield',
    '#title' => t('Width'),
    '#default_value' => $node->flashnode['width'],
    '#size' => 5,
    '#maxlength' => 5,
    '#description' => t('The width of the movie, in pixels. Leave blank to use the file\'s own settings.'),
    '#parents' => array(
      'flashnode',
      'width',
    ),
    '#access' => user_access('use basic options') || $user->uid == 1,
    '#after_build' => array(
      '_flashnode_form_after_build',
    ),
  );

  // We over-ride the #parents setting here to strip out ['options']
  $form['flashnode']['options1']['height'] = array(
    '#type' => 'textfield',
    '#title' => t('Height'),
    '#default_value' => $node->flashnode['height'],
    '#size' => 5,
    '#maxlength' => 5,
    '#description' => t('The height of the movie, in pixels. Leave blank to use the file\'s own settings.'),
    '#parents' => array(
      'flashnode',
      'height',
    ),
    '#access' => user_access('use basic options') || $user->uid == 1,
    '#after_build' => array(
      '_flashnode_form_after_build',
    ),
  );

  // Put other settings in a collapsible set for a clean input form
  // We actually create two sections - basic and advance to shield basic users from complex stuff
  // that they don't need to see!
  $form['flashnode']['options2'] = array(
    '#type' => 'fieldset',
    '#title' => t('Advanced flash node options'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#tree' => FALSE,
    '#access' => user_access('use advanced options') || $user->uid == 1,
  );

  // We over-ride the #parents setting here to strip out ['options']
  $form['flashnode']['options2']['substitution'] = array(
    '#type' => 'textarea',
    '#title' => t('Substitution content'),
    '#rows' => 5,
    '#default_value' => $node->flashnode['substitution'],
    '#parents' => array(
      'flashnode',
      'substitution',
    ),
    '#description' => t('If a javascript method is used to embed flash then this is the content that users will see if they are unable to, or choose not to, display the flash content. This content uses the same input format as the body. The default content may be used by entering @default.', array(
      '@default' => '!default',
    )),
    '#after_build' => array(
      '_flashnode_form_after_build',
    ),
  );

  // We over-ride the #parents setting here to strip out ['options']
  $form['flashnode']['options2']['flashvars'] = array(
    '#type' => 'textarea',
    '#title' => t('Flashvars'),
    '#rows' => 5,
    '#default_value' => $node->flashnode['flashvars'],
    '#parents' => array(
      'flashnode',
      'flashvars',
    ),
    '#description' => t('Specify any flashvars that need to be passed to the movie. If the input format allows PHP code you may use PHP to create a dynamic flashvars string.'),
  );

  // We over-ride the #parents setting here to strip out ['options']
  $form['flashnode']['options2']['base'] = array(
    '#type' => 'textfield',
    '#title' => t('Base'),
    '#default_value' => $node->flashnode['base'] ? $node->flashnode['base'] : variable_get('flashnode_default_base', base_path() . file_directory_path()),
    '#parents' => array(
      'flashnode',
      'base',
    ),
    '#description' => t('Over-ride the default setting with a different base path here if necessary, e.g. if migrating existing content. This setting is only needed for movies that use the %loadmovie command with relative paths.', array(
      '%loadmovie' => 'loadMovie()',
    )),
  );

  // Need to call the _flashnode_form_after_build function
  $form['flashnode']['#after_build'] = array(
    '_flashnode_form_after_build',
  );

  // Return form
  return $form;
}