You are here

function user_relationships_admin_type_edit in User Relationships 7

Relationship type edit page.

1 string reference to 'user_relationships_admin_type_edit'
user_relationships_menu in ./user_relationships.module
Implements hook_menu().

File

./user_relationships.admin.inc, line 155
User Relationships admin settings and config forms

Code

function user_relationships_admin_type_edit($form, &$form_state, $relationship_type = NULL) {
  if (!$relationship_type) {
    drupal_set_title(t('Add relationship type'));
  }
  else {
    drupal_set_title(t('Edit @name relationship type', array(
      '@name' => $relationship_type->name,
    )));
  }
  $form['tabs'] = array(
    '#type' => 'vertical_tabs',
  );
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#maxlength' => 255,
    '#default_value' => isset($relationship_type) ? $relationship_type->name : NULL,
    '#description' => t("Example: buddy, friend, coworker, spouse."),
    '#required' => TRUE,
    '#weight' => -10,
  );
  $form['machine_name'] = array(
    '#type' => 'machine_name',
    '#default_value' => isset($relationship_type) ? $relationship_type->machine_name : NULL,
    '#maxlength' => 255,
    '#machine_name' => array(
      'exists' => 'user_relationships_type_machine_name_load',
    ),
    '#weight' => -9,
  );
  $form['requires_approval'] = array(
    '#type' => 'checkbox',
    '#title' => t('Requires Approval'),
    '#default_value' => isset($relationship_type->requires_approval) ? $relationship_type->requires_approval : 1,
    '#description' => t('Check this if the requestee must approve the relationship'),
    '#weight' => -8,
  );
  $form['expires_val'] = array(
    '#title' => t('Request expires in'),
    '#field_suffix' => t('days'),
    '#type' => 'textfield',
    '#size' => 4,
    '#default_value' => isset($relationship_type->expires_val) ? $relationship_type->expires_val : 0,
    '#description' => t('After how many days should a request of this type be removed? (0 for never)'),
    '#weight' => -7,
    '#states' => array(
      'visible' => array(
        ':input[name=requires_approval]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );
  $form['is_oneway'] = array(
    '#type' => 'checkbox',
    '#title' => t('This is a one-way relationship'),
    '#default_value' => isset($relationship_type) ? $relationship_type->is_oneway : NULL,
    '#description' => t('This relationship should only go one direction. This might be a manager or teacher.'),
    '#weight' => -6,
  );
  $form['is_reciprocal'] = array(
    '#type' => 'checkbox',
    '#title' => t('This one-way relationship can be reciprocated'),
    '#default_value' => isset($relationship_type) ? $relationship_type->is_reciprocal : NULL,
    '#description' => t('The user who receives this request can create an additional one-way relationship back to the requester. This might be a follower or subscriber.'),
    '#weight' => -5,
    '#states' => array(
      'visible' => array(
        ':input[name=is_oneway]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );
  $form['branding'] = array(
    '#type' => 'fieldset',
    '#title' => t('Branding'),
    '#group' => 'tabs',
  );
  $form['branding']['plural_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Plural name'),
    '#maxlength' => 255,
    '#default_value' => isset($relationship_type->plural_name) ? $relationship_type->plural_name : NULL,
    '#description' => t("Example: buddies, friends, coworkers, spouses."),
    '#weight' => 2,
  );
  $form['branding']['name_capitalized'] = array(
    '#type' => 'textfield',
    '#title' => t('Capitalized name'),
    '#maxlength' => 255,
    '#default_value' => isset($relationship_type) ? $relationship_type->name_capitalized : NULL,
    '#description' => t("Example: buddies, friends, coworkers, spouses."),
    '#weight' => 6,
  );
  $form['branding']['plural_name_capitalized'] = array(
    '#type' => 'textfield',
    '#title' => t('Capitalized plural name'),
    '#maxlength' => 255,
    '#default_value' => isset($relationship_type) ? $relationship_type->plural_name_capitalized : NULL,
    '#description' => t("Example: buddies, friends, coworkers, spouses."),
    '#weight' => 10,
  );

  // #states doesn't work on a vertical tab fieldset, hide each input element
  // separately.
  $form['reverse_branding'] = array(
    '#type' => 'fieldset',
    '#title' => t('One-way reverse branding'),
    '#group' => 'tabs',
    '#description' => t('One-way reversed branding is only used when this relationship type only goes one way. Then, these names are used when displaying relationships initiated by other users.'),
    // Doesn't work properly yet.
    '#states' => array(
      'visible' => array(
        ':input[name=is_oneway]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );
  $form['reverse_branding']['reverse_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#maxlength' => 255,
    '#default_value' => isset($relationship_type) ? $relationship_type->reverse_name : NULL,
    '#description' => t("Example: buddies, friends, coworkers, spouses."),
    '#weight' => 0,
  );
  $form['reverse_branding']['reverse_plural_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Plural name'),
    '#maxlength' => 255,
    '#default_value' => isset($relationship_type) ? $relationship_type->reverse_plural_name : NULL,
    '#description' => t("Example: buddies, friends, coworkers, spouses."),
    '#weight' => 4,
  );
  $form['reverse_branding']['reverse_name_capitalized'] = array(
    '#type' => 'textfield',
    '#title' => t('Capitalized name'),
    '#maxlength' => 255,
    '#default_value' => isset($relationship_type) ? $relationship_type->reverse_name_capitalized : NULL,
    '#description' => t("Example: buddies, friends, coworkers, spouses."),
    '#weight' => 8,
  );
  $form['reverse_branding']['reverse_plural_name_capitalized'] = array(
    '#type' => 'textfield',
    '#title' => t('Capitalized plural name'),
    '#maxlength' => 255,
    '#default_value' => isset($relationship_type) ? $relationship_type->reverse_plural_name_capitalized : NULL,
    '#description' => t("Example: buddies, friends, coworkers, spouses."),
    '#weight' => 12,
  );
  $form['rtid'] = array(
    '#type' => 'value',
    '#value' => isset($relationship_type->rtid) ? (int) $relationship_type->rtid : NULL,
  );
  $form['action'] = array(
    '#type' => 'value',
    '#value' => isset($relationship_type->rtid) ? 'edit' : 'add',
  );
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => isset($relationship_type->rtid) ? t('Save relationship type') : t('Add relationship type'),
    '#weight' => 0,
  );
  if (module_exists('i18n_string')) {
    $form['actions']['translate'] = array(
      '#type' => 'submit',
      '#name' => 'save_translate',
      '#value' => isset($relationship_type->rtid) ? t('Save and translate') : t('Add and translate'),
      '#weight' => 5,
    );
  }
  return $form;
}