Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
project
drupal
Commits
8f89d7b9
Commit
8f89d7b9
authored
Oct 31, 2014
by
alexpott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2361615
by Gábor Hojtsy: Fixed Field type config schemas are not in the base schema.
parent
abea9657
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
198 additions
and
41 deletions
+198
-41
core/config/schema/core.data_types.schema.yml
core/config/schema/core.data_types.schema.yml
+137
-9
core/lib/Drupal/Core/Field/BaseFieldDefinition.php
core/lib/Drupal/Core/Field/BaseFieldDefinition.php
+11
-0
core/modules/content_translation/src/Tests/ContentTranslationSettingsTest.php
..._translation/src/Tests/ContentTranslationSettingsTest.php
+23
-0
core/modules/entity_reference/config/schema/entity_reference.schema.yml
...ntity_reference/config/schema/entity_reference.schema.yml
+0
-30
core/modules/system/tests/modules/entity_test/src/Entity/EntityTest.php
...ystem/tests/modules/entity_test/src/Entity/EntityTest.php
+1
-1
core/tests/Drupal/Tests/Core/Entity/BaseFieldDefinitionTest.php
...ests/Drupal/Tests/Core/Entity/BaseFieldDefinitionTest.php
+26
-1
No files found.
core/config/schema/core.data_types.schema.yml
View file @
8f89d7b9
...
...
@@ -414,14 +414,19 @@ core.date_format.*:
type
:
string
label
:
'
Default
language'
# Schema for the String field type.
# Schema for the configuration of the String field type.
field.string.storage_settings
:
type
:
mapping
label
:
'
String
settings'
mapping
:
max_length
:
type
:
integer
label
:
'
Maximum
length'
field.string.field_settings
:
type
:
sequence
label
:
'
String
settings'
sequence
:
-
type
:
string
label
:
'
Setting'
field.string.value
:
type
:
sequence
...
...
@@ -434,7 +439,127 @@ field.string.value:
type
:
string
label
:
'
Value'
# Schema for the configuration files of the Boolean field type.
# Schema for the configuration of the String (long) field type.
field.string_long.storage_settings
:
type
:
field.string.storage_settings
label
:
'
String
(long)
settings'
field.string_long.field_settings
:
type
:
field.string.field_settings
label
:
'
String
(long)
settings'
field.string_long.value
:
type
:
sequence
label
:
'
Default
value'
sequence
:
-
type
:
mapping
label
:
'
Default'
mapping
:
value
:
type
:
text
label
:
'
Value'
# Schema for the configuration of the URI field type.
field.uri.storage_settings
:
type
:
mapping
label
:
'
URI
settings'
mapping
:
max_length
:
type
:
integer
label
:
'
Maximum
length'
field.uri.field_settings
:
type
:
sequence
label
:
'
URI
settings'
field.uri.value
:
type
:
sequence
label
:
'
Default
value'
sequence
:
-
type
:
mapping
label
:
'
Default'
mapping
:
value
:
type
:
string
label
:
'
Value'
# Schema for the configuration of the Created field type.
field.created.storage_settings
:
type
:
sequence
label
:
'
Created
timestamp
settings'
field.created.field_settings
:
type
:
sequence
label
:
'
Created
timestamp
settings'
field.created.value
:
type
:
sequence
label
:
'
Default
value'
sequence
:
-
type
:
mapping
label
:
'
Default'
mapping
:
value
:
type
:
integer
label
:
'
Value'
# Schema for the configuration of the Changed field type.
field.changed.storage_settings
:
type
:
sequence
label
:
'
Changed
timestamp
settings'
field.changed.field_settings
:
type
:
sequence
label
:
'
Changed
timestamp
settings'
field.changed.value
:
type
:
sequence
label
:
'
Default
value'
sequence
:
-
type
:
mapping
label
:
'
Default'
mapping
:
value
:
type
:
integer
label
:
'
Value'
# Schema for the configuration of the Entity reference field type.
field.entity_reference.storage_settings
:
type
:
mapping
label
:
'
Entity
reference
settings'
mapping
:
target_type
:
type
:
string
label
:
'
Type
of
item
to
reference'
field.entity_reference.field_settings
:
type
:
mapping
label
:
'
Entity
reference
settings'
mapping
:
handler
:
type
:
string
label
:
'
Reference
method'
handler_settings
:
type
:
entity_reference.[%parent.handler].handler_settings
label
:
'
Reference
method
settings'
field.entity_reference.value
:
type
:
sequence
label
:
'
Default
value'
sequence
:
-
type
:
mapping
label
:
'
Default'
mapping
:
target_id
:
type
:
integer
label
:
'
Value'
# Schema for the configuration of the Boolean field type.
field.boolean.storage_settings
:
type
:
mapping
...
...
@@ -449,8 +574,7 @@ field.boolean.storage_settings:
field.boolean.field_settings
:
label
:
'
Boolean
settings'
type
:
mapping
mapping
:
{
}
type
:
sequence
field.boolean.value
:
type
:
sequence
...
...
@@ -463,7 +587,7 @@ field.boolean.value:
type
:
integer
label
:
'
Value'
# Schema for the configuration
files
of the Email field type.
# Schema for the configuration of the Email field type.
field.email.storage_settings
:
type
:
sequence
...
...
@@ -489,7 +613,7 @@ field.email.value:
type
:
email
label
:
'
Value'
# Schema for configuration
files of a numeric
field type
s
.
# Schema for
the
configuration
of the Integer
field type.
field.integer.storage_settings
:
type
:
sequence
...
...
@@ -526,6 +650,8 @@ field.integer.value:
type
:
integer
label
:
'
Value'
# Schema for the configuration of the Decimal field type.
field.decimal.storage_settings
:
type
:
mapping
label
:
'
Decimal
settings'
...
...
@@ -565,6 +691,8 @@ field.decimal.value:
type
:
float
label
:
'
Value'
# Schema for the configuration of the Float field type.
field.float.storage_settings
:
type
:
sequence
label
:
'
Float
settings'
...
...
core/lib/Drupal/Core/Field/BaseFieldDefinition.php
View file @
8f89d7b9
...
...
@@ -438,11 +438,22 @@ public function setDefaultValueCallback($callback) {
* the first item.
* - a numerically indexed array of items, each item being a property/value
* array.
* - a non-numerically indexed array, in which case the array is assumed to
* be a property/value array and used as the first item
* - NULL or array() for no default value.
*
* @return $this
*/
public
function
setDefaultValue
(
$value
)
{
// Unless the value is NULL or an empty array, we may need to transform it.
if
(
!
(
is_null
(
$value
)
||
(
is_array
(
$value
)
&&
empty
(
$value
))))
{
if
(
!
is_array
(
$value
))
{
$value
=
array
(
array
(
$this
->
getMainPropertyName
()
=>
$value
));
}
elseif
(
!
is_numeric
(
array_keys
(
$value
)[
0
]))
{
$value
=
array
(
0
=>
$value
);
}
}
$this
->
definition
[
'default_value'
]
=
$value
;
return
$this
;
}
...
...
core/modules/content_translation/src/Tests/ContentTranslationSettingsTest.php
View file @
8f89d7b9
...
...
@@ -8,6 +8,7 @@
namespace
Drupal\content_translation\Tests
;
use
Drupal\comment\Plugin\Field\FieldType\CommentItemInterface
;
use
Drupal\config\Tests\SchemaCheckTestTrait
;
use
Drupal\Core\Field\Entity\BaseFieldOverride
;
use
Drupal\Core\Language\Language
;
use
Drupal\field\Entity\FieldConfig
;
...
...
@@ -20,6 +21,8 @@
*/
class
ContentTranslationSettingsTest
extends
WebTestBase
{
use
SchemaCheckTestTrait
;
/**
* Modules to enable.
*
...
...
@@ -178,6 +181,8 @@ function testSettingsUI() {
$this
->
assertEqual
(
$definitions
[
'body'
]
->
isTranslatable
(),
$translatable
,
'Field translatability correctly switched.'
);
$this
->
assertEqual
(
$field
->
isTranslatable
(),
$definitions
[
'body'
]
->
isTranslatable
(),
'Configurable field translatability correctly switched.'
);
}
$this
->
assertConfigSchemas
();
}
/**
...
...
@@ -269,4 +274,22 @@ protected function entityManager() {
return
$this
->
container
->
get
(
'entity.manager'
);
}
/**
* Asserts all active configuration matches schemas.
*/
protected
function
assertConfigSchemas
()
{
$names
=
$this
->
container
->
get
(
'config.storage'
)
->
listAll
();
$factory
=
$this
->
container
->
get
(
'config.factory'
);
/** @var \Drupal\Core\Config\TypedConfigManagerInterface $typed_config */
$typed_config
=
$this
->
container
->
get
(
'config.typed'
);
foreach
(
$names
as
$name
)
{
// It is not possible to provide schema due to https://www.drupal.org/node/2248709
// @todo Refactor settings in https://www.drupal.org/node/2363155
if
(
$name
!=
'content_translation.settings'
)
{
$config
=
$factory
->
get
(
$name
);
$this
->
assertConfigSchema
(
$typed_config
,
$name
,
$config
->
get
());
}
}
}
}
core/modules/entity_reference/config/schema/entity_reference.schema.yml
View file @
8f89d7b9
# Schema for the configuration files of the Entity Reference module.
field.entity_reference.storage_settings
:
type
:
mapping
label
:
'
Entity
reference
settings'
mapping
:
target_type
:
type
:
string
label
:
'
Type
of
item
to
reference'
field.entity_reference.field_settings
:
type
:
mapping
label
:
'
Entity
reference
settings'
mapping
:
handler
:
type
:
string
label
:
'
Reference
method'
handler_settings
:
type
:
entity_reference.[%parent.handler].handler_settings
label
:
'
Reference
method
settings'
field.entity_reference.value
:
type
:
sequence
label
:
'
Default
value'
sequence
:
-
type
:
mapping
label
:
'
Default'
mapping
:
target_id
:
type
:
integer
label
:
'
Value'
entity_reference.default.handler_settings
:
type
:
mapping
label
:
'
View
handler
settings'
...
...
core/modules/system/tests/modules/entity_test/src/Entity/EntityTest.php
View file @
8f89d7b9
...
...
@@ -107,7 +107,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
->
setSetting
(
'handler'
,
'default'
)
// Default EntityTest entities to have the root user as the owner, to
// simplify testing.
->
setDefaultValue
(
array
(
0
=>
1
))
->
setDefaultValue
(
array
(
0
=>
array
(
'target_id'
=>
1
)
))
->
setTranslatable
(
TRUE
)
->
setDisplayOptions
(
'form'
,
array
(
'type'
=>
'entity_reference_autocomplete'
,
...
...
core/tests/Drupal/Tests/Core/Entity/BaseFieldDefinitionTest.php
View file @
8f89d7b9
...
...
@@ -164,6 +164,7 @@ public function testFieldDefaultValue() {
$default_value
=
array
(
'value'
=>
$this
->
randomMachineName
(),
);
$expected_default_value
=
array
(
$default_value
);
$definition
->
setDefaultValue
(
$default_value
);
$entity
=
$this
->
getMockBuilder
(
'Drupal\Core\Entity\ContentEntityBase'
)
->
disableOriginalConstructor
()
...
...
@@ -171,7 +172,31 @@ public function testFieldDefaultValue() {
// Set the field item list class to be used to avoid requiring the typed
// data manager to retrieve it.
$definition
->
setClass
(
'Drupal\Core\Field\FieldItemList'
);
$this
->
assertEquals
(
$default_value
,
$definition
->
getDefaultValue
(
$entity
));
$this
->
assertEquals
(
$expected_default_value
,
$definition
->
getDefaultValue
(
$entity
));
$data_definition
=
$this
->
getMockBuilder
(
'Drupal\Core\TypedData\DataDefinition'
)
->
disableOriginalConstructor
()
->
getMock
();
$data_definition
->
expects
(
$this
->
any
())
->
method
(
'getClass'
)
->
will
(
$this
->
returnValue
(
'Drupal\Core\Field\FieldItemBase'
));
$definition
->
setItemDefinition
(
$data_definition
);
// Set default value only with a literal.
$definition
->
setDefaultValue
(
$default_value
[
'value'
]);
$this
->
assertEquals
(
$expected_default_value
,
$definition
->
getDefaultValue
(
$entity
));
// Set default value with an indexed array.
$definition
->
setDefaultValue
(
$expected_default_value
);
$this
->
assertEquals
(
$expected_default_value
,
$definition
->
getDefaultValue
(
$entity
));
// Set default value with an empty array.
$definition
->
setDefaultValue
(
array
());
$this
->
assertEquals
(
array
(),
$definition
->
getDefaultValue
(
$entity
));
// Set default value with NULL.
$definition
->
setDefaultValue
(
NULL
);
$this
->
assertEquals
(
NULL
,
$definition
->
getDefaultValue
(
$entity
));
}
/**
...
...
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