Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
220
Merge Requests
220
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
097303e4
Commit
097303e4
authored
Jun 17, 2013
by
alexpott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#1393094
by swentel, solotandem: Make the field prefix in Field ui configurable.
parent
9236b3f7
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
59 additions
and
5 deletions
+59
-5
core/modules/field_ui/config/field_ui.settings.yml
core/modules/field_ui/config/field_ui.settings.yml
+1
-0
core/modules/field_ui/config/schema/field_ui.schema.yml
core/modules/field_ui/config/schema/field_ui.schema.yml
+9
-0
core/modules/field_ui/field_ui.install
core/modules/field_ui/field_ui.install
+9
-0
core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php
core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php
+10
-5
core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php
...s/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php
+30
-0
No files found.
core/modules/field_ui/config/field_ui.settings.yml
0 → 100644
View file @
097303e4
field_prefix
:
field_
core/modules/field_ui/config/schema/field_ui.schema.yml
0 → 100644
View file @
097303e4
# Schema for configuration files of the Field UI module.
field_ui.settings
:
type
:
mapping
label
:
'
Field
UI
settings'
mapping
:
field_prefix
:
type
:
string
label
:
'
The
prefix
for
new
fields
created
via
Field
UI'
core/modules/field_ui/field_ui.install
View file @
097303e4
...
@@ -43,3 +43,12 @@ function field_ui_update_8001() {
...
@@ -43,3 +43,12 @@ function field_ui_update_8001() {
}
}
}
}
}
}
/**
* Installs default config for Field UI.
*
* @ingroup config_upgrade
*/
function
field_ui_update_8002
()
{
update_7_to_8_install_default_config
(
'module'
,
'field_ui.settings'
);
}
core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php
View file @
097303e4
...
@@ -11,6 +11,7 @@
...
@@ -11,6 +11,7 @@
use
Drupal\Core\Entity\EntityManager
;
use
Drupal\Core\Entity\EntityManager
;
use
Drupal\field\Plugin\Type\Widget\WidgetPluginManager
;
use
Drupal\field\Plugin\Type\Widget\WidgetPluginManager
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
Drupal\field\Plugin\Core\Entity\Field
;
/**
/**
* Field UI field overview form.
* Field UI field overview form.
...
@@ -92,6 +93,9 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL,
...
@@ -92,6 +93,9 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL,
$extra_fields
=
field_info_extra_fields
(
$this
->
entity_type
,
$this
->
bundle
,
'form'
);
$extra_fields
=
field_info_extra_fields
(
$this
->
entity_type
,
$this
->
bundle
,
'form'
);
$entity_form_display
=
entity_get_form_display
(
$this
->
entity_type
,
$this
->
bundle
,
$this
->
mode
);
$entity_form_display
=
entity_get_form_display
(
$this
->
entity_type
,
$this
->
bundle
,
$this
->
mode
);
// Field prefix.
$field_prefix
=
config
(
'field_ui.settings'
)
->
get
(
'field_prefix'
);
$form
+=
array
(
$form
+=
array
(
'#entity_type'
=>
$this
->
entity_type
,
'#entity_type'
=>
$this
->
entity_type
,
'#bundle'
=>
$this
->
bundle
,
'#bundle'
=>
$this
->
bundle
,
...
@@ -308,12 +312,13 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL,
...
@@ -308,12 +312,13 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL,
'#title'
=>
t
(
'New field name'
),
'#title'
=>
t
(
'New field name'
),
'#title_display'
=>
'invisible'
,
'#title_display'
=>
'invisible'
,
// This field should stay LTR even for RTL languages.
// This field should stay LTR even for RTL languages.
'#field_prefix'
=>
'<span dir="ltr">
field_'
,
'#field_prefix'
=>
'<span dir="ltr">
'
.
$field_prefix
,
'#field_suffix'
=>
'</span>‎'
,
'#field_suffix'
=>
'</span>‎'
,
'#size'
=>
15
,
'#size'
=>
15
,
'#description'
=>
t
(
'A unique machine-readable name containing letters, numbers, and underscores.'
),
'#description'
=>
t
(
'A unique machine-readable name containing letters, numbers, and underscores.'
),
// 32 characters minus the 'field_' prefix.
// Calculate characters depending on the length of the field prefix
'#maxlength'
=>
26
,
// setting. Maximum length is 32.
'#maxlength'
=>
Field
::
ID_MAX_LENGTH
-
strlen
(
$field_prefix
),
'#prefix'
=>
'<div class="add-new-placeholder"> </div>'
,
'#prefix'
=>
'<div class="add-new-placeholder"> </div>'
,
'#machine_name'
=>
array
(
'#machine_name'
=>
array
(
'source'
=>
array
(
'fields'
,
$name
,
'label'
),
'source'
=>
array
(
'fields'
,
$name
,
'label'
),
...
@@ -502,8 +507,8 @@ protected function validateAddNew(array $form, array &$form_state) {
...
@@ -502,8 +507,8 @@ protected function validateAddNew(array $form, array &$form_state) {
else
{
else
{
$field_name
=
$field
[
'field_name'
];
$field_name
=
$field
[
'field_name'
];
// Add the
'field_'
prefix.
// Add the
field
prefix.
$field_name
=
'field_'
.
$field_name
;
$field_name
=
config
(
'field_ui.settings'
)
->
get
(
'field_prefix'
)
.
$field_name
;
form_set_value
(
$form
[
'fields'
][
'_add_new_field'
][
'field_name'
],
$field_name
,
$form_state
);
form_set_value
(
$form
[
'fields'
][
'_add_new_field'
][
'field_name'
],
$field_name
,
$form_state
);
}
}
...
...
core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php
View file @
097303e4
...
@@ -244,6 +244,36 @@ function assertFieldSettings($bundle, $field_name, $string = 'dummy test string'
...
@@ -244,6 +244,36 @@ function assertFieldSettings($bundle, $field_name, $string = 'dummy test string'
$this
->
assertTrue
(
$widget_configuration
[
'settings'
][
'test_widget_setting'
]
==
$string
,
'Field widget settings were found.'
);
$this
->
assertTrue
(
$widget_configuration
[
'settings'
][
'test_widget_setting'
]
==
$string
,
'Field widget settings were found.'
);
}
}
/**
* Tests that the 'field_prefix' setting works on Field UI.
*/
function
testFieldPrefix
()
{
// Change default field prefix.
$field_prefix
=
strtolower
(
$this
->
randomName
(
10
));
\
Drupal
::
config
(
'field_ui.settings'
)
->
set
(
'field_prefix'
,
$field_prefix
)
->
save
();
// Create a field input and label exceeding the new maxlength, which is 22.
$field_exceed_max_length_label
=
$this
->
randomString
(
23
);
$field_exceed_max_length_input
=
$this
->
randomName
(
23
);
// Try to create the field.
$edit
=
array
(
'fields[_add_new_field][label]'
=>
$field_exceed_max_length_label
,
'fields[_add_new_field][field_name]'
=>
$field_exceed_max_length_input
,
);
$this
->
drupalPost
(
'admin/structure/types/manage/'
.
$this
->
type
.
'/fields'
,
$edit
,
t
(
'Save'
));
$this
->
assertText
(
'New field name cannot be longer than 22 characters but is currently 23 characters long.'
);
// Create a valid field.
$edit
=
array
(
'fields[_add_new_field][label]'
=>
$this
->
field_label
,
'fields[_add_new_field][field_name]'
=>
$this
->
field_name_input
,
);
$this
->
fieldUIAddNewField
(
'admin/structure/types/manage/'
.
$this
->
type
,
$edit
);
$this
->
drupalGet
(
'admin/structure/types/manage/'
.
$this
->
type
.
'/fields/node.'
.
$this
->
type
.
'.'
.
$field_prefix
.
$this
->
field_name_input
);
$this
->
assertText
(
format_string
(
'@label settings for @type'
,
array
(
'@label'
=>
$this
->
field_label
,
'@type'
=>
$this
->
type
)));
}
/**
/**
* Tests that default value is correctly validated and saved.
* Tests that default value is correctly validated and saved.
*/
*/
...
...
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