Пример #1
0
/**
 * @param $form
 * @param $form_state
 */
function realia_form_system_theme_settings_alter(&$form, $form_state)
{
    include 'template.php';
    $form['theme_realia_settings'] = array('#type' => 'fieldset', '#title' => t('Realia settings'));
    $groups = realia_aviators_collect_styles();
    foreach ($groups as $group_id => $group) {
        $options = array();
        foreach ($group['css'] as $delta => $css) {
            $options[$delta] = $css['label'];
        }
        $setting = theme_get_setting($group_id);
        $form['theme_realia_settings'][$group_id] = array('#type' => 'radios', '#title' => $group['label'], '#id' => str_replace('_', '-', $group_id . '-' . $delta), '#options' => $options, '#default_value' => !empty($setting) ? $setting : reset(array_keys($options)));
        $currency = theme_get_setting('currency');
        $form['theme_realia_settings']['currency'] = array('#type' => 'textfield', '#title' => t('Currency'), '#size' => 6, '#default_value' => !empty($currency) ? $currency : 'USD', '#description' => t('Please enter <b>valid</b> currency code'), '#weight' => 20);
        $prefix_currency = theme_get_setting('prefix_currency');
        $form['theme_realia_settings']['prefix_currency'] = array('#type' => 'checkbox', '#title' => t('Prefix currency'), '#default_value' => isset($prefix_currency) ? $prefix_currency : true, '#weight' => 21, '#description' => t('If not checked, currency will display as suffix'));
    }
}
Пример #2
0
function realia_form_element($variables)
{
    $element =& $variables['element'];
    // This function is invoked as theme wrapper, but the rendered form element
    // may not necessarily have been processed by form_builder().
    $element += array('#title_display' => 'before');
    // Add element #id for #type 'item'.
    if (isset($element['#markup']) && !empty($element['#id'])) {
        $attributes['id'] = $element['#id'];
    }
    // Add element's #type and #name as class to aid with JS/CSS selectors.
    $attributes['class'] = array('form-item');
    if (!empty($element['#type'])) {
        $attributes['class'][] = 'form-type-' . strtr($element['#type'], '_', '-');
    }
    if (!empty($element['#name'])) {
        $attributes['class'][] = 'form-item-' . strtr($element['#name'], array(' ' => '-', '_' => '-', '[' => '-', ']' => ''));
    }
    // Add a class for disabled elements to facilitate cross-browser styling.
    if (!empty($element['#attributes']['disabled'])) {
        $attributes['class'][] = 'form-disabled';
    }
    $label = TRUE;
    if ($element['#type'] == 'radio') {
        $styles = realia_aviators_collect_styles();
        if (in_array($element['#array_parents'][0], array_keys($styles))) {
            $label = FALSE;
            if (isset($element['#return_value'])) {
                $attributes['class'][] = str_replace('_', '-', $element['#return_value']);
            }
        }
    }
    if (!$label) {
        $element_output = '<div' . drupal_attributes($attributes) . '>';
    } else {
        $output = '<div' . drupal_attributes($attributes) . '>' . "\n";
    }
    if ($element['#type'] == 'radio') {
        if (!$label) {
            $element = $variables['element'];
            // This is also used in the installer, pre-database setup.
            $t = get_t();
            // If the element is required, a required marker is appended to the label.
            $required = !empty($element['#required']) ? theme('form_required_marker', array('element' => $element)) : '';
            $title = filter_xss_admin($element['#title']);
            $attributes = array();
            // Style the label as class option to display inline with the element.
            if ($element['#title_display'] == 'after') {
                $attributes['class'] = 'option';
            } elseif ($element['#title_display'] == 'invisible') {
                $attributes['class'] = 'element-invisible';
            }
            if (!empty($element['#id'])) {
                $attributes['for'] = $element['#id'];
            }
            // The leading whitespace helps visually separate fields from inline labels.
            $output = $element_output . '<label' . drupal_attributes($attributes) . '>' . $element['#children'] . $t('!title !required', array('!title' => $title, '!required' => $required)) . "</label>";
            if (!empty($element['#description'])) {
                $output .= '<div class="description">' . $element['#description'] . "</div>\n";
            }
            $output .= "</div>\n";
        }
    }
    // If #title is not set, we don't display any label or required marker.
    if (!isset($element['#title'])) {
        $element['#title_display'] = 'none';
    }
    $prefix = isset($element['#field_prefix']) ? '<span class="field-prefix">' . $element['#field_prefix'] . '</span> ' : '';
    $suffix = isset($element['#field_suffix']) ? ' <span class="field-suffix">' . $element['#field_suffix'] . '</span>' : '';
    if ($label) {
        switch ($element['#title_display']) {
            case 'before':
            case 'invisible':
                $output .= ' ' . theme('form_element_label', $variables);
                $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
                break;
            case 'after':
                $output .= ' ' . $prefix . $element['#children'] . $suffix;
                $output .= ' ' . theme('form_element_label', $variables) . "\n";
                break;
            case 'none':
            case 'attribute':
                // Output no label and no required marker, only the children.
                $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
                break;
        }
    }
    if ($label) {
        if (!empty($element['#description'])) {
            $output .= '<div class="description">' . $element['#description'] . "</div>\n";
        }
        $output .= "</div>\n";
    }
    return $output;
}