Skip to content

Commit

Permalink
Fun with interfaces; allow more reference resolving in ContentType defs
Browse files Browse the repository at this point in the history
  • Loading branch information
gggeek committed May 2, 2018
1 parent 77bddec commit bed8266
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
9 changes: 9 additions & 0 deletions Core/Executor/ContentTypeManager.php
Expand Up @@ -100,6 +100,10 @@ protected function create($step)
$maxFieldDefinitionPos = 0;
$fieldDefinitions = array();
foreach ($step->dsl['attributes'] as $position => $attribute) {
// allow easy reuse of attribute defs by storing them in references
if (is_string($attribute)) {
$attribute = $this->referenceResolver->resolveReference($attribute);
}
$fieldDefinition = $this->createFieldDefinition($contentTypeService, $attribute, $contentTypeIdentifier, $lang);
$maxFieldDefinitionPos = $fieldDefinition->position > $maxFieldDefinitionPos ? $fieldDefinition->position : $maxFieldDefinitionPos;
$fieldDefinitions[] = $fieldDefinition;
Expand Down Expand Up @@ -205,6 +209,11 @@ protected function update($step)
$newFieldDefinitions = array();
foreach ($step->dsl['attributes'] as $attribute) {

// allow easy reuse of attribute defs by storing them in references
if (is_string($attribute)) {
$attribute = $this->referenceResolver->resolveReference($attribute);
}

$existingFieldDefinition = $this->contentTypeHasFieldDefinition($contentType, $attribute['identifier']);

if ($existingFieldDefinition) {
Expand Down
2 changes: 1 addition & 1 deletion Core/Executor/RepositoryExecutor.php
Expand Up @@ -235,7 +235,7 @@ protected function getCollectionName($collection)

/**
* Courtesy code to avoid reimplementing it in every subclass
* @deprecated will be moved into the reference resolver classes
* @todo will be moved into the reference resolver classes
*/
protected function resolveReferencesRecursively($match)
{
Expand Down
4 changes: 2 additions & 2 deletions Core/ReferenceResolver/ChainResolver.php
Expand Up @@ -4,12 +4,12 @@

use Kaliop\eZMigrationBundle\API\ReferenceResolverInterface;
use Kaliop\eZMigrationBundle\API\ReferenceBagInterface;
use Kaliop\eZMigrationBundle\API\ReferenceResolverBagInterface;
use Kaliop\eZMigrationBundle\API\EmbeddedReferenceResolverBagInterface;
use Kaliop\eZMigrationBundle\API\EnumerableReferenceResolverInterface;
use Kaliop\eZMigrationBundle\API\EmbeddedReferenceResolverInterface;
use Kaliop\eZMigrationBundle\API\Exception\ReferenceUnresolvedException;

class ChainResolver implements ReferenceResolverBagInterface, EnumerableReferenceResolverInterface, EmbeddedReferenceResolverInterface
class ChainResolver implements EmbeddedReferenceResolverBagInterface, EnumerableReferenceResolverInterface
{
/** @var ReferenceResolverInterface[] $resolvers */
protected $resolvers = array();
Expand Down
16 changes: 14 additions & 2 deletions WHATSNEW.md
Expand Up @@ -18,8 +18,20 @@ Version 4.8

```
match:
remote_content_id: "something [reference:myref] different"
# we get remote_content_id = "something 99 different"
remote_content_id: "something [reference:myref] times different"
# we get remote_content_id = "something 99 times different"
```

* New: when creating and updating ContentType definitions, it is possible to use a reference to define each field. The
value of the reference must be an array with all the usual keys: 'name', 'searchable', etc...
This makes it easy to define multiple ContentTypes sharing fields with the same definition such as f.e. the 'title'

```
attributes:
title: "reference:title_field_definition"
body:
name: Body
...
```


Expand Down

0 comments on commit bed8266

Please sign in to comment.