Commit 78a1c38f authored by Dries's avatar Dries

- Patch #1174694 by ericduran, linclark, Dave Reid: allow FAPI usage of the placeholder attribute.

parent 9b784c1e
......@@ -3650,14 +3650,14 @@ function theme_hidden($variables) {
* An associative array containing:
* - element: An associative array containing the properties of the element.
* Properties used: #title, #value, #description, #size, #maxlength,
* #required, #attributes, #autocomplete_path.
* #placeholder, #required, #attributes, #autocomplete_path.
*
* @ingroup themeable
*/
function theme_textfield($variables) {
$element = $variables['element'];
$element['#attributes']['type'] = 'text';
element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength'));
element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength', 'placeholder'));
_form_set_class($element, array('form-text'));
$extra = '';
......@@ -3708,14 +3708,14 @@ function theme_form($variables) {
* @param $variables
* An associative array containing:
* - element: An associative array containing the properties of the element.
* Properties used: #title, #value, #description, #rows, #cols, #required,
* #attributes
* Properties used: #title, #value, #description, #rows, #cols,
* #placeholder, #required, #attributes
*
* @ingroup themeable
*/
function theme_textarea($variables) {
$element = $variables['element'];
element_set_attributes($element, array('id', 'name', 'cols', 'rows'));
element_set_attributes($element, array('id', 'name', 'rows', 'cols', 'placeholder'));
_form_set_class($element, array('form-textarea'));
$wrapper_attributes = array(
......@@ -3741,14 +3741,14 @@ function theme_textarea($variables) {
* An associative array containing:
* - element: An associative array containing the properties of the element.
* Properties used: #title, #value, #description, #size, #maxlength,
* #required, #attributes.
* #placeholder, #required, #attributes.
*
* @ingroup themeable
*/
function theme_password($variables) {
$element = $variables['element'];
$element['#attributes']['type'] = 'password';
element_set_attributes($element, array('id', 'name', 'size', 'maxlength'));
element_set_attributes($element, array('id', 'name', 'size', 'maxlength', 'placeholder'));
_form_set_class($element, array('form-text'));
return '<input' . drupal_attributes($element['#attributes']) . ' />';
......
......@@ -386,6 +386,30 @@ class FormElementTestCase extends DrupalWebTestCase {
parent::setUp(array('form_test'));
}
/**
* Tests placeholder text for textfield, password, and textarea.
*/
function testPlaceHolderText() {
$this->drupalGet('form-test/placeholder-text');
$expected = 'placeholder-text';
// Test to make sure textfields and passwords have the proper placeholder
// text.
foreach (array('textfield', 'password') as $type) {
$element = $this->xpath('//input[@id=:id and @placeholder=:expected]', array(
':id' => 'edit-' . $type,
':expected' => $expected,
));
$this->assertTrue(!empty($element), t('Placeholder text placed in @type.', array('@type' => $type)));
}
// Test to make sure textarea has the proper placeholder text.
$element = $this->xpath('//textarea[@id=:id and @placeholder=:expected]', array(
':id' => 'edit-textarea',
':expected' => $expected,
));
$this->assertTrue(!empty($element), t('Placeholder text placed in textarea.'));
}
/**
* Tests expansion of #options for #type checkboxes and radios.
*/
......
......@@ -105,6 +105,12 @@ function form_test_menu() {
'page arguments' => array('form_test_select'),
'access callback' => TRUE,
);
$items['form-test/placeholder-text'] = array(
'title' => 'Placeholder',
'page callback' => 'drupal_get_form',
'page arguments' => array('form_test_placeholder_test'),
'access callback' => TRUE,
);
$items['form-test/checkboxes-radios'] = array(
'title' => t('Checkboxes, Radios'),
'page callback' => 'drupal_get_form',
......@@ -980,6 +986,21 @@ function form_test_select_submit($form, &$form_state) {
exit();
}
/**
* Builds a form to test the placeholder attribute.
*/
function form_test_placeholder_test($form, &$form_state) {
foreach (array('textfield', 'textarea', 'password') as $type) {
$form[$type] = array(
'#type' => $type,
'#title' => $type,
'#placeholder' => 'placeholder-text',
);
}
return $form;
}
/**
* Form constructor to test expansion of #type checkboxes and radios.
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment