You are here

function _user_relationship_blocks_form in User Relationships 5.2

Same name and namespace in other branches
  1. 6 user_relationship_blocks/user_relationship_blocks.module \_user_relationship_blocks_form()

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

1 call to _user_relationship_blocks_form()
user_relationship_blocks_block in plugins/user_relationship_blocks/user_relationship_blocks.module
Implementation for hook_block

File

plugins/user_relationship_blocks/user_relationship_blocks.module, line 87

Code

function _user_relationship_blocks_form($block, $rtid, $extra) {

  // No form for these so don't even bother
  $no_form_blocks = array(
    'pending',
    'actions',
  );
  if (in_array($block, $no_form_blocks)) {
    return;
  }
  if ($rtid == UR_BLOCK_ALL_TYPES) {
    $relationship_name = 'All';
  }
  else {
    $type = user_relationships_type_load($rtid);
    $relationship_name = $type->name;
  }
  $form = array();
  $var = "user_relationships_block_{$block}_t_{$rtid}_size";
  $form[$var] = array(
    '#type' => 'textfield',
    '#title' => t('Number of relationships to display in block'),
    '#description' => t('Enter the maximum number of relationships to display in this block.'),
    '#size' => 4,
    '#default_value' => variable_get($var, UR_BLOCK_DEFAULT_SIZE),
    '#weight' => 1,
    '#required' => TRUE,
    '#validate' => array(
      'user_relationships_setting_validation' => array(
        array(
          'is_numeric' => array(
            'msg' => t('Number of users must be an integer greater than 0.'),
          ),
        ),
      ),
    ),
  );
  $usr_msg = $block == UR_BLOCK_MY ? 'currently logged in user' : 'author whose node is being viewed';
  $msg = "NOTE: This block displays @relationship_name relationships of the {$usr_msg}.";
  if ($extra) {
    $relation = $extra == 'you_to_them' ? t('requester') : t('requestee');
    $msg .= "\nBecause this relationship is one-way this block will show relationships where the {$usr_msg} is the {$relation}";
  }
  $var = "user_relationships_block_{$block}_t_{$rtid}_sort";
  $form[$var] = array(
    '#type' => 'radios',
    '#title' => t('Which relationships should be displayed'),
    '#options' => array(
      'newest' => t('Newest'),
      'oldest' => t('Oldest'),
      'random' => t('Random'),
    ),
    '#default_value' => variable_get($var, UR_BLOCK_DEFAULT_SORT),
    '#required' => TRUE,
    '#weight' => 3,
    '#suffix' => t($msg, array(
      '@relationship_name' => $relationship_name,
    )),
  );
  return $form;
}