webform_structured_text.module in Webform Structured Text 6
Same filename and directory in other branches
Main module file for Webform Structured Text.
@author Shawn Sheridan <Shawn@SDSheridan.com>
File
webform_structured_text.moduleView source
<?php
/**
* @file
* Main module file for Webform Structured Text.
*
* @author Shawn Sheridan <Shawn@SDSheridan.com>
*/
/**
* Implements hook_help().
*/
function webform_structured_text_help($section = 'admin/help#webform_structured_text', $arg = NULL) {
switch ($section) {
case 'admin/help#webform_structured_text':
// Return a line-break version of the module README.txt
return nl2br(file_get_contents(drupal_get_path('module', 'webform_structured_text') . '/README.txt'));
}
return '';
}
/**
* Implements hook_webform_component_info().
*/
function webform_structured_text_webform_component_info() {
$components = array();
$components['structured_text'] = array(
'label' => t('Structured textfield'),
'description' => t('A textfield type that uses an input mask, rendering the portions of the masked field as separate text fields.'),
'features' => array(
'csv' => TRUE,
'default_value' => TRUE,
'description' => TRUE,
'email' => TRUE,
'email_address' => FALSE,
'email_name' => TRUE,
'required' => TRUE,
'title' => TRUE,
'title_display' => TRUE,
'title_inline' => TRUE,
'conditional' => TRUE,
'group' => FALSE,
'spam_analysis' => FALSE,
'attachment' => FALSE,
),
'file' => 'structured_text.inc',
);
return $components;
}
/**********************************
* Translation-related functions.
*/
/**
* Implements hook_locale()
*/
function webform_structured_text_locale($op = 'groups') {
switch ($op) {
case 'groups':
return array(
'webform_structured_text' => t('Webform Structured Text'),
);
case 'info':
$groups['webform_structured_text'] = array(
'title' => t('Webform Structured Text'),
'description' => t('User-defined error messages and mask components for localisable webform structured text fields.'),
'format' => FALSE,
// This group doesn't have strings with format
'list' => TRUE,
// This group can list all strings
'refresh callback' => 'webform_structured_text_i18n_string_refresh',
);
return $groups;
}
}
/**
* Custom translation function for portions of the webform structured text that need to be translated.
* @param string $name The context name that will be appended to the textgroup and a colon, to be passed through i18n_string.
* @param string $string The string to be translated.
* @param string $langcode (Optional) the language code.
* @param string $textgroup (Optional - defaults to 'webform_structured_text') the textgroup to use.
* @return string The translated string.
*/
function _webform_structured_text_t($name, $string, $langcode = NULL, $textgroup = 'webform_structured_text') {
return function_exists('i18nstrings') ? i18nstrings($textgroup . ':' . $name, $string, $langcode) : $string;
}
/**
* Update translatable strings.
* @param array $component A single component for which to update or remove translations.
*/
function webform_structured_text_i18n_update_strings($component = NULL, $op = 'update') {
if (!function_exists('i18nstrings_update')) {
return;
}
$update_function = $op == 'update' ? 'i18nstrings_update' : 'i18nstrings_remove';
if (empty($component)) {
$result = db_query("SELECT nid, cid, form_key, name, extra FROM {webform_component} WHERE type = 'structured_text'");
$components = array();
while ($component = db_fetch_object($result)) {
$components[] = $component;
}
}
else {
$components = array(
(object) $component,
);
}
module_load_include('inc', 'webform_structured_text', 'structured_text');
foreach ($components as $component) {
if (!is_array($component->extra)) {
$component->extra = unserialize($component->extra);
}
// First, deal with the markup elements of the mask.
if (isset($component->extra['mask']) && !empty($component->extra['mask'])) {
$mask = webform_structured_text_parse_mask($component->extra['mask']);
foreach ($mask as $index => $part) {
if ($part['type'] == 'markup') {
$update_function("webform_structured_text:{$component->nid}:{$component->cid}:mask:{$index}", $part['value']);
}
}
}
// Next, the error messages in the RegEx
if (isset($component->extra['mask_regex']) && !empty($component->extra['mask_regex'])) {
$regex = array_filter(explode("\n", $component->extra['mask_regex']));
foreach ($regex as $line) {
list($line_numb, $error_message, $pattern) = explode('|', $line, 3);
$update_function("webform_structured_text:{$component->nid}:{$component->cid}:regex:{$line_numb}:message", trim($error_message));
}
}
}
}
/**
* Implements hook_i18n_string_refresh().
*
* Refresh translations for all user-generated strings managed by webform_structured_text.
* This will load all strings inputted via the webform_structured_text user interface and
* register them (and their translations, if there are any) with the
* i18n_strings system.
*/
function webform_structured_text_i18n_string_refresh() {
webform_structured_text_i18n_update_strings();
return TRUE;
}
Functions
Name![]() |
Description |
---|---|
webform_structured_text_help | Implements hook_help(). |
webform_structured_text_i18n_string_refresh | Implements hook_i18n_string_refresh(). |
webform_structured_text_i18n_update_strings | Update translatable strings. |
webform_structured_text_locale | Implements hook_locale() |
webform_structured_text_webform_component_info | Implements hook_webform_component_info(). |
_webform_structured_text_t | Custom translation function for portions of the webform structured text that need to be translated. |