You are here

function url_redirect_edit_form in Url Redirect 7

Implements edit form.

1 string reference to 'url_redirect_edit_form'
url_redirect_menu in ./url_redirect.module
Implements hook_menu().

File

./url_redirect_edit.inc, line 11
Adds UI for edit Url redirect path.

Code

function url_redirect_edit_form($form, &$form_state) {
  $form = array();
  $form['goto_list'] = array(
    '#markup' => l(t('Url Redirect List'), 'admin/config/url_redirect/list'),
  );
  $parameters = drupal_get_query_parameters();
  $edit_path = check_plain($parameters['path']);
  $path_data = url_redirect_path_edit($edit_path);
  if ($path_data) {
    $check_form = $path_data['check_for'];
    $form['path'] = array(
      '#type' => 'textfield',
      '#title' => t('Path'),
      '#attributes' => array(
        'placeholder' => t('Enter Path'),
      ),
      '#required' => TRUE,
      '#default_value' => $path_data['path'],
      '#disabled' => TRUE,
    );
    $form['redirect_path'] = array(
      '#type' => 'textfield',
      '#title' => t('Redirect Path'),
      '#attributes' => array(
        'placeholder' => t('Enter Redirect Path'),
      ),
      '#required' => TRUE,
      '#default_value' => $path_data['redirect_path'],
      '#description' => t('This redirect path can be internal Drupal path such as node/add Enter <front> to link to the front page.'),
    );
    $status = array(
      0 => 'Disabled',
      1 => 'Enabled',
    );
    $option = user_roles($membersonly = TRUE, $permission = NULL);
    $users = url_redirect_user_fetch();
    if ($check_form == 'Role') {
      $roles = (array) json_decode($path_data['roles']);
      $form['checked_for'] = array(
        '#type' => 'radios',
        '#options' => drupal_map_assoc(array(
          t('Role'),
        )),
        '#title' => t('Select Redirect path for'),
        '#required' => TRUE,
        '#default_value' => 'Role',
      );
      $form['roles'] = array(
        '#type' => 'select',
        '#options' => $option,
        '#title' => t('Select Roles.'),
        '#multiple' => TRUE,
        '#default_value' => $roles,
      );
    }
    if ($check_form == 'User') {
      $default_users = (array) json_decode($path_data['users']);
      $form['checked_for'] = array(
        '#type' => 'radios',
        '#options' => drupal_map_assoc(array(
          t('User'),
        )),
        '#title' => t('Select Redirect path for'),
        '#required' => TRUE,
        '#default_value' => 'User',
      );
      $form['user'] = array(
        '#type' => 'select',
        '#title' => t('Select Users.'),
        '#options' => $users,
        '#multiple' => TRUE,
        '#default_value' => $default_users,
      );
    }
    $form['message'] = array(
      '#type' => 'radios',
      '#options' => drupal_map_assoc(array(
        t('Yes'),
        t('No'),
      )),
      '#title' => t('Display Message for Redirect'),
      '#required' => TRUE,
      '#description' => t('Show a message for redirect path.'),
      '#default_value' => $path_data['message'],
    );
    $form['status'] = array(
      '#type' => 'radios',
      '#options' => $status,
      '#title' => t('Status'),
      '#required' => TRUE,
      '#default_value' => $path_data['status'],
    );
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Save'),
    );
    $form['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete'),
    );
    return $form;
  }
  else {
    drupal_set_message(t('Path Specified is not correct to update'), 'error');
  }
}