You are here

function link_field_instance_settings_form in Link 7

Implements hook_field_instance_settings_form().

File

./link.module, line 91
Defines simple link field types.

Code

function link_field_instance_settings_form($field, $instance) {
  $form = array(
    '#element_validate' => array(
      'link_field_settings_form_validate',
    ),
  );
  $form['absolute_url'] = array(
    '#type' => 'checkbox',
    '#title' => t('Absolute URL'),
    '#default_value' => isset($instance['settings']['absolute_url']) && $instance['settings']['absolute_url'] !== '' ? $instance['settings']['absolute_url'] : TRUE,
    '#description' => t('If checked, the URL will always render as an absolute URL.'),
  );
  $form['validate_url'] = array(
    '#type' => 'checkbox',
    '#title' => t('Validate URL'),
    '#default_value' => isset($instance['settings']['validate_url']) && $instance['settings']['validate_url'] !== '' ? $instance['settings']['validate_url'] : TRUE,
    '#description' => t('If checked, the URL field will be verified as a valid URL during validation.'),
  );
  $form['url'] = array(
    '#type' => 'checkbox',
    '#title' => t('Optional URL'),
    '#default_value' => isset($instance['settings']['url']) ? $instance['settings']['url'] : '',
    '#return_value' => 'optional',
    '#description' => t('If checked, the URL field is optional and submitting a title alone will be acceptable. If the URL is omitted, the title will be displayed as plain text.'),
  );
  $title_options = array(
    'optional' => t('Optional Title'),
    'required' => t('Required Title'),
    'value' => t('Static Title'),
    'select' => t('Selected Title'),
    'none' => t('No Title'),
  );
  $form['title'] = array(
    '#type' => 'radios',
    '#title' => t('Link Title'),
    '#default_value' => isset($instance['settings']['title']) ? $instance['settings']['title'] : 'optional',
    '#options' => $title_options,
    '#description' => t('If the link title is optional or required, a field will be displayed to the end user. If the link title is static, the link will always use the same title. If <a href="http://drupal.org/project/token">token module</a> is installed, the static title value may use any other entity field as its value. Static and token-based titles may include most inline XHTML tags such as <em>strong</em>, <em>em</em>, <em>img</em>, <em>span</em>, etc.'),
  );
  $form['title_value'] = array(
    '#type' => 'textfield',
    '#title' => t('Static or default title'),
    '#default_value' => isset($instance['settings']['title_value']) ? $instance['settings']['title_value'] : '',
    '#description' => t('This title will 1) always be used if "Static Title" is selected above, or 2) used if "Optional title" is selected above and no title is entered when creating content.'),
    '#states' => array(
      'visible' => array(
        ':input[name="instance[settings][title]"]' => array(
          'value' => 'value',
        ),
      ),
    ),
  );
  $form['title_allowed_values'] = array(
    '#type' => 'textarea',
    '#title' => t('Title allowed values'),
    '#default_value' => isset($instance['settings']['title_allowed_values']) ? $instance['settings']['title_allowed_values'] : '',
    '#description' => t('When using "Selected Title", you can allow users to select the title from a limited set of values (eg. Home, Office, Other). Enter here all possible values that title can take, one value per line.'),
    '#states' => array(
      'visible' => array(
        ':input[name="instance[settings][title]"]' => array(
          'value' => 'select',
        ),
      ),
    ),
  );
  $form['title_label_use_field_label'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use field label as the label for the title field'),
    '#default_value' => isset($instance['settings']['title_label_use_field_label']) ? $instance['settings']['title_label_use_field_label'] : FALSE,
    '#description' => t('If this is checked the field label will be hidden.'),
  );
  $form['title_maxlength'] = array(
    '#type' => 'textfield',
    '#title' => t('Max length of title field'),
    '#default_value' => isset($instance['settings']['title_maxlength']) ? $instance['settings']['title_maxlength'] : '128',
    '#description' => t('Set a maximum length on the title field (applies only if Link Title is optional or required).  The maximum limit is 255 characters.'),
    '#maxlength' => 3,
    '#size' => 3,
  );
  if (module_exists('token')) {

    // Add token module replacements fields.
    $form['enable_tokens'] = array(
      '#type' => 'checkbox',
      '#title' => t('Allow user-entered tokens'),
      '#default_value' => isset($instance['settings']['enable_tokens']) ? $instance['settings']['enable_tokens'] : 1,
      '#description' => t('Checking will allow users to enter tokens in URLs and Titles on the entity edit form. This does not affect the field settings on this page.'),
    );
    $entity_info = entity_get_info($instance['entity_type']);
    $form['tokens_help'] = array(
      '#theme' => 'token_tree',
      '#token_types' => array(
        $entity_info['token type'],
      ),
      '#global_types' => TRUE,
      '#click_insert' => TRUE,
      '#dialog' => TRUE,
    );
  }
  $form['convert_aliases'] = array(
    '#type' => 'checkbox',
    '#title' => t('Convert local aliases'),
    '#default_value' => isset($instance['settings']['convert_aliases']) ? $instance['settings']['convert_aliases'] : '',
    '#description' => t('If checked, a path alias is converted to the internal system path, the same way as when saving menu links.'),
  );
  $form['display'] = array(
    '#tree' => TRUE,
  );
  $form['display']['url_cutoff'] = array(
    '#type' => 'textfield',
    '#title' => t('URL Display Cutoff'),
    '#default_value' => isset($instance['settings']['display']['url_cutoff']) ? $instance['settings']['display']['url_cutoff'] : '80',
    '#description' => t('If the user does not include a title for this link, the URL will be used as the title. When should the link title be trimmed and finished with an elipsis (&hellip;)? Leave blank for no limit.'),
    '#maxlength' => 3,
    '#size' => 3,
  );

  // Target options. E.g. New window = target="_blank".
  $target_options = array(
    LINK_TARGET_DEFAULT => t('Default (no target attribute)'),
    LINK_TARGET_TOP => t('Open link in window root'),
    LINK_TARGET_NEW_WINDOW => t('Open link in new window'),
    LINK_TARGET_USER => t('Allow the user to choose'),
  );
  $form['attributes'] = array(
    '#tree' => TRUE,
  );
  $form['attributes']['target'] = array(
    '#type' => 'radios',
    '#title' => t('Link Target'),
    '#default_value' => empty($instance['settings']['attributes']['target']) ? LINK_TARGET_DEFAULT : $instance['settings']['attributes']['target'],
    '#options' => $target_options,
  );
  $form['attributes']['rel'] = array(
    '#type' => 'textfield',
    '#title' => t('Rel Attribute'),
    '#description' => t('When output, this link will have this rel attribute. The most common usage is <a href="http://en.wikipedia.org/wiki/Nofollow" target="blank">rel=&quot;nofollow&quot;</a> which prevents some search engines from spidering entered links.'),
    '#default_value' => empty($instance['settings']['attributes']['rel']) ? '' : $instance['settings']['attributes']['rel'],
    '#field_prefix' => 'rel = "',
    '#field_suffix' => '"',
    '#size' => 20,
  );
  $rel_remove_options = array(
    'default' => t('Keep rel as set up above (untouched/default)'),
    'rel_remove_external' => t('Remove rel if given link is external'),
    'rel_remove_internal' => t('Remove rel if given link is internal'),
  );
  $form['rel_remove'] = array(
    '#type' => 'radios',
    '#title' => t('Remove rel attribute automatically'),
    '#default_value' => !isset($instance['settings']['rel_remove']) ? 'default' : $instance['settings']['rel_remove'],
    '#description' => t('Turn on/off if rel attribute should be removed automatically, if user given link is internal/external'),
    '#options' => $rel_remove_options,
  );
  $form['attributes']['configurable_class'] = array(
    '#title' => t("Allow the user to enter a custom link class per link"),
    '#type' => 'checkbox',
    '#default_value' => empty($instance['settings']['attributes']['configurable_class']) ? '' : $instance['settings']['attributes']['configurable_class'],
  );
  $form['attributes']['class'] = array(
    '#type' => 'textfield',
    '#title' => t('Additional CSS Class'),
    '#description' => t('When output, this link will have this class attribute. Multiple classes should be separated by spaces. Only alphanumeric characters and hyphens are allowed'),
    '#default_value' => empty($instance['settings']['attributes']['class']) ? '' : $instance['settings']['attributes']['class'],
  );
  $form['attributes']['configurable_title'] = array(
    '#title' => t("Allow the user to enter a link 'title' attribute"),
    '#type' => 'checkbox',
    '#default_value' => empty($instance['settings']['attributes']['configurable_title']) ? '' : $instance['settings']['attributes']['configurable_title'],
  );
  $form['attributes']['title'] = array(
    '#title' => t("Default link 'title' Attribute"),
    '#type' => 'textfield',
    '#description' => t('When output, links will use this "title" attribute if the user does not provide one and when different from the link text. Read <a href="http://www.w3.org/TR/WCAG10-HTML-TECHS/#links" target="blank">WCAG 1.0 Guidelines</a> for links comformances. Tokens values will be evaluated.'),
    '#default_value' => empty($instance['settings']['attributes']['title']) ? '' : $instance['settings']['attributes']['title'],
    '#field_prefix' => 'title = "',
    '#field_suffix' => '"',
    '#size' => 20,
  );
  return $form;
}