You are here

function entity_share_ui_endpoint_edit_form in Entity Share 7

Endpoint edit or create form.

Parameters

array $form: The form array.

array $form_state: The form state.

string $name: (Optional) The endpoint name.

Return value

array The form render array.

1 string reference to 'entity_share_ui_endpoint_edit_form'
entity_share_ui_client_menu in modules/entity_share_ui/modules/entity_share_ui_client/entity_share_ui_client.module
Implements hook_menu().

File

modules/entity_share_ui/modules/entity_share_ui_client/entity_share_ui_client.config.admin.inc, line 91
Entity Share UI Client Admin Configuration file.

Code

function entity_share_ui_endpoint_edit_form(array $form, array &$form_state, $name = NULL) {

  // Load endpoint data to reinject it if $name exists.
  if (!empty($name)) {
    $endpoint = EntityShareUiClientEndpoint::load($name);
    $button_name = t('Update');
    $action = 'update';
    drupal_set_title(t('Edit the endpoint @endpoint', array(
      '@endpoint' => !empty($endpoint['title']) ? $endpoint['title'] : $name,
    )));
  }
  else {
    $button_name = t('Create');
    $action = 'create';
    drupal_set_title(t('Create a new endpoint'));
  }

  // Form avec champ de type machine_name.
  $form = array();
  $form['name'] = array(
    '#type' => 'machine_name',
    '#machine_name' => array(
      'exists' => '_entity_share_ui_endpoint_name_exists',
    ),
    '#default_value' => isset($endpoint['name']) ? $endpoint['name'] : '',
    '#disabled' => !empty($endpoint['name']),
  );
  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#maxlength' => 128,
    '#required' => TRUE,
    '#default_value' => isset($endpoint['title']) ? $endpoint['title'] : '',
  );
  $form['description'] = array(
    '#type' => 'textarea',
    '#title' => t('Description'),
    '#default_value' => isset($endpoint['description']) ? $endpoint['description'] : '',
  );
  $form['url'] = array(
    '#type' => 'textfield',
    '#title' => t('Url'),
    '#maxlength' => 255,
    '#required' => TRUE,
    '#default_value' => isset($endpoint['url']) ? $endpoint['url'] : '',
  );

  // Authentication.
  $form['authentication'] = array(
    '#type' => 'fieldset',
    '#title' => t('Authentication'),
  );
  $form['authentication']['login'] = array(
    '#type' => 'textfield',
    '#title' => t('Login'),
    '#description' => t('User login to access the endpoint on the server side'),
    '#maxlength' => 128,
    '#required' => TRUE,
    '#default_value' => isset($endpoint['login']) ? $endpoint['login'] : '',
  );
  $form['authentication']['password'] = array(
    '#type' => 'password',
    '#title' => t('Password'),
    '#description' => t('User password to access the endpoint on the server side'),
    '#maxlength' => 128,
    '#required' => $action == 'create' ? TRUE : FALSE,
    '#default_value' => isset($endpoint['password']) ? $endpoint['password'] : '',
  );
  $form['enabled'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable endpoint'),
    '#default_value' => isset($endpoint['enabled']) ? $endpoint['enabled'] : 1,
  );
  $form['debug'] = array(
    '#type' => 'checkbox',
    '#title' => t('Debug mode'),
    '#default_value' => isset($endpoint['debug']) ? $endpoint['debug'] : 0,
  );
  $form['eid'] = array(
    '#type' => 'hidden',
    '#value' => isset($endpoint['eid']) ? $endpoint['eid'] : '',
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => $button_name,
    '#submit' => array(
      'entity_share_ui_endpoint_edit_form_submit',
    ),
  );
  $form['cancel'] = array(
    '#type' => 'link',
    '#title' => t('Cancel'),
    '#href' => ENDPOINT_MAIN_PATH,
  );
  return $form;
}