Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,27 @@ $contentType->unpublish();
$contentType->delete();
```

Changing the ID of a content type field:

``` php
$oldFieldId = 'oldFieldId';
$newFieldId = 'newFieldId';
$contentType = $environmentProxy->getContentType($contentTypeId);
$field = $contentType->getField($oldFieldId);
$field->setNewId($newFieldId);
$fields = $contentType->getFields();
foreach ($fields as $index => $currentField) {
if ($currentField->getId() === $oldFieldId) {
$fields[$index] = $field;
break;
}
}
$contentType->setFields($fields);
$contentType->update();
$contentType->publish();
```


### Editor interfaces

Fetching and updating
Expand Down
26 changes: 26 additions & 0 deletions src/Resource/ContentType/Field/BaseField.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ abstract class BaseField implements FieldInterface
*/
protected $id;

/**
* New ID of the Field for renaming.
*
* @var ?string
*/
protected $newId = null;

/**
* Name of the Field.
*
Expand Down Expand Up @@ -81,6 +88,21 @@ public function getId(): string
return $this->id;
}

public function getNewId(): ?string
{
return $this->newId;
}

/**
* @return static
*/
public function setNewId(string $newId)
{
$this->newId = $newId;

return $this;
}

public function getName(): string
{
return $this->name;
Expand Down Expand Up @@ -220,6 +242,10 @@ public function jsonSerialize(): array
$data['validations'] = $this->validations;
}

if (!is_null($this->newId)) {
$data['newId'] = $this->newId;
}

return $data;
}
}