function safeword_field_info in Safeword 8
Same name and namespace in other branches
- 7 safeword.module \safeword_field_info()
Implements hook_field_info().
Provides the description of the field.
File
- ./
safeword.module, line 48 - Provides a FieldAPI field type, widget, and several formatters for a combined human readable/machine name pair of values. Possible uses include automatic generation of editable pathauto segments, handy Views argument values, and impressing friends.
Code
function safeword_field_info() {
$field_settings = array(
'max_length' => 255,
'machine_label' => t('URL-safe'),
'machine_description' => t('A URL-safe version of the text. It may only contain lowercase letters, numbers and underscores. Leave blank to re-generate.'),
'replace_pattern' => '(--|<[^<>]+>|[^/a-z0-9-])+',
// old [^a-z0-9-]+
'replace_value' => '-',
'allow_machine_changes' => TRUE,
'unique' => FALSE,
'show_complete_path' => FALSE,
'complete_path_label' => t('Complete path'),
);
// Work out where this field is being added and adapt labels.
$path = $_GET['q'];
$path_parts = explode('/', $path);
$second_part = isset($path_parts[2]) ? $path_parts[2] : '';
switch ($second_part) {
case 'types':
$label = t('Machine name from node title');
$description = t('A field with a scrubbed machine-safe variation of the node title.');
break;
case 'taxonomy':
$label = t('Machine name from taxonomy term name');
$description = t('A field with a scrubbed machine-safe variation of the taxonomy term name.');
break;
default:
$label = t('Machine name from title');
$description = t('A field with a scrubbed machine-safe variation of the title.');
break;
}
return array(
'safeword' => array(
'label' => t('Machine name from text'),
'description' => t('A field with human readable text and a scrubbed machine-safe variation.'),
'default_widget' => 'safeword_machine_name',
'default_formatter' => 'safeword_human',
// Support default token formatter for field tokens.
'default_token_formatter' => 'safeword_machine_basic',
'property_type' => 'safeword_field',
'property_callbacks' => array(
'safeword_field_property_info_callback',
),
'settings' => $field_settings,
),
'safeword_title' => array(
'label' => $label,
'description' => $description,
'default_widget' => 'safeword_machine_name_only',
'default_formatter' => 'safeword_machine_basic',
// Support default token formatter for field tokens.
'default_token_formatter' => 'safeword_machine_basic',
'property_type' => 'safeword_field',
'property_callbacks' => array(
'safeword_field_property_info_callback',
),
'settings' => $field_settings,
),
);
}