Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Drupal.org issue queue
Drupal.org issue queue
Security & Compliance
Security & Compliance
Dependency List
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
project
drupal
Commits
e28f1738
Commit
e28f1738
authored
Apr 04, 2013
by
catch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#1942902
by Dave Reid: Fixed Placeholder not supported in telephone default widget.
parent
b85f42e1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
2 deletions
+30
-2
core/modules/telephone/lib/Drupal/telephone/Plugin/field/widget/TelephoneDefaultWidget.php
.../telephone/Plugin/field/widget/TelephoneDefaultWidget.php
+17
-0
core/modules/telephone/lib/Drupal/telephone/Tests/TelephoneFieldTest.php
...lephone/lib/Drupal/telephone/Tests/TelephoneFieldTest.php
+13
-2
No files found.
core/modules/telephone/lib/Drupal/telephone/Plugin/field/widget/TelephoneDefaultWidget.php
View file @
e28f1738
...
...
@@ -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
;
}
...
...
core/modules/telephone/lib/Drupal/telephone/Tests/TelephoneFieldTest.php
View file @
e28f1738
...
...
@@ -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"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment