Skip to content

Commit 6511f91

Browse files
BAP-21474: Extended Entities Without Code Generation (#33445)
The approach to expanding entities has been changed, instead of generating additional fields and associations, the new approach uses PHP magic methods to access. Implementation: - ExtendEntityTrait - ExtendEntityInterface - EntityFieldExtensionInterface - ExtendedEntityFieldsProcessor For the full list of changes see the [OroPlatform Changelog for 5.1 LTS version](https://github.com/oroinc/platform/blob/master/CHANGELOG.md#510-unreleased). Co-authored-by: Andrii Yatsenko [[email protected]](mailto:[email protected]) Co-authored-by: Victor Tihonchuk [[email protected]](mailto:[email protected])
1 parent b2af980 commit 6511f91

File tree

242 files changed

+1263
-1711
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

242 files changed

+1263
-1711
lines changed

bootstrap_test.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
use Oro\Bundle\EntityExtendBundle\Test\EntityExtendTestInitializer;
4+
5+
require __DIR__.'/vendor/autoload.php';
6+
7+
EntityExtendTestInitializer::initialize();

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
77
backupGlobals="false"
88
backupStaticAttributes="false"
9-
bootstrap="vendor/autoload.php"
9+
bootstrap="bootstrap_test.php"
1010
stopOnError="false"
1111
stopOnFailure="false"
1212
stopOnWarning="false"

src/Oro/Bundle/CMSBundle/ContentVariantType/CmsPageContentVariantType.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Oro\Component\WebCatalog\ContentVariantTypeInterface;
1010
use Oro\Component\WebCatalog\Entity\ContentVariantInterface;
1111
use Symfony\Component\PropertyAccess\PropertyAccessor;
12+
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
1213
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
1314

1415
/**
@@ -26,7 +27,7 @@ class CmsPageContentVariantType implements ContentVariantTypeInterface, ContentV
2627

2728
public function __construct(
2829
AuthorizationCheckerInterface $authorizationChecker,
29-
PropertyAccessor $propertyAccessor
30+
PropertyAccessorInterface $propertyAccessor
3031
) {
3132
$this->authorizationChecker = $authorizationChecker;
3233
$this->propertyAccessor = $propertyAccessor;

src/Oro/Bundle/CMSBundle/Entity/ContentBlock.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
use Doctrine\Common\Collections\ArrayCollection;
66
use Doctrine\ORM\Mapping as ORM;
7-
use Oro\Bundle\CMSBundle\Model\ExtendContentBlock;
87
use Oro\Bundle\EntityBundle\EntityProperty\DatesAwareInterface;
98
use Oro\Bundle\EntityBundle\EntityProperty\DatesAwareTrait;
109
use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\Config;
1110
use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\ConfigField;
11+
use Oro\Bundle\EntityExtendBundle\Entity\ExtendEntityInterface;
12+
use Oro\Bundle\EntityExtendBundle\Entity\ExtendEntityTrait;
13+
use Oro\Bundle\LocaleBundle\Entity\Localization;
1214
use Oro\Bundle\LocaleBundle\Entity\LocalizedFallbackValue;
1315
use Oro\Bundle\OrganizationBundle\Entity\OrganizationAwareInterface;
1416
use Oro\Bundle\OrganizationBundle\Entity\Ownership\BusinessUnitAwareTrait;
@@ -37,13 +39,17 @@
3739
* }
3840
* }
3941
* )
42+
* @method LocalizedFallbackValue getDefaultTitle()
43+
* @method LocalizedFallbackValue getTitle(Localization $localization = null)
4044
*/
41-
class ContentBlock extends ExtendContentBlock implements
45+
class ContentBlock implements
4246
DatesAwareInterface,
43-
OrganizationAwareInterface
47+
OrganizationAwareInterface,
48+
ExtendEntityInterface
4449
{
4550
use BusinessUnitAwareTrait;
4651
use DatesAwareTrait;
52+
use ExtendEntityTrait;
4753

4854
/**
4955
* @var int
@@ -137,8 +143,6 @@ class ContentBlock extends ExtendContentBlock implements
137143
*/
138144
public function __construct()
139145
{
140-
parent::__construct();
141-
142146
$this->titles = new ArrayCollection();
143147
$this->scopes = new ArrayCollection();
144148
$this->contentVariants = new ArrayCollection();

src/Oro/Bundle/CMSBundle/Entity/ContentTemplate.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
namespace Oro\Bundle\CMSBundle\Entity;
44

55
use Doctrine\ORM\Mapping as ORM;
6-
use Oro\Bundle\CMSBundle\Model\ExtendContentTemplate;
76
use Oro\Bundle\EntityBundle\EntityProperty\DatesAwareInterface;
87
use Oro\Bundle\EntityBundle\EntityProperty\DatesAwareTrait;
98
use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\Config;
109
use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\ConfigField;
10+
use Oro\Bundle\EntityExtendBundle\Entity\ExtendEntityInterface;
11+
use Oro\Bundle\EntityExtendBundle\Entity\ExtendEntityTrait;
1112
use Oro\Bundle\OrganizationBundle\Entity\OrganizationAwareInterface;
1213
use Oro\Bundle\UserBundle\Entity\Ownership\UserAwareTrait;
1314

@@ -44,10 +45,11 @@
4445
* }
4546
* )
4647
*/
47-
class ContentTemplate extends ExtendContentTemplate implements DatesAwareInterface, OrganizationAwareInterface
48+
class ContentTemplate implements DatesAwareInterface, OrganizationAwareInterface, ExtendEntityInterface
4849
{
4950
use DatesAwareTrait;
5051
use UserAwareTrait;
52+
use ExtendEntityTrait;
5153

5254
/**
5355
* @ORM\Id

src/Oro/Bundle/CMSBundle/Entity/ImageSlide.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
namespace Oro\Bundle\CMSBundle\Entity;
44

55
use Doctrine\ORM\Mapping as ORM;
6-
use Oro\Bundle\CMSBundle\Model\ExtendImageSlide;
6+
use Oro\Bundle\AttachmentBundle\Entity\File;
77
use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\Config;
88
use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\ConfigField;
9+
use Oro\Bundle\EntityExtendBundle\Entity\ExtendEntityInterface;
10+
use Oro\Bundle\EntityExtendBundle\Entity\ExtendEntityTrait;
911
use Oro\Bundle\OrganizationBundle\Entity\OrganizationAwareInterface;
1012
use Oro\Bundle\OrganizationBundle\Entity\Ownership\OrganizationAwareTrait;
1113

@@ -30,10 +32,17 @@
3032
* }
3133
* }
3234
* )
35+
* @method null|File getMainImage()
36+
* @method ImageSlide setMainImage(File $image)
37+
* @method null|File getMediumImage()
38+
* @method ImageSlide setMediumImage(File $image)
39+
* @method null|File getSmallImage()
40+
* @method ImageSlide setSmallImage(File $image)
3341
*/
34-
class ImageSlide extends ExtendImageSlide implements OrganizationAwareInterface
42+
class ImageSlide implements OrganizationAwareInterface, ExtendEntityInterface
3543
{
3644
use OrganizationAwareTrait;
45+
use ExtendEntityTrait;
3746

3847
public const TEXT_ALIGNMENT_CENTER = 'center';
3948
public const TEXT_ALIGNMENT_LEFT = 'left';

src/Oro/Bundle/CMSBundle/Entity/LoginPage.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
namespace Oro\Bundle\CMSBundle\Entity;
44

55
use Doctrine\ORM\Mapping as ORM;
6-
use Oro\Bundle\CMSBundle\Model\ExtendLoginPage;
6+
use Oro\Bundle\AttachmentBundle\Entity\File;
77
use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\Config;
88
use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\ConfigField;
9+
use Oro\Bundle\EntityExtendBundle\Entity\ExtendEntityInterface;
10+
use Oro\Bundle\EntityExtendBundle\Entity\ExtendEntityTrait;
911

1012
/**
13+
* Login page entity class.
14+
*
1115
* @ORM\Table(name="oro_cms_login_page")
1216
* @ORM\Entity()
1317
* @Config(
@@ -26,9 +30,15 @@
2630
* }
2731
* }
2832
* )
33+
* @method File getLogoImage()
34+
* @method LoginPage setLogoImage(File $image)
35+
* @method File getBackgroundImage()
36+
* @method LoginPage setBackgroundImage(File $image)
2937
*/
30-
class LoginPage extends ExtendLoginPage
38+
class LoginPage implements ExtendEntityInterface
3139
{
40+
use ExtendEntityTrait;
41+
3242
/**
3343
* @var integer
3444
*

src/Oro/Bundle/CMSBundle/Entity/Page.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
use Doctrine\Common\Collections\ArrayCollection;
66
use Doctrine\Common\Collections\Collection;
77
use Doctrine\ORM\Mapping as ORM;
8-
use Oro\Bundle\CMSBundle\Model\ExtendPage;
98
use Oro\Bundle\DraftBundle\Entity\DraftableInterface;
109
use Oro\Bundle\DraftBundle\Entity\DraftableTrait;
1110
use Oro\Bundle\EntityBundle\EntityProperty\DatesAwareInterface;
1211
use Oro\Bundle\EntityBundle\EntityProperty\DatesAwareTrait;
1312
use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\Config;
1413
use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\ConfigField;
14+
use Oro\Bundle\EntityExtendBundle\Entity\ExtendEntityInterface;
15+
use Oro\Bundle\EntityExtendBundle\Entity\ExtendEntityTrait;
16+
use Oro\Bundle\LocaleBundle\Entity\Localization;
1517
use Oro\Bundle\LocaleBundle\Entity\LocalizedFallbackValue;
1618
use Oro\Bundle\OrganizationBundle\Entity\OrganizationAwareInterface;
1719
use Oro\Bundle\OrganizationBundle\Entity\Ownership\AuditableOrganizationAwareTrait;
@@ -87,17 +89,26 @@
8789
* }
8890
* }
8991
* )
92+
* @method LocalizedFallbackValue getTitle(Localization $localization = null)
93+
* @method LocalizedFallbackValue getDefaultTitle()
94+
* @method LocalizedFallbackValue getSlug(Localization $localization = null)
95+
* @method LocalizedFallbackValue getDefaultSlug()
96+
* @method setDefaultTitle($title)
97+
* @method setDefaultSlug($slug)
98+
* @method $this cloneLocalizedFallbackValueAssociations()
9099
*/
91-
class Page extends ExtendPage implements
100+
class Page implements
92101
DatesAwareInterface,
93102
SluggableInterface,
94103
DraftableInterface,
95-
OrganizationAwareInterface
104+
OrganizationAwareInterface,
105+
ExtendEntityInterface
96106
{
97107
use AuditableOrganizationAwareTrait;
98108
use DatesAwareTrait;
99109
use SluggableTrait;
100110
use DraftableTrait;
111+
use ExtendEntityTrait;
101112

102113
/**
103114
* @var integer
@@ -163,8 +174,6 @@ class Page extends ExtendPage implements
163174
*/
164175
public function __construct()
165176
{
166-
parent::__construct();
167-
168177
$this->slugPrototypes = new ArrayCollection();
169178
$this->slugs = new ArrayCollection();
170179
$this->titles = new ArrayCollection();
@@ -245,7 +254,7 @@ public function __toString()
245254
public function __clone()
246255
{
247256
if ($this->id) {
248-
$this->cloneLocalizedFallbackValueAssociations();
257+
$this->cloneExtendEntityStorage();
249258
}
250259
}
251260
}

src/Oro/Bundle/CMSBundle/Entity/TabbedContentItem.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
namespace Oro\Bundle\CMSBundle\Entity;
44

55
use Doctrine\ORM\Mapping as ORM;
6-
use Oro\Bundle\CMSBundle\Model\ExtendTabbedContentItem;
76
use Oro\Bundle\EntityBundle\EntityProperty\DatesAwareInterface;
87
use Oro\Bundle\EntityBundle\EntityProperty\DatesAwareTrait;
98
use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\Config;
109
use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\ConfigField;
10+
use Oro\Bundle\EntityExtendBundle\Entity\ExtendEntityInterface;
11+
use Oro\Bundle\EntityExtendBundle\Entity\ExtendEntityTrait;
1112
use Oro\Bundle\OrganizationBundle\Entity\OrganizationAwareInterface;
1213
use Oro\Bundle\OrganizationBundle\Entity\Ownership\OrganizationAwareTrait;
1314

@@ -33,10 +34,14 @@
3334
* }
3435
* )
3536
*/
36-
class TabbedContentItem extends ExtendTabbedContentItem implements OrganizationAwareInterface, DatesAwareInterface
37+
class TabbedContentItem implements
38+
OrganizationAwareInterface,
39+
DatesAwareInterface,
40+
ExtendEntityInterface
3741
{
3842
use OrganizationAwareTrait;
3943
use DatesAwareTrait;
44+
use ExtendEntityTrait;
4045

4146
/**
4247
* @ORM\Column(type="integer")

src/Oro/Bundle/CMSBundle/ImportExport/Normalizer/LocalizedFallbackValueCollectionNormalizer.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Oro\Bundle\CMSBundle\ImportExport\Normalizer;
44

5+
use Oro\Bundle\EntityExtendBundle\EntityPropertyInfo;
56
use Oro\Bundle\LocaleBundle\Entity\LocalizedFallbackValue;
67
use Oro\Bundle\LocaleBundle\ImportExport\Normalizer\LocalizationCodeFormatter;
78
use Oro\Bundle\LocaleBundle\ImportExport\Normalizer\LocalizedFallbackValueCollectionNormalizer as BaseNormalizer;
@@ -21,7 +22,9 @@ public function normalize($object, string $format = null, array $context = []):
2122
foreach ($object as $item) {
2223
$key = LocalizationCodeFormatter::formatName($item->getLocalization());
2324

24-
$result[$key]['wysiwyg'] = method_exists($item, 'getWysiwyg') ? $item->getWysiwyg() : null;
25+
$result[$key]['wysiwyg'] = EntityPropertyInfo::methodExists($item, 'getWysiwyg')
26+
? $item->getWysiwyg()
27+
: null;
2528
}
2629

2730
return $result;
@@ -42,7 +45,7 @@ public function denormalize($data, string $type, string $format = null, array $c
4245
/** @var LocalizedFallbackValue $object */
4346
$object = $result->get($localizationName);
4447

45-
if (method_exists($object, 'getWysiwyg')) {
48+
if (EntityPropertyInfo::methodExists($object, 'setWysiwyg')) {
4649
$object->setWysiwyg((string)$item['wysiwyg']);
4750
}
4851
}

0 commit comments

Comments
 (0)