You are here

function simpleads_new_block_form in SimpleAds 7.2

New advertisement block form.

1 string reference to 'simpleads_new_block_form'
simpleads_menu in ./simpleads.module
Implements hook_menu().

File

./simpleads.admin.inc, line 11
simpleads.admin.inc

Code

function simpleads_new_block_form($form, &$form_state) {
  $library = libraries_detect('jquery.cycle');
  if (empty($library['installed'])) {
    drupal_set_message(t('jQuery Cycle plugin is not installed. Please <a href="!download-url" target="_blank">download plugin</a> to site/all/libraries/jquery.cycle directory.', array(
      '!download-url' => $library['download url'],
    )), 'warning');
  }
  $form['#attached'] = array(
    'js' => array(
      drupal_get_path('module', 'simpleads') . '/js/block.js',
    ),
  );
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => 'Administrative name',
    '#description' => 'Visible to administrators only',
    '#required' => TRUE,
  );
  $form['machine_name'] = array(
    '#type' => 'machine_name',
    '#title' => 'Machine Name',
    '#required' => TRUE,
    '#description' => t('Machine-friendly name.'),
    '#size' => 20,
    '#maxlength' => 20,
    '#machine_name' => array(
      'exists' => '_simpleads_machine_name_check_duplicates',
      'source' => array(
        'name',
      ),
    ),
  );
  $form['advertisement_groups'] = array(
    '#type' => 'radios',
    '#title' => 'Advertisement groups',
    '#options' => _simpleads_get_groups(),
    '#required' => TRUE,
  );
  $advertisement_views = _simpleads_get_views_list();
  $groups_default = isset($form_state['values']['views']) ? $form_state['values']['views'] : key($advertisement_views);
  $form['views'] = array(
    '#type' => 'select',
    '#title' => 'Advertisement View',
    '#options' => $advertisement_views,
    '#description' => 'Please select a View from the list.',
    '#ajax' => array(
      'event' => 'change',
      'callback' => '_simpleads_get_views_list_select',
      'wrapper' => 'views-display-id',
    ),
    '#default_value' => $groups_default,
  );
  $form['views_display_id'] = array(
    '#type' => 'select',
    '#title' => 'Advertisement View Display',
    '#options' => _simpleads_get_views_displays($groups_default),
    '#description' => 'Please select a display that pulls advertisements for this block.',
    '#prefix' => '<div id="views-display-id">',
    '#suffix' => '</div>',
    '#default_value' => isset($form_state['values']['views_display_id']) ? $form_state['values']['views_display_id'] : '',
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Create a block',
  );
  return $form;
}