-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE: Allow setting variable stage widths
Relates: #500
- Loading branch information
Showing
5 changed files
with
95 additions
and
7 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
...eosIo/Classes/ContentRepository/Transformations/RenameAndUpdatePropertyTransformation.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neos\NeosIo\ContentRepository\Transformations; | ||
|
||
use Neos\ContentRepository\Domain\Model\NodeData; | ||
use Neos\ContentRepository\Migration\Transformations\AbstractTransformation; | ||
|
||
/** | ||
* Rename a given property and replace its value based on the previous value. | ||
*/ | ||
class RenameAndUpdatePropertyTransformation extends AbstractTransformation | ||
{ | ||
protected string $oldPropertyName; | ||
protected string $newPropertyName; | ||
protected mixed $oldValue; | ||
protected mixed $newValue; | ||
|
||
public function setFrom(string $oldPropertyName): void | ||
{ | ||
$this->oldPropertyName = $oldPropertyName; | ||
} | ||
|
||
public function setTo(string $newPropertyName): void | ||
{ | ||
$this->newPropertyName = $newPropertyName; | ||
} | ||
|
||
public function setOldValue(mixed $oldValue): void | ||
{ | ||
$this->oldValue = $oldValue; | ||
} | ||
|
||
public function setNewValue(mixed $newValue): void | ||
{ | ||
$this->newValue = $newValue; | ||
} | ||
|
||
/** | ||
* Returns true if the given node has a property with the name to work on | ||
* and does not yet have a property with the name to rename that property to. | ||
*/ | ||
public function isTransformable(NodeData $node): bool | ||
{ | ||
return ($node->hasProperty($this->oldPropertyName) && !$node->hasProperty($this->newPropertyName)); | ||
} | ||
|
||
/** | ||
* Renames the configured property to the new name if it's value matches, if not it is removed | ||
*/ | ||
public function execute(NodeData $node): void | ||
{ | ||
$oldPropertyValue = $node->getProperty($this->oldPropertyName); | ||
if ($oldPropertyValue === $this->oldValue) { | ||
$node->setProperty($this->newPropertyName, $this->newValue); | ||
} | ||
$node->removeProperty($this->oldPropertyName); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
DistributionPackages/Neos.NeosIo/Migrations/ContentRepository/Version20230726143110.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
up: | ||
comments: 'Adjust max width property for stages' | ||
migration: | ||
- filters: | ||
- type: 'NodeType' | ||
settings: | ||
nodeType: 'Neos.NeosIo:Stage' | ||
withSubTypes: true | ||
transformations: | ||
- type: 'Neos\NeosIo\ContentRepository\Transformations\RenameAndUpdatePropertyTransformation' | ||
settings: | ||
from: 'isContentFullWidth' | ||
to: 'contentWidth' | ||
oldValue: true | ||
newValue: 'full' | ||
down: | ||
comments: 'No down migration available' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters