Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
0990c7ee
Commit
0990c7ee
authored
Mar 07, 2014
by
webchick
Browse files
Issue
#1982776
by netsensei, Dave Reid, plopesc: Formatters do not support weights like widgets do.
parent
82bb0f33
Changes
11
Hide whitespace changes
Inline
Side-by-side
core/lib/Drupal/Core/Field/Annotation/FieldFormatter.php
View file @
0990c7ee
...
...
@@ -74,4 +74,13 @@ class FieldFormatter extends Plugin {
*/
public
$settings
=
array
();
/**
* An integer to determine the weight of this formatter relative to other
* formatter in the Field UI when selecting a formatter for a given field
* instance.
*
* @var int optional
*/
public
$weight
=
NULL
;
}
core/lib/Drupal/Core/Field/FormatterPluginManager.php
View file @
0990c7ee
...
...
@@ -167,13 +167,15 @@ public function prepareConfiguration($field_type, array $configuration) {
*/
public
function
getOptions
(
$field_type
=
NULL
)
{
if
(
!
isset
(
$this
->
formatterOptions
))
{
$field_types
=
$this
->
fieldTypeManager
->
getDefinitions
();
$options
=
array
();
foreach
(
$this
->
getDefinitions
()
as
$name
=>
$formatter
)
{
foreach
(
$formatter
[
'field_types'
]
as
$formatter_field_type
)
{
$field_types
=
$this
->
fieldTypeManager
->
getDefinitions
();
$formatter_types
=
$this
->
getDefinitions
();
uasort
(
$formatter_types
,
array
(
'Drupal\Component\Utility\SortArray'
,
'sortByWeightElement'
));
foreach
(
$formatter_types
as
$name
=>
$formatter_type
)
{
foreach
(
$formatter_type
[
'field_types'
]
as
$formatter_field_type
)
{
// Check that the field type exists.
if
(
isset
(
$field_types
[
$formatter_field_type
]))
{
$options
[
$formatter_field_type
][
$name
]
=
$formatter
[
'label'
];
$options
[
$formatter_field_type
][
$name
]
=
$formatter
_type
[
'label'
];
}
}
}
...
...
core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/Field/FieldFormatter/TestFieldDefaultFormatter.php
View file @
0990c7ee
...
...
@@ -22,7 +22,8 @@
* },
* settings = {
* "test_formatter_setting" = "dummy test string"
* }
* },
* weight = 1
* )
*/
class
TestFieldDefaultFormatter
extends
FormatterBase
{
...
...
core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/Field/FieldFormatter/TestFieldEmptyFormatter.php
View file @
0990c7ee
...
...
@@ -21,7 +21,8 @@
* },
* settings = {
* "test_empty_string" = "**EMPTY FIELD**"
* }
* },
* weight = -5
* )
*/
class
TestFieldEmptyFormatter
extends
FormatterBase
{
...
...
core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/Field/FieldFormatter/TestFieldEmptySettingFormatter.php
View file @
0990c7ee
...
...
@@ -21,7 +21,8 @@
* },
* settings = {
* "field_empty_setting" = ""
* }
* },
* weight = -1
* )
*/
class
TestFieldEmptySettingFormatter
extends
FormatterBase
{
...
...
core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/Field/FieldFormatter/TestFieldMultipleFormatter.php
View file @
0990c7ee
...
...
@@ -22,7 +22,8 @@
* },
* settings = {
* "test_formatter_setting_multiple" = "dummy test string"
* }
* },
* weight = 5
* )
*/
class
TestFieldMultipleFormatter
extends
FormatterBase
{
...
...
core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/Field/FieldFormatter/TestFieldNoSettingsFormatter.php
View file @
0990c7ee
...
...
@@ -19,6 +19,7 @@
* field_types = {
* "test_field",
* },
* weight = -10
* )
*/
class
TestFieldNoSettingsFormatter
extends
FormatterBase
{
...
...
core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/Field/FieldFormatter/TestFieldPrepareViewFormatter.php
View file @
0990c7ee
...
...
@@ -22,7 +22,8 @@
* },
* settings = {
* "test_formatter_setting_additional" = "dummy test string"
* }
* },
* weight = 10
* )
*/
class
TestFieldPrepareViewFormatter
extends
FormatterBase
{
...
...
core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/Field/FieldWidget/TestFieldWidget.php
View file @
0990c7ee
...
...
@@ -23,7 +23,8 @@
* },
* settings = {
* "test_widget_setting" = "dummy test string"
* }
* },
* weight = -10
* )
*/
class
TestFieldWidget
extends
WidgetBase
{
...
...
core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/Field/FieldWidget/TestFieldWidgetMultiple.php
View file @
0990c7ee
...
...
@@ -25,7 +25,8 @@
* settings = {
* "test_widget_setting_multiple" = "dummy test string"
* },
* multiple_values = TRUE
* multiple_values = TRUE,
* weight = 10
* )
*/
class
TestFieldWidgetMultiple
extends
WidgetBase
{
...
...
core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageDisplayTest.php
View file @
0990c7ee
...
...
@@ -51,12 +51,28 @@ function testFormatterUI() {
$setting_name
=
key
(
$default_settings
);
$setting_value
=
$display_options
[
'settings'
][
$setting_name
];
// Display the "Manage display" screen and check that the expected formatter
is
// selected.
// Display the "Manage display" screen and check that the expected formatter
//
is
selected.
$this
->
drupalGet
(
$manage_display
);
$this
->
assertFieldByName
(
'fields[field_test][type]'
,
$format
,
'The expected formatter is selected.'
);
$this
->
assertText
(
"
$setting_name
:
$setting_value
"
,
'The expected summary is displayed.'
);
// Check whether formatter weights are respected.
$result
=
$this
->
xpath
(
'//select[@id=:id]/option'
,
array
(
':id'
=>
'edit-fields-field-test-type'
));
$options
=
array_map
(
function
(
$item
)
{
return
(
string
)
$item
->
attributes
()
->
value
[
0
];
},
$result
);
$expected_options
=
array
(
'field_no_settings'
,
'field_empty_test'
,
'field_empty_setting'
,
'field_test_default'
,
'field_test_multiple'
,
'field_test_with_prepare_view'
,
'hidden'
,
);
$this
->
assertEqual
(
$options
,
$expected_options
,
'The expected formatter ordering is respected.'
);
// Change the formatter and check that the summary is updated.
$edit
=
array
(
'fields[field_test][type]'
=>
'field_test_multiple'
,
'refresh_rows'
=>
'field_test'
);
$this
->
drupalPostAjaxForm
(
NULL
,
$edit
,
array
(
'op'
=>
t
(
'Refresh'
)));
...
...
@@ -139,6 +155,18 @@ public function testWidgetUI() {
$this
->
assertFieldByName
(
'fields[field_test][type]'
,
$widget_type
,
'The expected widget is selected.'
);
$this
->
assertText
(
"
$setting_name
:
$setting_value
"
,
'The expected summary is displayed.'
);
// Check whether widget weights are respected.
$result
=
$this
->
xpath
(
'//select[@id=:id]/option'
,
array
(
':id'
=>
'edit-fields-field-test-type'
));
$options
=
array_map
(
function
(
$item
)
{
return
(
string
)
$item
->
attributes
()
->
value
[
0
];
},
$result
);
$expected_options
=
array
(
'test_field_widget'
,
'test_field_widget_multiple'
,
'hidden'
,
);
$this
->
assertEqual
(
$options
,
$expected_options
,
'The expected widget ordering is respected.'
);
// Change the widget and check that the summary is updated.
$edit
=
array
(
'fields[field_test][type]'
=>
'test_field_widget_multiple'
,
'refresh_rows'
=>
'field_test'
);
$this
->
drupalPostAjaxForm
(
NULL
,
$edit
,
array
(
'op'
=>
t
(
'Refresh'
)));
...
...
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