You are here

function flashnode_form in Flash Node 6.2

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

Implementation of hook_form

File

./flashnode.module, line 188

Code

function flashnode_form(&$node) {

  // Need to access user object later to determine if some sections of node form are visible
  global $user;

  // Check flash directory exists and is writable
  _flashnode_check_settings();

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

  // Flash node items require their parents
  $form['flashnode']['#tree'] = TRUE;

  // Lifted from image.module to handle upload and previews
  if ($node->new_file) {
    $form['new_file'] = array(
      '#type' => 'value',
      '#value' => TRUE,
    );
  }
  $form['flashnode']['filepath'] = array(
    '#type' => 'value',
    '#value' => $node->flashnode['filepath'],
  );
  $form['flashnode']['filename'] = array(
    '#type' => 'value',
    '#value' => $node->flashnode['filename'],
  );
  $form['flashnode']['fid'] = array(
    '#type' => 'value',
    '#value' => $node->flashnode['fid'],
  );
  $form['flashnode']['_height'] = array(
    '#type' => 'value',
    '#value' => $node->flashnode['_height'],
  );
  $form['flashnode']['_width'] = array(
    '#type' => 'value',
    '#value' => $node->flashnode['_width'],
  );

  // Add title and body fields as required
  $type = node_get_types('type', $node);

  // Add title if required
  if ($type->has_title) {
    $form['title'] = array(
      '#type' => 'textfield',
      '#title' => check_plain($type->title_label),
      '#required' => TRUE,
      '#default_value' => $node->title,
      '#weight' => -5,
    );
  }

  // Add body area if required
  if ($type->has_body) {
    $form['body_field'] = node_body_field($node, $type->body_label, $type->min_word_count);
  }

  // Flash node upload field
  $form['flashnode']['flashfile'] = array(
    '#type' => 'file',
    '#title' => t('Flash file'),
    '#description' => $node->flashnode['fid'] ? t('Current file is %filename. Click "Browse..." to upload a different file.', array(
      '%filename' => basename($node->flashnode['filepath']),
    )) : t('Click "Browse..." to select a file to upload.'),
    '#tree' => FALSE,
  );

  // Put other settings in a collapsible set for a clean input form
  // We create two sections - basic and advanced
  // Access to these settings is controlled via user permissions
  // Basic settings
  $form['flashnode']['basic'] = 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']['basic']['display'] = array(
    '#type' => 'radios',
    '#title' => t('Display in'),
    '#default_value' => isset($node->flashnode['display']) ? $node->flashnode['display'] : variable_get('flashnode_default_display', FLASHNODE_TEASER_AND_BODY),
    '#options' => array(
      FLASHNODE_TEASER_AND_BODY => t('Teaser and body'),
      FLASHNODE_TEASER_ONLY => t('Teaser only'),
      FLASHNODE_BODY_ONLY => t('Body only'),
      FLASHNODE_DO_NOT_DISPLAY => 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']['basic']['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,
  );

  // We over-ride the #parents setting here to strip out ['options']
  $form['flashnode']['basic']['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,
  );

  // Advanced settings
  $form['flashnode']['advanced'] = 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']['advanced']['substitution'] = array(
    '#type' => 'textarea',
    '#title' => t('Substitution content'),
    '#rows' => 5,
    '#default_value' => isset($node->flashnode['substitution']) ? $node->flashnode['substitution'] : '!default',
    '#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',
    )),
  );

  // We over-ride the #parents setting here to strip out ['options']
  $form['flashnode']['advanced']['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']['advanced']['base'] = array(
    '#type' => 'textfield',
    '#title' => t('Base'),
    '#default_value' => isset($node->flashnode['base']) ? $node->flashnode['base'] : variable_get('flashnode_default_base', ''),
    '#parents' => array(
      'flashnode',
      'base',
    ),
    '#description' => t('Over-ride the default setting with a different base path here if necessary. This setting is needed for movies that use ActionScription functions such as %loadmovie with unqualified paths. Leave blank to let flash node generate a default that points to %defaultbase.', array(
      '%loadmovie' => 'loadMovie()',
      '%defaultbase' => file_create_url(''),
    )),
  );

  // We over-ride the #parents setting here to strip out ['options']
  $form['flashnode']['advanced']['params'] = array(
    '#type' => 'textfield',
    '#title' => t('Parameters'),
    '#default_value' => $node->flashnode['params'],
    '#parents' => array(
      'flashnode',
      'params',
    ),
    '#description' => t('An optional list of parameters to pass to the flash player when the file is rendered. Refer to !technote for details of parameters that can be used. Note - this feature requires SWF Tools to be used to embed flash content.', array(
      '!technote' => l('Adobe TechNote 12701', 'http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_12701'),
    )),
  );

  // Return form
  return $form;
}