Commit e28f1738 authored by catch's avatar catch

Issue #1942902 by Dave Reid: Fixed Placeholder not supported in telephone default widget.

parent b85f42e1
......@@ -20,11 +20,27 @@
* label = @Translation("Telephone number"),
* field_types = {
* "telephone"
* },
* settings = {
* "placeholder" = ""
* }
* )
*/
class TelephoneDefaultWidget extends WidgetBase {
/**
* Implements Drupal\field\Plugin\Type\Widget\WidgetInterface::settingsForm().
*/
public function settingsForm(array $form, array &$form_state) {
$element['placeholder'] = array(
'#type' => 'textfield',
'#title' => t('Placeholder'),
'#default_value' => $this->getSetting('placeholder'),
'#description' => t('Text that will be shown inside the field until a value is entered. This hint is usually a sample value or a brief description of the expected format.'),
);
return $element;
}
/**
* Implements \Drupal\field\Plugin\Type\Widget\WidgetInterface::formElement().
*/
......@@ -32,6 +48,7 @@ public function formElement(array $items, $delta, array $element, $langcode, arr
$element['value'] = $element + array(
'#type' => 'tel',
'#default_value' => isset($items[$delta]['value']) ? $items[$delta]['value'] : NULL,
'#placeholder' => $this->getSetting('placeholder'),
);
return $element;
}
......
......@@ -64,6 +64,12 @@ function testTelephoneField() {
'label' => 'Telephone Number',
'entity_type' => 'node',
'bundle' => 'article',
'widget' => array(
'type' => 'telephone_default',
'settings' => array(
'placeholder' => '123-456-7890',
),
),
);
field_create_instance($instance);
......@@ -74,16 +80,21 @@ function testTelephoneField() {
))
->save();
// Display creation form.
$this->drupalGet('node/add/article');
$this->assertFieldByName("field_telephone[und][0][value]", '', 'Widget found.');
$this->assertRaw('placeholder="123-456-7890"');
// Test basic entery of telephone field.
$edit = array(
"title" => $this->randomName(),
"field_telephone[und][0][value]" => "123456789",
);
$this->drupalPost('node/add/article', $edit, t('Save'));
$this->drupalPost(NULL, $edit, t('Save'));
$this->assertRaw('<a href="tel:123456789">', 'A telephone link is provided on the article node page.');
// Add number with a space in it. Need to ensure it is stripped.
// Add number with a space in it. Need to ensure it is stripped on output.
$edit = array(
"title" => $this->randomName(),
"field_telephone[und][0][value]" => "1234 56789",
......
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