You are here

function user_relationship_blocks_block_configure in User Relationships 7

helper function user_relationship_blocks_block delegates to when $op == 'configure'

File

user_relationship_blocks/user_relationship_blocks.module, line 109
User Relationship Blocks implementation @author Jeff Smick (creator) @author Alex Karshakevich (maintainer) http://drupal.org/user/183217

Code

function user_relationship_blocks_block_configure($delta) {

  //pad array with nulls before calling list() to avoid php notices
  $exploded = explode(UR_BLOCK_SEPARATOR, $delta);
  while (count($exploded) < 3) {
    $exploded[] = NULL;
  }
  list($block, $rtid, $extra) = $exploded;

  // No form needed for the pending block so don't even bother
  if ($block == 'pending') {
    return;
  }

  //current block settings
  $settings = user_relationship_blocks_block_save($delta);
  if ($block != 'actions') {
    if ($rtid == UR_BLOCK_ALL_TYPES) {
      $relationship_name = t('All');
    }
    else {
      $type = user_relationships_type_load($rtid);
      $relationship_name = user_relationships_type_get_name($type);
    }
    $form['size'] = array(
      '#type' => 'textfield',
      '#size' => 4,
      '#weight' => 1,
      '#required' => TRUE,
      '#title' => t('Number of relationships to display in block'),
      '#description' => t('Enter the maximum number of relationships to display in this block.'),
      '#default_value' => $settings->size,
      '#validate' => array(
        'user_relationships_ui_setting_validation' => array(
          array(
            'is_positive' => array(
              'size' => t('Number of relationships to display must be an integer greater than 0.'),
            ),
          ),
        ),
      ),
    );
    $user_identifier = $block == UR_BLOCK_MY ? t('currently logged in user') : t('author whose node is being viewed');
    $msg = t("NOTE: This block displays @rel_name relationships of the @user_identifier.", array(
      '@rel_name' => $relationship_name,
      '@user_identifier' => $user_identifier,
    ));
    if ($extra) {
      $relation = $extra == 'you_to_them' ? t('requester') : t('requestee');
      $msg .= "\n" . t("Because this relationship is one-way this block will show relationships where the @user_identifier is the @relation", array(
        '@user_identifier' => $user_identifier,
        '@relation' => $relation,
      ));
    }

    //$sort_var = "{$var}_sort";
    $form['sort'] = array(
      '#type' => 'radios',
      '#title' => t('Which relationships should be displayed'),
      '#options' => array(
        'newest' => t('Newest'),
        'oldest' => t('Oldest'),
        'random' => t('Random'),
      ),
      '#default_value' => $settings->sort,
      '#required' => TRUE,
      '#weight' => 3,
      '#suffix' => $msg,
    );
  }
  $form['bid'] = array(
    '#type' => 'hidden',
    '#value' => $delta,
  );
  return $form;
}