1.20.x link.module link_field_instance_settings_form($field, $instance)

Implements hook_field_instance_settings_form().

File

modules/link/link.module, line 54
Defines simple link field types.

Code

function link_field_instance_settings_form($field, $instance) {
  $entity_info = entity_get_info($instance['entity_type']);
  $token_types = !empty($entity_info['token type']) ? array($entity_info['token type']) : '';
  $token_link = ' ' . theme('token_tree_link', array('token_types' => $token_types));

  $form = array(
    '#element_validate' => array('link_field_settings_form_validate'),
  );

  $form['validate_url'] = array(
    '#type' => 'checkbox',
    '#title' => t('Validate URL'),
    '#default_value' => $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' => $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'),
    'none' => t('No Title'),
  );

  $form['title'] = array(
    '#type' => 'radios',
    '#title' => t('Link Title'),
    '#default_value' => $instance['settings']['title'],
    '#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.'),
  );

  $form['title_value'] = array(
    '#type' => 'textfield',
    '#title' => t('Static title'),
    '#default_value' => $instance['settings']['title_value'],
    '#description' => t('This title will always be used if &quot;Static Title&quot; is selected above. The static title value may use tokens of 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.') . $token_link,
    '#states' => array(
      'visible' => array(
        ':input[name="instance[settings][title]"]' => array('value' => 'value'),
      ),
    ),
  );

  $form['title_label_use_field_label'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use field label for title label'),
    '#default_value' => $instance['settings']['title_label_use_field_label'],
    '#description' => t('If checked, hides the label on the group of elements and instead uses the field label on the title element.'),
    '#states' => array(
      'visible' => array(
        ':input[name="instance[settings][title]"]' => array('!value' => 'none'),
      ),
    ),
  );

  $form['title_maxlength'] = array(
    '#type' => 'textfield',
    '#title' => t('Max length of title field'),
    '#default_value' => $instance['settings']['title_maxlength'],
    '#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,
    '#states' => array(
      'visible' => array(
        ':input[name="instance[settings][title]"]' => array('!value' => 'none'),
      ),
    ),
  );

  $form['advanced'] = array(
    '#type' => 'fieldset',
    '#title' => t('Advanced Options'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#parents' => array('instance', 'settings'),
  );
  $form['advanced']['enable_tokens'] = array(
    '#type' => 'checkbox',
    '#title' => t('Allow user-entered tokens'),
    '#default_value' => $instance['settings']['enable_tokens'],
    '#description' => t('Checking will allow users to enter tokens in URLs and Titles on the content form. This does not affect the field settings on this page, which always support tokens.'),
  );
  $form['advanced']['display']['url_cutoff'] = array(
    '#type' => 'textfield',
    '#title' => t('URL Display Cutoff'),
    '#default_value' => $instance['settings']['display']['url_cutoff'],
    '#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 = 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['advanced']['attributes']['target'] = array(
    '#type' => 'radios',
    '#title' => t('Link Target'),
    '#default_value' => $instance['settings']['attributes']['target'],
    '#options' => $target_options,
  );
  $form['advanced']['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">rel=&quot;nofollow&quot;</a> which prevents some search engines from spidering entered links.'),
    '#default_value' => $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['advanced']['rel_remove'] = array(
    '#type' => 'radios',
    '#title' => t('Remove rel attribute automatically'),
    '#default_value' => $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['advanced']['attributes']['configurable_class'] = array(
    '#title' => t("Allow the user to enter a custom link class per link"),
    '#type' => 'checkbox',
    '#default_value' => $instance['settings']['attributes']['configurable_class'],
  );
  $form['advanced']['attributes']['class'] = array(
    '#type' => 'textfield',
    '#title' => t('Additional CSS Classes'),
    '#description' => t('Add these classes on output (will be added to any user-provided classes). Multiple classes should be separated by spaces.'),
    '#default_value' => $instance['settings']['attributes']['class'],
  );
  $form['advanced']['attributes']['configurable_title'] = array(
    '#title' => t("Allow the user to enter a link 'title' attribute"),
    '#type' => 'checkbox',
    '#default_value' => $instance['settings']['attributes']['configurable_title'],
  );
  $form['advanced']['attributes']['title'] = array(
    '#type' => 'textfield',
    '#title' => t("Default link 'title' Attribute"),
    '#states' => array(
      'visible' => array(
        ':input[name="instance[settings][attributes][configurable_title]"]' => array('checked' => TRUE),
      ),
    ),
    '#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">WCAG 1.0 Guidelines</a> for links comformances. Tokens values will be evaluated.'),
    '#default_value' => $instance['settings']['attributes']['title'],
    '#field_prefix' => 'title = "',
    '#field_suffix' => '"',
    '#size' => 20,
  );
  return $form;
}