Skip to content

Commit

Permalink
Allow simpler yml for content creation/update; fix docs for obj state…
Browse files Browse the repository at this point in the history
…s dsl
  • Loading branch information
gggeek committed Oct 20, 2016
1 parent d599125 commit 612071c
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 52 deletions.
25 changes: 19 additions & 6 deletions Core/Executor/ContentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,24 +270,37 @@ protected function matchContents($action)
*
* @param ContentCreateStruct|ContentUpdateStruct $createOrUpdateStruct
* @param ContentType $contentType
* @param array $fields
* @param array $fields see description of expected format in code below
* @throws \Exception
*/
protected function setFields($createOrUpdateStruct, array $fields, ContentType $contentType)
{
foreach ($fields as $field) {
// each $field is one key value pair
// eg.: $field = array($fieldIdentifier => $fieldValue)
$fieldIdentifier = key($field);
$i = 0;
// the 'easy' yml: key = field name, value = value
// deprecated: the 'legacy' yml: key = numerical index, value = array ( field name => value )
foreach ($fields as $key => $field) {

if ($key === $i && is_array($field) && count($field) == 1) {
// each $field is one key value pair
// eg.: $field = array($fieldIdentifier => $fieldValue)
reset($field);
$fieldIdentifier = key($field);
$fieldValue = $field[$fieldIdentifier];
} else {
$fieldIdentifier = $key;
$fieldValue = $field;
}

$fieldType = $contentType->fieldDefinitionsByIdentifier[$fieldIdentifier];
if ($fieldType == null) {
throw new \Exception("Field '$fieldIdentifier' is not present in field type '{$contentType->identifier}'");
}

$fieldValue = $this->getFieldValue($field[$fieldIdentifier], $fieldType, $contentType->identifier, $this->context);
$fieldValue = $this->getFieldValue($fieldValue, $fieldType, $contentType->identifier, $this->context);

$createOrUpdateStruct->setField($fieldIdentifier, $fieldValue, $this->getLanguageCode());

$i++;
}
}

Expand Down
46 changes: 23 additions & 23 deletions Resources/doc/DSL/ManageContent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,37 @@
owner: xxx # user id, login or email if unique; Optional, set the content owner
modification_date: zzz # Optional, set content modification date (for formats, see: http://php.net/manual/en/datetime.formats.php)
attributes:
- attribute1: value1
- attribute2: value2
- attribute3: |
value can be
on multiple lines
and new lines are preserved on parsing
- attribute4: >
value on multiple
lines, but new line is not preserved on parsing
attribute1: value1
attribute2: value2
attribute3: |
value can be
on multiple lines
and new lines are preserved on parsing
attribute4: >
value on multiple
lines, but new line is not preserved on parsing
# ezimage/ezbinaryfile file attribute example
- attribute5:
attribute5:
path: 'path/to/image' # Relative path from MigrationsVersions/images/ or MigrationsVersions/files/
alt_text: xyz # Optional, only used for images
filename: abc # Optional, taken from the actual file if not specified
mime_type: def # Optional. For ezbinaryfile only. If not specified, the actual file is analyzed using the php function mime_content_type()
# ezimage/ezbinaryfile file attribute example, using simplified form
- attribute5b: 'path/to/image'
attribute5b: 'path/to/image'
# ezxmltext, showing an example of using references
- attribute6: '<section><paragraph><embed view="embed" size="medium" object_id="[reference:example_reference]" /></paragraph></section>'
attribute6: '<section><paragraph><embed view="embed" size="medium" object_id="[reference:example_reference]" /></paragraph></section>'
# Adding values to an ezauthor field
- attribute7:
-

name: Test Author

email: [email protected]
-
name: Another Author

email: [email protected]
attribute7:
-

name: Test Author

email: [email protected]
-
name: Another Author

email: [email protected]
# Adding values to an ezobjectrelation field
- attribute8: x # content id or string: reference:xxx
attribute8: x # content id or string: reference:xxx
# Adding values to an ezobjectrelationlist field
- ezobjectrelationlist: [ x, reference:xxx ] # array of content ids or reference strings
ezobjectrelationlist: [ x, reference:xxx ] # array of content ids or reference strings
# Optionally assign object states to the content
object_states:
- xxx # int|string an object state id or identifier. If the identifier is not unique, use obj-state-gorup-identifier/obj-state-identifier
Expand Down Expand Up @@ -75,8 +75,8 @@
publication_date: zzz # Optional, set content modification date (for formats, see: http://php.net/manual/en/datetime.formats.php)
new_remote_id: xxx # string Optional set a new RemoteId
attributes: # the list of attribute identifier value pairs. For the format to use, see above
- attribute1: value1
- attribute2: value2
attribute1: value1
attribute2: value2
# Optionally assign object states to the content
object_states:
- xxx # int|string an object state id or didentifier. For the format to use, see above
Expand Down
40 changes: 20 additions & 20 deletions Resources/doc/DSL/ManageObjectStatesAndGoups.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
type: object_state_group
identifier: x # String identifier of the object state group
names: # Array of names keyed by language code.
- languageCodeA: name
- languageCodeB: name
languageCodeA: name
languageCodeB: name
descriptions: # Optional: array of descriptions keyed by language code.
- languageCodeA: description
- languageCodeB: description
languageCodeA: description
languageCodeB: description
references: #Optional
-
-
identifier: referenceId # A string used to identify the reference
attribute: attribute # An attribute to get the value of for the reference; supported: object_state_group_id, object_state_group_identifier
# The shorthand 'id' can be used instead of 'object_state_group_id'
Expand All @@ -22,13 +22,13 @@
identifier: y # string|string[] The Identifier of the object state group(s) to update
identifier: x # Optional String: new identifier of the object state group
names: # Optional: array of names keyed by language code.
- languageCodeA: name
- languageCodeB: name
languageCodeA: name
languageCodeB: name
descriptions: # Optional: array of descriptions keyed by language code.
- languageCodeA: description
- languageCodeB: description
languageCodeA: description
languageCodeB: description
references: #Optional
-
-
identifier: referenceId # A string used to identify the reference
attribute: attribute # An attribute to get the value of for the reference; supported: object_state_group_id, object_state_group_identifier
# The shorthand 'id' can be used instead of 'object_state_group_id'
Expand All @@ -48,13 +48,13 @@
object_state_group: x # The Id of the object state group the new state will be created under.
identifier: xyz # The string identifier of the new object state.
names: # Array of names keyed by language code.
- languageCodeA: name
- languageCodeB: name
languageCodeA: name
languageCodeB: name
descriptions: # Optional: array of descriptions keyed by language code.
- languageCodeA: description
- languageCodeB: description
languageCodeA: description
languageCodeB: description
references: #Optional
-
-
identifier: referenceId # A string used to identify the reference
attribute: attribute # An attribute to get the value of for the reference (currently supports object_state_id)
# The shorthand 'id' can be used instead of 'object_state_id'
Expand All @@ -67,13 +67,13 @@
identifier: x # string|string[] The string identifier of the object state to update. If the identifier is not unique, use group-identifier/state-identifier
identifier: x # Optional String: new identifier of the object state
names: # Optional: array of names keyed by language code.
- languageCodeA: name
- languageCodeB: name
languageCodeA: name
languageCodeB: name
descriptions: # Optional: array of descriptions keyed by language code.
- languageCodeA: description
- languageCodeB: description
languageCodeA: description
languageCodeB: description
references: #Optional
-
-
identifier: referenceId # A string used to identify the reference
attribute: attribute # An attribute to get the value of for the reference (currently supports object_state_id)
# The shorthand 'id' can be used instead of 'object_state_id'
Expand Down
2 changes: 1 addition & 1 deletion Tests/dsl/good/UnitTestOK004_content.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
sort_order: DESC
modification_date: "2006:07:08 18:11:31"
attributes:
- ezstring: hello world 3
ezstring: hello world 3
references:
-
identifier: kmb_test_2_3
Expand Down
4 changes: 2 additions & 2 deletions Tests/dsl/good/UnitTestOK012_objectState.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
eng-GB: Kaliop Migration Bundle Test Object State Group 1
roles: [1, 2] # Anon, admin
references:
-
-
identifier: kmb_test_12
attribute: id

Expand All @@ -29,7 +29,7 @@
descriptions:
eng-GB: Kaliop Migration Bundle Test Object State 1
references:
-
-
identifier: kmb_test_12_state
attribute: id

Expand Down
3 changes: 3 additions & 0 deletions WHATSNEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ Version 3.0.0-beta3

* Changes to the YML definition language:

* Creation and update of content: the format use to specify the attributes has been simplified. The old format is
still working but is considered deprecated and will be removed in the future

* Updating and deleting of Users, User Groups, Roles and Content Types: usage of a `match` key is allowed; previous
ways of defining elements to match are deprecated

Expand Down

0 comments on commit 612071c

Please sign in to comment.