Repository: pimcore/pimcore (language: php)

Issue:
[Bug]: Allowed brick types are out-of-date for versions
### Pimcore version

\>= 6

### Steps to reproduce

Similar to #2585 it is a problem that the allowed bricks get saved in a class property (and not in a getter method) because when objects get serialized, the property `$allowedTypes` will be hard-coded to the list of bricks which were available at the time when the object got saved. If later another brick gets allowed for the object brick container field and the version data gets loaded, it will not be possible to add the new brick.

Steps to reproduce:
1. Create class `Test` with object brick container field `bricks`
2. Create object brick `BrickA` and allow it for above field
3. Create object `/test` of above class, save draft version
4. Create new brick `BrickB` and allow it for above field
5. Run the following script:
```php
<?php
$object = \Pimcore\Model\DataObject\Concrete::getByPath('/test');
$version = $object->getLatestVersion();
$versionObject = $version->getData();

var_dump($versionObject->getBricks()->getAllowedBrickTypes());
```

This will return 
```
array(3) {
  [0]=>
  string(6) "BrickA"
}
```

### Expected / actual behavior

It should be possible to add newly created object bricks to restored version objects.
[Bug]: Allowed brick types are out-of-date for versions
### Pimcore version

\>= 6

### Steps to reproduce

Similar to #2585 it is a problem that the allowed bricks get saved in a class property (and not in a getter method) because when objects get serialized, the property `$allowedTypes` will be hard-coded to the list of bricks which were available at the time when the object got saved. If later another brick gets allowed for the object brick container field and the version data gets loaded, it will not be possible to add the new brick.

Steps to reproduce:
1. Create class `Test` with object brick container field `bricks`
2. Create object brick `BrickA` and allow it for above field
3. Create object `/test` of above class, save draft version
4. Create new brick `BrickB` and allow it for above field
5. Run the following script:
```php
<?php
$object = \Pimcore\Model\DataObject\Concrete::getByPath('/test');
$version = $object->getLatestVersion();
$versionObject = $version->getData();

var_dump($versionObject->getBricks()->getAllowedBrickTypes());
```

This will return 
```
array(3) {
  [0]=>
  string(6) "BrickA"
}
```

### Expected / actual behavior

It should be possible to add newly created object bricks to restored version objects.


Discussion / hints:
Thanks a lot for reporting the issue. We did not consider the issue as "Priority" or "Backlog", so we're not going to work on that anytime soon. Please create a pull request to fix the issue if this is a bug report. We'll then review it as quickly as possible. If you're interested in contributing a feature, please contact us first here before creating a pull request. We'll then decide whether we'd accept it or not. Thanks for your understanding.
@BlackbitDevs Thanks for reporting the issue. Could you please provide the version files also ? 
@aryaantony92 I have added a detail in above steps to reproduce the problem: Of course you have to allow `BrickB` to `Test.bricks` field.

Currently I do not have any version file ready. But can't you reproduce the problem with above steps? The version will automatically be created when you save the draft version (step 3).
Thanks a lot for reporting the issue. We did not consider the issue as "Priority" or "Backlog", so we're not going to work on that anytime soon. Please create a pull request to fix the issue if this is a bug report. We'll then review it as quickly as possible. If you're interested in contributing a feature, please contact us first here before creating a pull request. We'll then decide whether we'd accept it or not. Thanks for your understanding.
@BlackbitDevs Thanks for reporting the issue. Could you please provide the version files also ? 
@aryaantony92 I have added a detail in above steps to reproduce the problem: Of course you have to allow `BrickB` to `Test.bricks` field.

Currently I do not have any version file ready. But can't you reproduce the problem with above steps? The version will automatically be created when you save the draft version (step 3).

Fix patch:
diff --git a/models/DataObject/Objectbrick.php b/models/DataObject/Objectbrick.php
index c877c9e33f3..87bcb77590b 100644
--- a/models/DataObject/Objectbrick.php
+++ b/models/DataObject/Objectbrick.php
@@ -224,7 +224,7 @@ public function delete(Concrete $object): void
     public function __sleep(): array
     {
         $finalVars = [];
-        $blockedVars = ['object'];
+        $blockedVars = ['object', 'brickGetters'];
         $vars = parent::__sleep();
 
         foreach ($vars as $value) {


Test patch: