function boostrapdrupal_textfield($variables) { $element = $variables['element']; $output = ''; if ($element['#name'] == 'name' && current_path() == 'user/login') { $output = '<div class="input-group"><span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>'; } $element['#attributes']['type'] = 'text'; if (isset($variables['element']['#description'])) { $element['#attributes']['placeholder'] = $variables['element']['#description']; } element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength')); _form_set_class($element, array('form-text', 'form-control', 'input-lg-3')); $extra = ''; if ($element['#autocomplete_path'] && drupal_valid_path($element['#autocomplete_path'])) { drupal_add_library('system', 'drupal.autocomplete'); $element['#attributes']['class'][] = 'form-autocomplete'; $attributes = array(); $attributes['type'] = 'hidden'; $attributes['id'] = $element['#attributes']['id'] . '-autocomplete'; $attributes['value'] = url($element['#autocomplete_path'], array('absolute' => TRUE)); $attributes['disabled'] = 'disabled'; $attributes['class'][] = 'autocomplete'; $extra = '<input' . drupal_attributes($attributes) . ' />'; } $output .= '<input' . drupal_attributes($element['#attributes']) . ' />'; if ($element['#name'] == 'name' && current_path() == 'user/login') { $output .= '</div>'; } return $output . $extra; }
/** * Overrides theme_textfield(). */ function bootstrap_sst_textfield($variables) { $element = $variables['element']; $element['#attributes']['type'] = 'text'; element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength')); _form_set_class($element, array('form-text')); $output = '<input' . drupal_attributes($element['#attributes']) . ' />'; $extra = ''; if ($element['#autocomplete_path'] && drupal_valid_path($element['#autocomplete_path'])) { drupal_add_library('system', 'drupal.autocomplete'); $element['#attributes']['class'][] = 'form-autocomplete'; $attributes = array(); $attributes['type'] = 'hidden'; $attributes['id'] = $element['#attributes']['id'] . '-autocomplete'; $attributes['value'] = url($element['#autocomplete_path'], array('absolute' => TRUE)); $attributes['disabled'] = 'disabled'; $attributes['class'][] = 'autocomplete'; // Uses icon for autocomplete "throbber". if ($icon = _bootstrap_icon('refresh')) { $output = '<div class="input-group">' . $output . '<span class="input-group-addon">' . $icon . '</span></div>'; } else { $output = '<div class="input-group">' . $output . '<span class="input-group-addon">'; // The throbber's background image must be set here because sites may not // be at the root of the domain (ie: /) and this value cannot be set via // CSS. $output .= '<span class="autocomplete-throbber" style="background-image:url(' . url('misc/throbber.gif') . ')"></span>'; $output .= '</span></div>'; } $extra = '<input' . drupal_attributes($attributes) . ' />'; } return $output . $extra; }
/** * Overrides theme_textfield(). */ function evolve_textfield($variables) { $element = $variables['element']; $element['#attributes']['type'] = 'text'; element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength')); _form_set_class($element, array('form-text')); $output = '<input' . drupal_attributes($element['#attributes']) . ' />'; $extra = ''; if ($element['#autocomplete_path'] && drupal_valid_path($element['#autocomplete_path'])) { drupal_add_library('system', 'drupal.autocomplete'); $element['#attributes']['class'][] = 'form-autocomplete'; $attributes = array(); $attributes['type'] = 'hidden'; $attributes['id'] = $element['#attributes']['id'] . '-autocomplete'; $attributes['value'] = url($element['#autocomplete_path'], array('absolute' => TRUE)); $attributes['disabled'] = 'disabled'; $attributes['class'][] = 'autocomplete'; $output = '<div class="input-group">' . $output . '<span class="input-group-addon">' . _bootstrap_icon('refresh') . '</span></div>'; $extra = '<input' . drupal_attributes($attributes) . ' />'; } return $output . $extra; }
/** * Overrides theme_form_element(). */ function bootstrap_form_element(&$variables) { $element =& $variables['element']; $is_checkbox = FALSE; $is_radio = FALSE; // 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']; } // Check for errors and set correct error class. if (isset($element['#parents']) && form_get_error($element)) { $attributes['class'][] = 'error'; } 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'; } if (!empty($element['#autocomplete_path']) && drupal_valid_path($element['#autocomplete_path'])) { $attributes['class'][] = 'form-autocomplete'; } $attributes['class'][] = 'form-item'; // See http://getbootstrap.com/css/#forms-controls. if (isset($element['#type'])) { if ($element['#type'] == "radio") { $attributes['class'][] = 'radio'; $is_radio = TRUE; } elseif ($element['#type'] == "checkbox") { $attributes['class'][] = 'checkbox'; $is_checkbox = TRUE; } else { $attributes['class'][] = 'form-group'; } } $description = FALSE; $tooltip = FALSE; // Convert some descriptions to tooltips. // @see bootstrap_tooltip_descriptions setting in _bootstrap_settings_form() if (!empty($element['#description'])) { $description = $element['#description']; if (theme_get_setting('bootstrap_tooltip_enabled') && theme_get_setting('bootstrap_tooltip_descriptions') && $description === strip_tags($description) && strlen($description) <= 200) { $tooltip = TRUE; $attributes['data-toggle'] = 'tooltip'; $attributes['title'] = $description; } } $output = '<div' . drupal_attributes($attributes) . '>' . "\n"; // If #title is not set, we don't display any label or required marker. if (!isset($element['#title'])) { $element['#title_display'] = 'none'; } $prefix = ''; $suffix = ''; if (isset($element['#field_prefix']) || isset($element['#field_suffix'])) { // Determine if "#input_group" was specified. if (!empty($element['#input_group'])) { $prefix .= '<div class="input-group">'; $prefix .= isset($element['#field_prefix']) ? '<span class="input-group-addon">' . $element['#field_prefix'] . '</span>' : ''; $suffix .= isset($element['#field_suffix']) ? '<span class="input-group-addon">' . $element['#field_suffix'] . '</span>' : ''; $suffix .= '</div>'; } else { $prefix .= isset($element['#field_prefix']) ? $element['#field_prefix'] : ''; $suffix .= isset($element['#field_suffix']) ? $element['#field_suffix'] : ''; } } switch ($element['#title_display']) { case 'before': case 'invisible': $output .= ' ' . theme('form_element_label', $variables); $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n"; break; case 'after': if ($is_radio || $is_checkbox) { $output .= ' ' . $prefix . $element['#children'] . $suffix; } else { $variables['#children'] = ' ' . $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 ($description && !$tooltip) { $output .= '<p class="help-block">' . $element['#description'] . "</p>\n"; } $output .= "</div>\n"; return $output; }
/** * Implements theme_textfield(). */ function foundation_access_textfield($variables) { $element = $variables['element']; $element['#attributes']['type'] = 'text'; element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength')); $extra = ''; if ($element['#autocomplete_path'] && drupal_valid_path($element['#autocomplete_path'])) { drupal_add_library('system', 'drupal.autocomplete'); $element['#attributes']['class'][] = 'form-autocomplete'; $attributes = array(); $attributes['type'] = 'hidden'; $attributes['id'] = $element['#attributes']['id'] . '-autocomplete'; $attributes['value'] = url($element['#autocomplete_path'], array('absolute' => TRUE)); $attributes['disabled'] = 'disabled'; $attributes['class'][] = 'autocomplete'; $extra = '<input' . drupal_attributes($attributes) . ' />'; } $output = '<input' . drupal_attributes($element['#attributes']) . ' />'; return $output . $extra; }
/** * Overrides theme_form_element(). */ function europa_form_element(&$variables) { $element =& $variables['element']; $is_checkbox = FALSE; $is_radio = FALSE; $feedback_message = FALSE; // 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']; } // Check for errors and set correct error class. if (isset($element['#parents']) && form_get_error($element)) { $attributes['class'][] = 'has-error'; $feedback_message = '<p class="feedback-message is-error">' . form_get_error($element) . '</p>'; } 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'; } if (!empty($element['#autocomplete_path']) && drupal_valid_path($element['#autocomplete_path'])) { $attributes['class'][] = 'form-autocomplete'; } $attributes['class'][] = 'form-item'; // See http://getbootstrap.com/css/#forms-controls. if (isset($element['#type'])) { if ($element['#type'] == "radio") { $attributes['class'][] = 'radio'; $is_radio = TRUE; } elseif ($element['#type'] == "checkbox") { $attributes['class'][] = 'checkbox'; $is_checkbox = TRUE; } else { $attributes['class'][] = 'form-group'; } } // Putting description into variable since it is not going to change. // Here Bootstrap tooltips have been removed since in current implemenation we // will use descriptions that are displayed under <label> element. if (!empty($element['#description'])) { $description = '<p class="help-block">' . $element['#description'] . '</p>'; } $output = '<div' . drupal_attributes($attributes) . '>' . "\n"; // If #title is not set, we don't display any label or required marker. if (!isset($element['#title'])) { $element['#title_display'] = 'none'; } $prefix = ''; $suffix = ''; if (isset($element['#field_prefix']) || isset($element['#field_suffix'])) { // Determine if "#input_group" was specified. if (!empty($element['#input_group'])) { $prefix .= '<div class="input-group">'; $prefix .= isset($element['#field_prefix']) ? '<span class="input-group-addon">' . $element['#field_prefix'] . '</span>' : ''; $suffix .= isset($element['#field_suffix']) ? '<span class="input-group-addon">' . $element['#field_suffix'] . '</span>' : ''; $suffix .= '</div>'; } else { $prefix .= isset($element['#field_prefix']) ? $element['#field_prefix'] : ''; $suffix .= isset($element['#field_suffix']) ? $element['#field_suffix'] : ''; } } switch ($element['#title_display']) { case 'before': case 'invisible': $output .= ' ' . theme('form_element_label', $variables); if (!empty($description)) { $output .= $description; } $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n"; //if (form_get_error($element)) { $output .= $feedback_message; //} break; case 'after': if ($is_radio || $is_checkbox) { $output .= ' ' . $prefix . $element['#children'] . $suffix; } else { $variables['#children'] = ' ' . $prefix . $element['#children'] . $suffix; } $output .= ' ' . theme('form_element_label', $variables) . "\n"; //if (form_get_error($element)) { $output .= $feedback_message; //} break; case 'none': case 'attribute': // Output no label and no required marker, only the children. if (!empty($description)) { $output .= $description; } $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n"; //if (form_get_error($element)) { $output .= $feedback_message; //} break; } $output .= "</div>\n"; return $output; }
/** * {@inheritdoc} */ public function validateForm(array &$form, array &$form_state) { $source =& $form_state['values']['source']; $source = $this->aliasManager->getPathByAlias($source); $alias = $form_state['values']['alias']; // Language is only set if language.module is enabled, otherwise save for all // languages. $langcode = isset($form_state['values']['langcode']) ? $form_state['values']['langcode'] : LanguageInterface::LANGCODE_NOT_SPECIFIED; if ($this->aliasStorage->aliasExists($alias, $langcode, $source)) { $this->setFormError('alias', $form_state, t('The alias %alias is already in use in this language.', array('%alias' => $alias))); } if (!drupal_valid_path($source)) { $this->setFormError('source', $form_state, t("The path '@link_path' is either invalid or you do not have access to it.", array('@link_path' => $source))); } }
function mothership_textfield($variables) { $element = $variables['element']; $element['#size'] = '30'; //is this element requred then lest add the required element into the input $required = !empty($element['#required']) ? ' required' : ''; //dont need to set type in html5 its default so lets remove it because we can $element['#attributes']['type'] = 'text'; //placeholder if (!empty($element['#title']) and theme_get_setting('mothership_classes_form_placeholder_label')) { $element['#attributes']['placeholder'] = $element['#title']; } element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength')); //remove the form-text class if (!theme_get_setting('mothership_classes_form_input')) { _form_set_class($element, array('form-text')); } $extra = ''; if ($element['#autocomplete_path'] && drupal_valid_path($element['#autocomplete_path'])) { drupal_add_library('system', 'drupal.autocomplete'); $element['#attributes']['class'][] = 'form-autocomplete'; $attributes = array(); $attributes['type'] = 'hidden'; $attributes['id'] = $element['#attributes']['id'] . '-autocomplete'; $attributes['value'] = url($element['#autocomplete_path'], array('absolute' => TRUE)); $attributes['disabled'] = 'disabled'; $attributes['class'][] = 'autocomplete'; $extra = '<input' . drupal_attributes($attributes) . $required . ' />'; } $output = '<input' . drupal_attributes($element['#attributes']) . $required . ' />'; return $output . $extra; }
/** * Overrides EntityForm::validate(). */ public function validate(array $form, array &$form_state) { $menu_link = $this->buildEntity($form, $form_state); $normal_path = $this->pathAliasManager->getPathByAlias($menu_link->link_path); if ($menu_link->link_path != $normal_path) { drupal_set_message(t('The menu system stores system paths only, but will use the URL alias for display. %link_path has been stored as %normal_path', array('%link_path' => $menu_link->link_path, '%normal_path' => $normal_path))); $menu_link->link_path = $normal_path; $form_state['values']['link_path'] = $normal_path; } if (!UrlHelper::isExternal($menu_link->link_path)) { $parsed_link = parse_url($menu_link->link_path); if (isset($parsed_link['query'])) { $menu_link->options['query'] = array(); parse_str($parsed_link['query'], $menu_link->options['query']); } else { // Use unset() rather than setting to empty string // to avoid redundant serialized data being stored. unset($menu_link->options['query']); } if (isset($parsed_link['fragment'])) { $menu_link->options['fragment'] = $parsed_link['fragment']; } else { unset($menu_link->options['fragment']); } if (isset($parsed_link['path']) && $menu_link->link_path != $parsed_link['path']) { $menu_link->link_path = $parsed_link['path']; } } if (!trim($menu_link->link_path) || !drupal_valid_path($menu_link->link_path, TRUE)) { $this->setFormError('link_path', $form_state, $this->t("The path '@link_path' is either invalid or you do not have access to it.", array('@link_path' => $menu_link->link_path))); } parent::validate($form, $form_state); }
/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { // Check for empty front page path. if (empty($form_state['values']['site_frontpage'])) { // Set to default "user". form_set_value($form['front_page']['site_frontpage'], 'user', $form_state); } else { // Get the normal path of the front page. form_set_value($form['front_page']['site_frontpage'], $this->aliasManager->getPathByAlias($form_state['values']['site_frontpage']), $form_state); } // Validate front page path. if (!drupal_valid_path($form_state['values']['site_frontpage'])) { $form_state->setErrorByName('site_frontpage', $this->t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state['values']['site_frontpage']))); } // Get the normal paths of both error pages. if (!empty($form_state['values']['site_403'])) { form_set_value($form['error_page']['site_403'], $this->aliasManager->getPathByAlias($form_state['values']['site_403']), $form_state); } if (!empty($form_state['values']['site_404'])) { form_set_value($form['error_page']['site_404'], $this->aliasManager->getPathByAlias($form_state['values']['site_404']), $form_state); } // Validate 403 error path. if (!empty($form_state['values']['site_403']) && !drupal_valid_path($form_state['values']['site_403'])) { $form_state->setErrorByName('site_403', $this->t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state['values']['site_403']))); } // Validate 404 error path. if (!empty($form_state['values']['site_404']) && !drupal_valid_path($form_state['values']['site_404'])) { $form_state->setErrorByName('site_404', $this->t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state['values']['site_404']))); } parent::validateForm($form, $form_state); }
/** * Returns HTML for a form element. * * Each form element is wrapped in a DIV container having the following CSS * classes: * - form-item: Generic for all form elements. * - form-type-#type: The internal element #type. * - form-item-#name: The internal form element #name (usually derived from the * $form structure and set via form_builder()). * - form-disabled: Only set if the form element is #disabled. * * In addition to the element itself, the DIV contains a label for the element * based on the optional #title_display property, and an optional #description. * * The optional #title_display property can have these values: * - before: The label is output before the element. This is the default. * The label includes the #title and the required marker, if #required. * - after: The label is output after the element. For example, this is used * for radio and checkbox #type elements as set in system_element_info(). * If the #title is empty but the field is #required, the label will * contain only the required marker. * - invisible: Labels are critical for screen readers to enable them to * properly navigate through forms but can be visually distracting. This * property hides the label for everyone except screen readers. * - attribute: Set the title attribute on the element to create a tooltip * but output no label element. This is supported only for checkboxes * and radios in form_pre_render_conditional_form_element(). It is used * where a visual label is not needed, such as a table of checkboxes where * the row and column provide the context. The tooltip will include the * title and required marker. * * If the #title property is not set, then the label and any required marker * will not be output, regardless of the #title_display or #required values. * This can be useful in cases such as the password_confirm element, which * creates children elements that have their own labels and required markers, * but the parent element should have neither. Use this carefully because a * field without an associated label can cause accessibility challenges. * * @param array $variables * An associative array containing: * - element: An associative array containing the properties of the element. * Properties used: #title, #title_display, #description, #id, #required, * #children, #type, #name. * * @return string * The constructed HTML. * * @see theme_form_element() * * @ingroup theme_functions */ function bootstrap_form_element(&$variables) { $element =& $variables['element']; $name = !empty($element['#name']) ? $element['#name'] : FALSE; $type = !empty($element['#type']) ? $element['#type'] : FALSE; $checkbox = $type && $type === 'checkbox'; $radio = $type && $type === 'radio'; // Create an attributes array for the wrapping container. if (empty($element['#wrapper_attributes'])) { $element['#wrapper_attributes'] = array(); } $wrapper_attributes =& $element['#wrapper_attributes']; // 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 wrapper ID for 'item' type. if ($type && $type === 'item' && !empty($element['#markup']) && !empty($element['#id'])) { $wrapper_attributes['id'] = $element['#id']; } // Check for errors and set correct error class. if (isset($element['#parents']) && form_get_error($element) || !empty($element['#required']) && bootstrap_setting('forms_required_has_error')) { $wrapper_attributes['class'][] = 'has-error'; } // Add necessary classes to wrapper container. $wrapper_attributes['class'][] = 'form-item'; if ($name) { $wrapper_attributes['class'][] = 'form-item-' . drupal_html_class($name); } if ($type) { $wrapper_attributes['class'][] = 'form-type-' . drupal_html_class($type); } if (!empty($element['#attributes']['disabled'])) { $wrapper_attributes['class'][] = 'form-disabled'; } if (!empty($element['#autocomplete_path']) && drupal_valid_path($element['#autocomplete_path'])) { $wrapper_attributes['class'][] = 'form-autocomplete'; } // Checkboxes and radios do no receive the 'form-group' class, instead they // simply have their own classes. if ($checkbox || $radio) { $wrapper_attributes['class'][] = drupal_html_class($type); } elseif ($type && $type !== 'hidden') { $wrapper_attributes['class'][] = 'form-group'; } // Create a render array for the form element. $build = array('#theme_wrappers' => array('container__form_element'), '#attributes' => $wrapper_attributes); // Render the label for the form element. $build['label'] = array('#markup' => theme('form_element_label', $variables)); // Increase the label weight if it should be displayed after the element. if ($element['#title_display'] === 'after') { $build['label']['#weight'] = 10; } // Checkboxes and radios render the input element inside the label. If the // element is neither of those, then the input element must be rendered here. if (!$checkbox && !$radio) { $prefix = isset($element['#field_prefix']) ? $element['#field_prefix'] : ''; $suffix = isset($element['#field_suffix']) ? $element['#field_suffix'] : ''; if ((!empty($prefix) || !empty($suffix)) && (!empty($element['#input_group']) || !empty($element['#input_group_button']))) { if (!empty($element['#field_prefix'])) { $prefix = '<span class="input-group-' . (!empty($element['#input_group_button']) ? 'btn' : 'addon') . '">' . $prefix . '</span>'; } if (!empty($element['#field_suffix'])) { $suffix = '<span class="input-group-' . (!empty($element['#input_group_button']) ? 'btn' : 'addon') . '">' . $suffix . '</span>'; } // Add a wrapping container around the elements. $input_group_attributes =& _bootstrap_get_attributes($element, 'input_group_attributes'); $input_group_attributes['class'][] = 'input-group'; $prefix = '<div' . drupal_attributes($input_group_attributes) . '>' . $prefix; $suffix .= '</div>'; } // Build the form element. $build['element'] = array('#markup' => $element['#children'], '#prefix' => !empty($prefix) ? $prefix : NULL, '#suffix' => !empty($suffix) ? $suffix : NULL); } // Construct the element's description markup. if (!empty($element['#description'])) { $build['description'] = array('#type' => 'container', '#attributes' => array('class' => array('help-block')), '#weight' => 20, 0 => array('#markup' => filter_xss_admin($element['#description']))); } // Render the form element build array. return drupal_render($build); }
function neb_textfield($variables) { $element = $variables['element']; $element['#size'] = '30'; //is this element requred then lest add the required element into the input $required = !empty($element['#required']) ? ' required' : ''; element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength')); $extra = ''; if ($element['#autocomplete_path'] && drupal_valid_path($element['#autocomplete_path'])) { drupal_add_library('system', 'drupal.autocomplete'); $element['#attributes']['class'][] = 'form-autocomplete'; $attributes = array(); $attributes['type'] = 'hidden'; $attributes['id'] = $element['#attributes']['id'] . '-autocomplete'; $attributes['value'] = url($element['#autocomplete_path'], array('absolute' => TRUE)); $attributes['disabled'] = 'disabled'; $attributes['class'][] = 'autocomplete'; $extra = '<input' . drupal_attributes($attributes) . $required . ' />'; } $output = '<input' . drupal_attributes($element['#attributes']) . $required . ' />'; return $output . $extra; }
<?php $element = $variables['element']; $element['#attributes']['type'] = 'text'; element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength')); _form_set_class($element, array('form-control')); $extra = ''; if ($element['#autocomplete_path'] && drupal_valid_path($element['#autocomplete_path'])) { drupal_add_library('system', 'drupal.autocomplete'); $element['#attributes']['class'][] = 'form-autocomplete'; $attributes = array(); $attributes['type'] = 'hidden'; $attributes['id'] = $element['#attributes']['id'] . '-autocomplete'; $attributes['value'] = url($element['#autocomplete_path'], array('absolute' => TRUE)); $attributes['disabled'] = 'disabled'; $attributes['class'][] = 'autocomplete'; $extra = '<input' . drupal_attributes($attributes) . ' />'; } // Add aria-describedby attribute for screen readers. if (!empty($element['#description'])) { $element['#attributes']['aria-describedby'] = 'help-' . $element['#id']; } $output = ''; if ($element['#autocomplete_path'] && drupal_valid_path($element['#autocomplete_path'])) { $output .= '<div class="has-autocomplete has-feedback">'; } $output .= '<input' . drupal_attributes($element['#attributes']) . ' />'; if ($element['#autocomplete_path'] && drupal_valid_path($element['#autocomplete_path'])) { $output .= '<span class="glyphicon glyphicon-refresh form-control-feedback" aria-hidden="true"></span></div>'; } print $output . $extra;
/** * Implements theme_textfield(). */ function hasta_textfield($variables) { $element = $variables['element']; $element['#attributes']['type'] = isset($element['#attributes']['type']) ? $element['#attributes']['type'] : 'text'; if (!isset($element['#attributes']['class']) || !is_array($element['#attributes']['class']) || !in_array('class-lock', $element['#attributes']['class'])) { $element['#attributes']['class'][] = 'gui-input'; } element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength')); $output = '<input' . drupal_attributes($element['#attributes']) . ' />'; $extra = ''; if ($element['#autocomplete_path'] && drupal_valid_path($element['#autocomplete_path'])) { drupal_add_library('system', 'drupal.autocomplete'); $element['#attributes']['class'][] = 'form-autocomplete'; $attributes = array(); $attributes['type'] = 'hidden'; $attributes['id'] = $element['#attributes']['id'] . '-autocomplete'; $attributes['value'] = url($element['#autocomplete_path'], array('absolute' => TRUE)); $attributes['disabled'] = 'disabled'; $attributes['class'][] = 'autocomplete'; $output = '<div class="input-group">' . $output . '<span class="input-group-addon"><i class = "fa fa-refresh"></i></span></div>'; $extra = '<input' . drupal_attributes($attributes) . ' />'; } foreach ($element['#attributes']['class'] as $i => $class) { if (strpos($class, 'fa-') !== FALSE) { $element['#nd_icon'] = 'fa ' . $class; unset($element['#attributes']['class'][$i]); } } $output .= $extra; if (isset($element['#nd_icon'])) { $output = '<label class = "field prepend-icon">' . $output . '<span class = "field-icon"><i class="' . $element['#nd_icon'] . '"></i></span></label>'; } $output = '<div class = "section">' . $output . '</div>'; return $output; }
/** * Overrides theme_form_element(). */ function bootstrap_form_element(&$variables) { $element =& $variables['element']; $is_checkbox = FALSE; $is_radio = FALSE; // 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']; } // Check for errors and set correct error class. if (isset($element['#parents']) && form_get_error($element)) { $attributes['class'][] = 'error'; } 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'; } if (!empty($element['#autocomplete_path']) && drupal_valid_path($element['#autocomplete_path'])) { $attributes['class'][] = 'form-autocomplete'; } $attributes['class'][] = 'form-item'; // See http://getbootstrap.com/css/#forms-controls. if (isset($element['#type'])) { if ($element['#type'] == "radio") { $attributes['class'][] = 'radio'; $is_radio = TRUE; } elseif ($element['#type'] == "checkbox") { $attributes['class'][] = 'checkbox'; $is_checkbox = TRUE; } else { $attributes['class'][] = 'form-group'; } } $description = FALSE; $tooltip = FALSE; // Convert some descriptions to tooltips. // @see bootstrap_tooltip_descriptions setting in _bootstrap_settings_form() // Mukurtu patch -- use tooltips for (almost) *all* form field descriptions: // 1. Do not limit to only descriptions under 200 chars // 2. For text area fields, the description is not yet available in $element, so load it from the field instance and use that. // 3. We are still respecting the markup condition (description === strip_tags($description)) because jquery-ui tooltips can't show markup // 4. Override the default placement of these tooltips from bootstrap's default "auto-left" to "bottom", because auto-left was failing to right (since there is no space at left), but right was very squeezed on smaller screens if (!empty($element['#description'])) { $description = $element['#description']; } elseif ($element['#type'] == 'textarea') { $textfield = field_info_instance($element['#entity_type'], $element['#field_name'], $element['#bundle']); $description = $textfield['description']; } if ($description) { if (theme_get_setting('bootstrap_tooltip_enabled') && theme_get_setting('bootstrap_tooltip_descriptions') && $description === strip_tags($description)) { $tooltip = TRUE; $attributes['data-toggle'] = 'tooltip'; $attributes['data-placement'] = 'bottom'; $attributes['title'] = $description; } } $output = '<div' . drupal_attributes($attributes) . '>' . "\n"; // If #title is not set, we don't display any label or required marker. if (!isset($element['#title'])) { $element['#title_display'] = 'none'; } $prefix = ''; $suffix = ''; if (isset($element['#field_prefix']) || isset($element['#field_suffix'])) { // Determine if "#input_group" was specified. if (!empty($element['#input_group'])) { $prefix .= '<div class="input-group">'; $prefix .= isset($element['#field_prefix']) ? '<span class="input-group-addon">' . $element['#field_prefix'] . '</span>' : ''; $suffix .= isset($element['#field_suffix']) ? '<span class="input-group-addon">' . $element['#field_suffix'] . '</span>' : ''; $suffix .= '</div>'; } else { $prefix .= isset($element['#field_prefix']) ? $element['#field_prefix'] : ''; $suffix .= isset($element['#field_suffix']) ? $element['#field_suffix'] : ''; } } switch ($element['#title_display']) { case 'before': case 'invisible': $output .= ' ' . theme('form_element_label', $variables); $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n"; break; case 'after': if ($is_radio || $is_checkbox) { $output .= ' ' . $prefix . $element['#children'] . $suffix; } else { $variables['#children'] = ' ' . $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 ($description && !$tooltip) { $output .= '<p class="help-block">' . $element['#description'] . "</p>\n"; } $output .= "</div>\n"; return $output; }