You are here

function instagram_block_block_configure in Instagram Block 7

Implements hook_block_configure().

Set values to be used when rendering the block later.

File

./instagram_block.module, line 69
Module file for the instagram_block module.

Code

function instagram_block_block_configure($delta = '') {
  $form = array();
  $description = '';

  // Default values
  $empty = array(
    'access_token' => '',
  );

  // Store data from variable in $form for now.
  $form['#admin_data'] = variable_get('instagram_block_admin_settings', $empty);
  $form['description'] = array(
    '#title' => t('Description'),
    '#type' => 'item',
    '#markup' => '',
    '#weight' => -50,
  );
  $form['count'] = array(
    '#type' => 'textfield',
    '#title' => t('Number of images to display.'),
  );
  $form['width'] = array(
    '#type' => 'textfield',
    '#title' => t('Image width in pixels.'),
  );
  $form['height'] = array(
    '#type' => 'textfield',
    '#title' => t('Image height in pixels.'),
  );
  $image_options = array(
    'thumbnail' => t('Thumbnail Preview'),
    'low_resolution' => t('Low Resolution'),
    'standard_resolution' => t('Standard Resolution'),
  );
  $form['img_resolution'] = array(
    '#type' => 'select',
    '#title' => t('Image resolution'),
    '#description' => t('Choose the quality of the images you would like to display.'),
    '#options' => $image_options,
  );
  $form['block_cache'] = array(
    '#type' => 'select',
    '#title' => t('Block Cache Settings'),
    '#description' => t('Configure block caching.'),
    '#options' => array(
      DRUPAL_CACHE_PER_ROLE => t('Cache block per role'),
      DRUPAL_CACHE_PER_USER => t('Cache block per user'),
      DRUPAL_CACHE_PER_PAGE => t('Cache block per page'),
      DRUPAL_CACHE_GLOBAL => t('Cache block globally'),
      DRUPAL_NO_CACHE => t('Don\'t cache block'),
    ),
  );
  switch ($delta) {
    case 'instagram_block':

      // Store data from variable in $form for now.
      $form['#block_data'] = variable_get('instagram_block_user_block_settings', array());
      $description = t('Configurations in this block utilise the !globalconfig.', array(
        '!globalconfig' => l('global configuration', 'admin/config/services/instagram_block'),
      ));
      $form['count']['#default_value'] = isset($form['#block_data']['count']) ? $form['#block_data']['count'] : '';
      $form['width']['#default_value'] = isset($form['#block_data']['width']) ? $form['#block_data']['width'] : '';
      $form['height']['#default_value'] = isset($form['#block_data']['height']) ? $form['#block_data']['height'] : '';
      $form['img_resolution']['#default_value'] = isset($form['#block_data']['img_resolution']) ? $form['#block_data']['img_resolution'] : '';
      $form['block_cache']['#default_value'] = isset($form['#block_data']['block_cache']) ? $form['#block_data']['block_cache'] : DRUPAL_CACHE_GLOBAL;
      break;
    case 'instagram_block_tag':
      $form['#block_data'] = variable_get('instagram_block_tag_block_settings', array());
      $description = t('This block won\'t fetch media from your personal instagram account. Configurations in this block utilise the !globalconfig.', array(
        '!globalconfig' => l('global configuration', 'admin/config/services/instagram_block'),
      ));
      $form['count']['#default_value'] = isset($form['#block_data']['count']) ? $form['#block_data']['count'] : '';
      $form['width']['#default_value'] = isset($form['#block_data']['width']) ? $form['#block_data']['width'] : '';
      $form['height']['#default_value'] = isset($form['#block_data']['height']) ? $form['#block_data']['height'] : '';
      $form['img_resolution']['#default_value'] = isset($form['#block_data']['img_resolution']) ? $form['#block_data']['img_resolution'] : '';
      $form['block_cache']['#default_value'] = isset($form['#block_data']['block_cache']) ? $form['#block_data']['block_cache'] : DRUPAL_CACHE_GLOBAL;
      $form['tag'] = array(
        '#type' => 'textfield',
        '#title' => t('Tag'),
        '#description' => t('Fetch media with this tag'),
        '#default_value' => isset($form['#block_data']['tag']) ? $form['#block_data']['tag'] : '',
        '#weight' => -49,
      );
      break;
  }
  $form['description']['#markup'] = $description;
  return $form;
}