You are here

function ddblock_block_configure_form in Dynamic display block 7

Block configuration page of dynamic display block blocks added to standard block configuration page.

Parameters

$delta: Blocknumber of the block.

Return value

form with configuration settings.

1 call to ddblock_block_configure_form()
ddblock_block_configure in ./ddblock.module
Implements hook_block_configure().

File

./ddblock.module, line 264
Enables your site to display dynamic content in a block.

Code

function ddblock_block_configure_form($delta) {

  // get configuration settings
  foreach (ddblock_get_configuration_settings('ddblock', $delta)
    ->settings() as $key => $value) {
    ${$key} = $value;
  }

  // get configuration settings
  foreach (ddblock_get_cycle_configuration_settings('ddblock_cycle', $delta)
    ->settings() as $key => $value) {
    ${$key} = $value;
  }

  // get module path to dynamic display block module
  $ddblock_path = drupal_get_path('module', 'ddblock');

  // add ddblock js file
  drupal_add_js($ddblock_path . '/js/ddblock.admin.js');

  // Need this for AJAX.
  $form['#cache'] = TRUE;

  // show warning that cycle plugin is not installed.
  $cycle_path = libraries_get_path('jquery.cycle');
  if (empty($cycle_path) || !(file_exists($cycle_path . '/jquery.cycle.all.min.js') || file_exists($cycle_path . '/jquery.cycle.all.js'))) {
    $form['no_cycle_js'] = array(
      '#type' => 'item',
      '#title' => 'Cycle plugin',
      '#markup' => '<div style="color: red">' . t('You need to install the jQuery cycle plugin.<br />
      Create a directory in sites/all/libraries called jquery.cycle, and then copy jquery.cycle.all.js or jquery.cycle.all.min.js into it.<br />
      Latest version tested: 2.99<br />
      You can find the plugin at !url.', array(
        '!url' => l('http://malsup.com/jquery/cycle/download.html', 'http://malsup.com/jquery/cycle/download.html', array(
          'attributes' => array(
            'target' => '_blank',
          ),
        )),
      )) . '</div>',
      '#prefix' => '<div id="ddblock-no-cycle-js">',
      '#suffix' => '</div>',
      '#weight' => -11,
    );
  }

  // content settings: what to use as content for the dynamic display block.
  $form['content'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#title' => t('Content settings'),
    '#prefix' => '<div id="ddblock-content-settings">',
    '#suffix' => '</div>',
    '#weight' => -1,
  );

  // input type settings
  $options = array(
    'images' => t('Image folder'),
    'nodes' => t('Content type'),
  );
  $form['content']['input_type'] = array(
    '#type' => 'select',
    '#title' => t('Input type'),
    '#default_value' => $input_type,
    '#options' => $options,
    '#multiple' => FALSE,
    '#required' => TRUE,
    '#description' => t("Input of the dynamic display block."),
    '#weight' => -7,
  );

  // image folder settings.
  $form['content']['image_folder'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#title' => t('Image folder settings'),
    '#prefix' => '<div id="ddblock-image-folder-settings-wrapper">',
    '#suffix' => '</div>',
    '#weight' => -6,
  );
  $form['content']['image_folder']['folder'] = array(
    '#type' => 'textfield',
    '#title' => t('Image Folder'),
    '#default_value' => $folder,
    '#size' => 25,
    '#maxlength' => 100,
    '#required' => FALSE,
    '#description' => t("The folder containing image files to be used as the content of dynamic display block. The folder is relative to the drupal files path in admin > settings > file-system. e.g. <strong>images/ddblock</strong>."),
  );
  $form['content']['image_folder']['ignore_files'] = array(
    '#type' => 'textfield',
    '#title' => t('Ignore files'),
    '#default_value' => $ignore_files,
    '#required' => FALSE,
    '#description' => t("Ignore these files to be shown. e.g. ignore file with _thumbnail, _preview in the file_name.<br />\n      You can use a comma seprated list"),
  );
  $form['content']['image_folder']['max_image'] = array(
    '#type' => 'textfield',
    '#title' => t('Number of images'),
    '#default_value' => $max_image,
    '#required' => FALSE,
    '#description' => t("The number of images to show in the block."),
  );

  // content type settings.
  $form['content']['content_types'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#title' => t('Content type settings'),
    '#prefix' => '<div id="ddblock-content-types-settings-wrapper">',
    '#suffix' => '</div>',
    '#weight' => -5,
  );

  // get possible content types from settings.
  $node_types = variable_get('ddblock_node_type', array());
  foreach ($node_types as $key => $value) {
    if ($value) {
      $content_types[$key] = $value;
    }
  }

  // add a none option to the content types to choose from.
  $content_types['none'] = t("None");
  $form['content']['content_types']['content_type'] = array(
    '#type' => 'select',
    '#title' => t('Content Type'),
    '#default_value' => $content_type,
    '#options' => $content_types,
    '#description' => t("The nodes of the content type to be used as content of dynamic display block.<br />Only content types enabled in the settings tab of the ddblock module will show up here."),
    '#attributes' => array(
      'class' => array(
        'content-type-select',
      ),
    ),
    '#ahah' => array(
      'path' => 'ddblock/js/select_nodes',
      'wrapper' => 'select-nodes-wrapper',
      'effect' => 'slide',
    ),
  );
  ddblock_select_nodes_form($form, $content_type, $nodes);
  $options = array(
    'body' => t('Body'),
    'teaser' => t('Teaser'),
  );
  $form['content']['content_types']['node_body_teaser'] = array(
    '#type' => 'radios',
    '#title' => t('Node content'),
    '#default_value' => $node_body_teaser,
    '#options' => $options,
    '#multiple' => FALSE,
    '#required' => TRUE,
    '#description' => t("Show node body or teaser"),
  );

  // get image style options
  $image_style_options = image_style_options(FALSE);

  // if image styles exist make it possible to use image styles
  if (is_array($image_style_options)) {
    $image_style_options['none'] = 'None';
    $image_style_slide_desc = t("Style options to use for slide image");
    $image_style_pager_item_desc = t("Style options to use for pager-item image. Only for themes that use an image in the pager");

    // Image style toggle
    $form['block_settings']['image_style_toggle'] = array(
      '#type' => 'checkbox',
      '#title' => t('Use image styles'),
      '#default_value' => $image_style_toggle,
      '#required' => FALSE,
      '#description' => t("Use image styles for images"),
      '#weight' => -5,
    );

    // Image style settings.
    $extra = empty($image_style_toggle) ? ' style="display:none"' : '';
    $form['block_settings']['image_style'] = array(
      '#type' => 'fieldset',
      '#collapsible' => TRUE,
      '#title' => t('Image styles settings'),
      '#prefix' => '<div id="ddblock-image-style-settings-wrapper"' . $extra . '>',
      '#suffix' => '</div>',
      '#weight' => -4,
    );
    $form['block_settings']['image_style']['image_style_slide'] = array(
      '#type' => 'select',
      '#title' => t('Image style slide image'),
      '#default_value' => $image_style_slide,
      '#options' => $image_style_options,
      '#multiple' => FALSE,
      '#required' => FALSE,
      '#description' => $image_style_slide_desc,
      '#weight' => 1,
    );
    $form['block_settings']['image_style']['image_style_pager_item'] = array(
      '#type' => 'select',
      '#title' => t('Image style pager-item image'),
      '#default_value' => $image_style_pager_item,
      '#options' => $image_style_options,
      '#multiple' => FALSE,
      '#required' => FALSE,
      '#description' => $image_style_pager_item_desc,
      '#weight' => 2,
    );
  }

  // content container settings.
  $form['content']['content_container'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#title' => t('Content container settings'),
    '#weight' => -4,
  );
  $form['content']['content_container']['container_basic'] = array(
    '#type' => 'textfield',
    '#title' => t('Content container'),
    '#default_value' => $container_basic,
    '#required' => FALSE,
    '#description' => t("Container of the content to show, eg. div.slide, to show the content of slides."),
  );
  $form['content']['content_container']['overflow'] = array(
    '#type' => 'checkbox',
    '#title' => t('Overflow hidden'),
    '#default_value' => $overflow,
    '#required' => FALSE,
    '#description' => t("Hide the overflow of the container"),
  );
  $form['content']['content_container']['height'] = array(
    '#type' => 'textfield',
    '#title' => t('Height'),
    '#default_value' => $height,
    '#required' => FALSE,
    '#description' => t("Height of the content to show.<br /> This value is often higher as the image height"),
  );
  $form['content']['content_container']['width'] = array(
    '#type' => 'textfield',
    '#title' => t('Width'),
    '#default_value' => $width,
    '#required' => FALSE,
    '#description' => t("Width of the content to show.<br />This value is often higher as the image widht"),
  );

  // Image settings.
  $form['content']['images'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#title' => t('Image settings'),
    '#description' => t('Set to 0 (zero) for both the height and the width to be able to use the original image size or image styles.<br />To show all the images the height and width of the content container must be bigger that the biggest image.'),
    '#weight' => -3,
  );
  $form['content']['images']['image_height'] = array(
    '#type' => 'textfield',
    '#title' => t('Height'),
    '#default_value' => $image_height,
    '#required' => FALSE,
    '#description' => t("Height of the image to show"),
  );
  $form['content']['images']['image_width'] = array(
    '#type' => 'textfield',
    '#title' => t('Width'),
    '#default_value' => $image_width,
    '#required' => FALSE,
    '#description' => t("Width of the image to show"),
  );

  //wrapper for ddblock block settings
  $form['block_settings']['#prefix'] = '<div id="ddblock-block-settings">';
  $form['block_settings']['#suffix'] = '</div>';
  $form['block_settings']['settings'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#title' => t('Settings'),
    '#weight' => 11,
  );

  // transition effect settings
  $options = _ddblock_get_effects();
  $form['block_settings']['settings']['fx'] = array(
    '#type' => 'select',
    '#title' => t('Transition Effect'),
    '#default_value' => $fx,
    '#options' => $options,
    '#multiple' => FALSE,
    '#required' => TRUE,
    '#description' => t("The transition effect between content.<br />(all for random effect per slide, none for no effect)<br />Multiple effects can be set in the Custom jQuery Cycle Plugin Settings."),
  );

  // speed settings
  $options = drupal_map_assoc(array(
    0,
    250,
    500,
    1000,
    2000,
    3000,
    4000,
    5000,
    6000,
    7000,
    8000,
    9000,
    10000,
    15000,
    20000,
  ));
  $form['block_settings']['settings']['speed'] = array(
    '#type' => 'select',
    '#title' => t('Speed'),
    '#default_value' => $speed,
    '#options' => $options,
    '#required' => TRUE,
    '#description' => t("Speed of the transitions (1000 = 1 second, 0 = direct)."),
  );

  // timeout settings
  $options = drupal_map_assoc(array(
    0,
    250,
    500,
    1000,
    2000,
    3000,
    4000,
    5000,
    6000,
    7000,
    8000,
    9000,
    10000,
    15000,
    20000,
    30000,
  ));
  $form['block_settings']['settings']['timeout'] = array(
    '#type' => 'select',
    '#title' => t('Timeout'),
    '#default_value' => $timeout,
    '#options' => $options,
    '#required' => TRUE,
    '#description' => t("The time (in milliseconds) between transitions (1000 = 1 second, 0 to disable auto advance)."),
  );

  // order settings
  $options = array(
    'none' => t('None'),
    'asc' => t('Ascending'),
    'desc' => t('Descending'),
  );
  $form['block_settings']['settings']['order'] = array(
    '#type' => 'radios',
    '#title' => t('Sort Order'),
    '#default_value' => $order,
    '#options' => $options,
    '#multiple' => FALSE,
    '#required' => TRUE,
    '#description' => t("The display order of the content. None for using the original content order."),
  );

  // pause settings
  $form['block_settings']['settings']['pause'] = array(
    '#type' => 'checkbox',
    '#title' => t('Pause'),
    '#default_value' => $pause,
    '#description' => t("Enable users to pause the cycle by hovering on the content."),
  );

  // next settings
  $form['block_settings']['settings']['next'] = array(
    '#type' => 'checkbox',
    '#title' => t('Next'),
    '#default_value' => $next,
    '#description' => t("Enable users to advanced to the next content by clicking on the content."),
  );

  // pager settings
  $form['block_settings']['settings']['pager_toggle'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use Pager'),
    '#default_value' => $pager_toggle,
    '#required' => FALSE,
    '#description' => t("Use a pager to select slides"),
  );

  // show fields when using pager
  $extra = empty($pager_toggle) ? ' style="display:none"' : '';
  $form['block_settings']['settings']['pager_settings'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#prefix' => '<div id="ddblock-pager-settings-wrapper"' . $extra . '>',
    '#suffix' => '</div>',
    '#title' => t('Pager settings'),
  );
  $options = array(
    'number-pager' => t('Number pager'),
    'prev-next-pager' => t('Prev next pager'),
    'image-pager' => t('Image pager'),
  );
  $form['block_settings']['settings']['pager_settings']['pager'] = array(
    '#type' => 'select',
    '#title' => t('Pager'),
    '#default_value' => $pager,
    '#options' => $options,
    '#required' => TRUE,
    '#description' => t("Add a pager to the block."),
  );
  $options = array(
    'click' => t('Click'),
    'mouseover' => t('Mouseover'),
  );
  $form['block_settings']['settings']['pager_settings']['pager_event'] = array(
    '#type' => 'select',
    '#title' => t('Pager event'),
    '#default_value' => $pager_event,
    '#options' => $options,
    '#required' => FALSE,
    '#description' => t("The event on which the pager reacts."),
  );
  $form['block_settings']['settings']['pager_settings']['pager_height'] = array(
    '#type' => 'textfield',
    '#title' => t('Height'),
    '#default_value' => $pager_height,
    '#required' => FALSE,
    '#description' => t("Height of the pager"),
  );
  $form['block_settings']['settings']['pager_settings']['pager_width'] = array(
    '#type' => 'textfield',
    '#title' => t('Width'),
    '#default_value' => $pager_width,
    '#required' => FALSE,
    '#description' => t("Width of the pager"),
  );
  $form['block_settings']['settings']['pager_settings']['pager_fast'] = array(
    '#type' => 'checkbox',
    '#title' => t('Fast Pager'),
    '#default_value' => $pager_fast,
    '#required' => FALSE,
    '#description' => t("Use fast pager event when clicked or hovered."),
  );
  $form['block_settings']['settings']['pager_settings']['pager_pause'] = array(
    '#type' => 'checkbox',
    '#title' => t('Pager pause'),
    '#default_value' => $pager_pause,
    '#required' => FALSE,
    '#description' => t("Pause the slideshow when pager hovered."),
  );

  // prev/next pager settings.
  $form['block_settings']['settings']['pager2'] = array(
    '#type' => 'checkbox',
    '#title' => t('Prev/Next Pager'),
    '#default_value' => $pager2,
    '#required' => FALSE,
    '#description' => t("Add a previous/next pager."),
  );

  // show fields when using pager
  $extra = empty($pager2) ? ' style="display:none"' : '';
  $form['block_settings']['settings']['pager2_settings'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#prefix' => '<div id="ddblock-pager2-settings-wrapper"' . $extra . '>',
    '#suffix' => '</div>',
    '#title' => t('Prev/next pager settings'),
  );
  $options = array(
    'click' => t('Click'),
    'mouseover' => t('Mouseover'),
  );
  $form['block_settings']['settings']['pager2_settings']['pager2_event'] = array(
    '#type' => 'select',
    '#title' => t('Pager event'),
    '#default_value' => $pager2_event,
    '#options' => $options,
    '#required' => FALSE,
    '#description' => t("The event on which the prev/next pager reacts."),
  );
  $form['block_settings']['settings']['pager2_settings']['pager2_slide_prev'] = array(
    '#type' => 'textfield',
    '#title' => t('Prev text on slide'),
    '#default_value' => $pager2_slide_prev,
    '#size' => 30,
    '#required' => FALSE,
    '#description' => t("Caption for the prev pager on the slide.<br />Can also be empty if you use a background image to go to the previous slide."),
  );
  $form['block_settings']['settings']['pager2_settings']['pager2_slide_next'] = array(
    '#type' => 'textfield',
    '#title' => t('Next text on slide'),
    '#default_value' => $pager2_slide_next,
    '#size' => 30,
    '#required' => FALSE,
    '#description' => t("Caption for the next pager on the slide.<br />Can also be empty if you use a background image to go to the next slide."),
  );

  // hide prev/next pager when no prev/next slide available
  $form['block_settings']['settings']['pager2_settings']['pager2_slide']['pager2_slide_hide'] = array(
    '#type' => 'checkbox',
    '#title' => t('Prev/Next Hide'),
    '#default_value' => $pager2_slide_hide,
    '#required' => FALSE,
    '#description' => t("Hide Prev/Next Pager when no slide available."),
  );

  // custom jcycle plugin settings
  // collapsed or not collapsed depending on value for custom settings.
  if ($custom_jquery) {
    $collapsed = FALSE;
  }
  else {
    $collapsed = TRUE;
  }
  $form['block_settings']['settings']['custom'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => $collapsed,
    '#title' => t('Custom jQuery Cycle Plugin Settings'),
    '#weight' => 1,
    '#description' => t('If you use custom jQuery options, they will override your other settings.'),
  );
  $form['block_settings']['settings']['custom']['custom_jquery'] = array(
    '#type' => 'textarea',
    '#title' => t('Custom Options'),
    '#default_value' => $custom_jquery,
    '#cols' => 60,
    '#rows' => 10,
    '#required' => FALSE,
    '#description' => t('Use valid JSON syntax, with double quotes for key/and string value pairs.<br />The total script needs to be enclosed in curly brackets.<br />No comma allowed after the last statement like in an array.<br />e.g.<br />{"fx":"fade",<br />"startingSlide":2,<br />"autostop":1}'),
  );
  $form_state['redirect'] = 'admin/structure/ddblock/list';
  return $form;
}