You are here

function rotating_banner_slide_form in Rotating Banner 7

Same name and namespace in other branches
  1. 7.2 rotating_banner.admin.inc \rotating_banner_slide_form()

Form callback to edit a rotating banner slide.

@global <type> $base_url

_state

Parameters

<type> $form:

<type> $banner:

<type> $slide:

Return value

<type>

2 calls to rotating_banner_slide_form()
rotating_banner_slide_add in ./rotating_banner.admin.inc
rotating_banner_slide_edit in ./rotating_banner.admin.inc

File

./rotating_banner.admin.inc, line 30

Code

function rotating_banner_slide_form($form, &$form_state, $banner, $slide = NULL) {
  global $base_url;
  $slide_defaults = RotatingBannerSlide::getDefaultSettings();
  include_once drupal_get_path('module', 'media') . '/wysiwyg_plugins/media.inc';
  media_include_browser_js();
  drupal_add_js(array(
    'rotatingBanner' => $banner->settings,
  ), 'setting');
  $form['#id'] = 'rotating-banner-slide-form';
  $form['#submit'][] = 'rotating_banner_slide_form_submit';

  // Add assets
  $path = drupal_get_path('module', 'rotating_banner');
  $form['#attached']['js'][] = $path . '/rotating_banner.admin.js';
  $form['#attached']['js'][] = $path . '/json2.js';
  $form['#attached']['css'][] = $path . '/rotating_banner.css';
  $form['#attached']['css'][] = $path . '/rotating_banner.admin.css';
  $form['rbid'] = array(
    '#type' => 'value',
    '#value' => $banner->rbid,
  );
  if (isset($slide)) {
    $form['sid'] = array(
      '#type' => 'value',
      '#value' => $slide->sid,
    );
  }
  $form['fid'] = array(
    '#type' => 'hidden',
    '#default_value' => 0,
    // Used by rotating_banner.admin.js.
    '#attributes' => array(
      'id' => 'edit-fid',
    ),
  );
  $link_text = <<<EOF
<ul class="action-links">
  <li><a href="#" class="choose-image-link">Choose banner image</a></li>
  <li class="rb-custom-layout-tools"><a href="#" id="rb-add-headline">Add new banner headline</a></li>
  <li><a href="#" class="rb-custom-layout-tools" id="rb-add-text">Add new text area</a></li>

</ul>
EOF;
  $form['textboxes'] = array(
    '#type' => 'hidden',
    '#default_value' => '',
    // Used by rotating_banner.admin.js.
    '#attributes' => array(
      'id' => 'edit-textboxes',
    ),
  );
  $form['slide'] = array(
    '#type' => 'markup',
    '#prefix' => '<div class="form-item rb-slide-preview"><label> Preview </label>',
    '#suffix' => '</div>',
  );

  // Actions the user can take
  $form['links'] = array(
    '#type' => 'markup',
    '#markup' => $link_text,
  );
  $layout_instructions_custom = <<<EOS
  <strong>Instructions:</strong>
    <ol>
    <li> Add as many text areas and headlines as you want using the links at the top of the page.</li>
    <li> Drag them around your slide. </li>
    <li> Double click them to edit (click outside the textbox to save your edit). </li>
    </ol>
EOS;
  $form['layout-instructions-custom'] = array(
    '#type' => 'markup',
    '#prefix' => '<div class="rb-custom-layout-tools">',
    '#markup' => t($layout_instructions_custom),
    '#suffix' => '</div>',
  );
  $form['layout'] = array(
    '#type' => 'select',
    '#title' => t('Layout'),
    '#description' => t('Where should the headline and text be placed on this slide.'),
    '#options' => module_invoke_all('rotating_banner_slide_layouts'),
    '#default_value' => $slide_defaults['layout'],
  );
  $form['layout-text-editor'] = array(
    '#prefix' => '<div class="layout-text-editor">',
    '#suffix' => '</div>',
    '#tree' => true,
  );
  $form['layout-text-editor']['header'] = array(
    '#type' => 'textfield',
    '#title' => t('Banner headline'),
  );
  $form['layout-text-editor']['text'] = array(
    '#type' => 'textarea',
    '#title' => t('Banner text'),
  );
  $form['link'] = array(
    '#type' => 'textfield',
    '#title' => t('Link'),
    '#description' => t('Where to send the user when this slide is clicked on.  Can be an absolute URL (http://google.com), or a relative URL (node/1).  Use "&lt;front&gt;" for the front page of your site.'),
    '#default_value' => $slide_defaults['link'],
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  if ($slide) {
    $form['link']['#default_value'] = $slide->link;
    $form['fid']['#default_value'] = $slide->fid;
    $form['layout']['#default_value'] = $slide->layout;

    //$form['textboxes']['#default_value'] = drupal_json_encode($slide->textboxes);
    $image = file_create_url(file_load($slide->fid)->uri);

    // This is totally yuk.  @todo
    $file = file_load($slide->fid);
    $link = $slide->link;
    $textboxes = $slide->textboxes;
    $form['slide'] += array(
      '#theme' => 'rotating_banner_slide',
      '#banner' => $banner,
      '#background_image' => $file,
      '#textboxes' => $textboxes,
    );

    //$form['slide']['#prefix'] = '<div class="rotating-banner-slide" style="' . sprintf('background-image: url(%s)', $image) . '">';
  }
  else {
    $default_textboxes = $slide_defaults['textboxes'];
    $background_image = NULL;
    if (isset($slide_defaults['fid'])) {
      $background_image = file_load($slide_defaults['fid']);
    }
    $form['fid']['#default_value'] = $slide_defaults['fid'];
    $form['slide'] += array(
      '#theme' => 'rotating_banner_slide',
      '#banner' => $banner,
      '#textboxes' => $default_textboxes,
      '#background_image' => $background_image,
    );
  }

  //  Annoying, this applies a lot of markup I don't want.
  //  $form['links'] = array(
  //    '#theme' => 'item_list',
  //    '#items' => array('<a href="#" id=".choose-image-link">Choose background image</a>', '<a href="#" id=".rb-textbox-text">Add text area</a>'),
  //    '#attributes' => array('class' => array('action-links')),
  //  );

  //Why isn't this getting called on its own?
  $form['#validate'][] = 'rotating_banner_slide_form_validate';
  return $form;
}