This topic contains 5 replies, has 2 voices, and was last updated by gmustiere 6 years ago.
- Topic
Hello,
OroCrm 2.6
I extended the oro_contact entity with an enum type field following this guide (https://github.com/oroinc/platform/tree/master/src/Oro/Bundle/EntityExtendBundle#add-option-set-field), the migration and data generation happens correctly during installation, however the class generated with the cache does not provide me with a GET/SET method. Have I forgotten an option to give o my migration scheme ?
Migration :
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354<?phpnamespace AppBundle\Migrations\Schema\V1_22;use Doctrine\DBAL\Schema\Schema;use Oro\Bundle\EntityExtendBundle\EntityConfig\ExtendScope;use Oro\Bundle\EntityExtendBundle\Migration\Extension\ExtendExtension;use Oro\Bundle\EntityExtendBundle\Migration\Extension\ExtendExtensionAwareInterface;use Oro\Bundle\MigrationBundle\Migration\Migration;use Oro\Bundle\MigrationBundle\Migration\QueryBag;/*** Class AddOtherSearchTypesToOrocmAccount** @package AppBundle\Migrations\Schema\V1_22*/class AddValidationFieldToContact implements Migration, ExtendExtensionAwareInterface{/*** @var ExtendExtension*/private $extendExtension;CONST SCHEMA_VALIDATION_STATE_ASSOCATION_NAME = 'contact_validation_state';CONST SCHEMA_VALIDATION_STATE_ENUM_CODE = 'validation_state';/*** @param ExtendExtension $extendExtension*/public function setExtendExtension(ExtendExtension $extendExtension){$this->extendExtension = $extendExtension;}/*** @param Schema $schema* @param QueryBag $queries*/public function up(Schema $schema, QueryBag $queries){$table = $schema->getTable('orocrm_contact');$this->extendExtension->addEnumField($schema,$table,self::SCHEMA_VALIDATION_STATE_ASSOCATION_NAME,self::SCHEMA_VALIDATION_STATE_ENUM_CODE,false,false,['extend' => ['owner' => ExtendScope::OWNER_CUSTOM, 'without_default' => true]]);}}Load data :
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455<?php<?phpnamespace AppBundle\Migrations\Data\ORM;use AppBundle\Migrations\Schema\V1_22\AddValidationFieldToContact;use Doctrine\Common\DataFixtures\FixtureInterface;use Doctrine\Common\Persistence\ObjectManager;use Oro\Bundle\ContactBundle\Entity\Contact;use Oro\Bundle\ContactBundle\Entity\Source;use Oro\Bundle\EntityExtendBundle\Entity\Repository\EnumValueRepository;use Oro\Bundle\EntityExtendBundle\Tools\ExtendHelper;/*** Class LoadSources** @package AppBundle\Migrations\Data\ORM*/class LoadValidation implements FixtureInterface{CONST STATE_VALIDATION_ACCEPTED = 'acceptée';CONST STATE_VALIDATION_REFUSED = 'refusée';CONST STATE_VALIDATION_UNTRAITED = 'non-traitée';/*** @var array*/protected $data = [self::STATE_VALIDATION_ACCEPTED => false,self::STATE_VALIDATION_REFUSED => false,self::STATE_VALIDATION_UNTRAITED => true];/*** @param ObjectManager $manager** @throws \InvalidArgumentException*/public function load(ObjectManager $manager){$className = ExtendHelper::buildEnumValueClassName(AddValidationFieldToContact::SCHEMA_VALIDATION_STATE_ENUM_CODE);/** @var EnumValueRepository $enumRepo */$enumRepo = $manager->getRepository($className);$priority = 1;foreach ($this->data as $name => $isDefault) {$enumOption = $enumRepo->createEnumValue($name, $priority++, $isDefault);$manager->persist($enumOption);}$manager->flush();}}EV_class :
123456789101112<?php<?phpnamespace Extend\Entity;class EV_Validation_State extends \Oro\Bundle\EntityExtendBundle\Entity\AbstractEnumValue implements \Oro\Bundle\EntityExtendBundle\Entity\ExtendEntityInterface{public function __construct($id, $name, $priority = 0, $default = false){parent::__construct($id, $name, $priority, $default);}}Business logic :
123456789101112131415161718192021foreach ($uow->getScheduledEntityUpdates() as $entity) {if ($entity instanceof Contact && isset($uow->getEntityChangeSet($entity)[AddValidationFieldToContact::SCHEMA_VALIDATION_STATE_ASSOCATION_NAME])) {//I expect to have a method like that... but no$stavelidation = $entity->getContactValidationState();$stateValidation = LoadValidation::STATE_VALIDATION_ACCEPTED;if (LoadValidation::STATE_VALIDATION_ACCEPTED === $stateValidation) {$this->createOrAttachAccountFromContactHandler->handle($entity);$this->addContactFromSSOHandler->handle($entity);break;}$stateValidation = LoadValidation::STATE_VALIDATION_REFUSED;if (LoadValidation::STATE_VALIDATION_REFUSED === $stateValidation) {$this->removeContactFromSSOHandler->handle($entity);break;}}}Thank you for your help
Br.
Gabriel
The forum ‘OroCRM – Programming Questions’ is closed to new topics and replies.