function link_field_settings in Link 6
Same name and namespace in other branches
- 5 link.module \link_field_settings()
- 6.2 link.module \link_field_settings()
Implementation of hook_field_settings().
File
- ./
link.module, line 29 - Defines simple link field types.
Code
function link_field_settings($op, $field) {
switch ($op) {
case 'form':
$form = array(
'#theme' => 'link_field_settings',
);
$form['url'] = array(
'#type' => 'checkbox',
'#title' => t('Optional URL'),
'#default_value' => $field['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 ommitted, 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' => isset($field['title']) ? $field['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 node 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',
'#default_value' => $field['title_value'],
'#size' => '46',
);
// Add token module replacements if available
if (module_exists('token')) {
$form['tokens'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#title' => t('Placeholder tokens'),
'#description' => t("The following placeholder tokens can be used in both paths and titles. When used in a path or title, they will be replaced with the appropriate values."),
);
$form['tokens']['help'] = array(
'#value' => theme('token_help', 'node'),
);
$form['enable_tokens'] = array(
'#type' => 'checkbox',
'#title' => t('Allow user-entered tokens'),
'#default_value' => isset($field['enable_tokens']) ? $field['enable_tokens'] : 1,
'#description' => t('Checking will allow users to enter tokens in URLs and Titles on the node edit form. This does not affect the field settings on this page.'),
);
}
$form['display'] = array(
'#tree' => TRUE,
);
$form['display']['url_cutoff'] = array(
'#type' => 'textfield',
'#title' => t('URL Display Cutoff'),
'#default_value' => isset($field['display']['url_cutoff']) ? $field['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 (…)? Leave blank for no limit.'),
'#maxlength' => 3,
'#size' => 3,
);
$target_options = array(
'default' => t('Default (no target attribute)'),
'_top' => t('Open link in window root'),
'_blank' => t('Open link in new window'),
'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($field['attributes']['target']) ? 'default' : $field['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">rel="nofollow"</a> which prevents some search engines from spidering entered links.'),
'#default_value' => empty($field['attributes']['rel']) ? '' : $field['attributes']['rel'],
'#field_prefix' => 'rel = "',
'#field_suffix' => '"',
'#size' => 20,
);
$form['attributes']['class'] = array(
'#type' => 'textfield',
'#title' => t('Additional CSS Class'),
'#description' => t('When output, this link will have have this class attribute. Multiple classes should be separated by spaces.'),
'#default_value' => empty($field['attributes']['class']) ? '' : $field['attributes']['class'],
);
return $form;
case 'validate':
if ($field['title'] == 'value' && empty($field['title_value'])) {
form_set_error('title_value', t('A default title must be provided if the title is a static value'));
}
break;
case 'save':
return array(
'attributes',
'display',
'url',
'title',
'title_value',
'enable_tokens',
);
case 'database columns':
return array(
'url' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'sortable' => TRUE,
),
'title' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'sortable' => TRUE,
),
'attributes' => array(
'type' => 'text',
'size' => 'medium',
'not null' => FALSE,
),
);
case 'views data':
module_load_include('inc', 'link', 'views/link.views');
return link_views_content_field_data($field);
}
}