Working with oro crm entities

19
Working with OroCRM Entities Working with OroCRM Entities

Transcript of Working with oro crm entities

Page 1: Working with oro crm entities

Working with OroCRM Entities

Working with OroCRM Entities

Page 2: Working with oro crm entities

Working with OroCRM Entities

Agenda

• Doctrine entity

• Configurable entity

• Extended entity

Page 3: Working with oro crm entities

Working with OroCRM Entities

Doctrine Entity

Page 4: Working with oro crm entities

Working with OroCRM Entities

Overview

Entities are PHP objects that can be identified over many requests by a unique identifier or primary key. These classes don’t need to extend any abstract base class or interface. An entity class must not be final or contain final methods. Additionally it must not implement clone nor wakeup or do so safely.An entity contains persistable properties. A persistable property is an instance variable of the entity that is saved into and retrieved from the database by Doctrine’s data mapping capabilities.

Doctrine 2 ORM Documentationhttp://docs.doctrine-project.org/projects/doctrine-orm/en/latest/tutorials/getting-started.

html

Doctrine Entity

Page 5: Working with oro crm entities

Working with OroCRM Entities

How to add Doctrine entity?

● Create PHP Class to represent DB table, e.g. Acme\Bundle\HotelBundle\Entity\Hotel

● Use Doctrine\ORM\Mapping to add Doctrine annotation to class

● Create Oro Migration DB tables schema, e.g. acme_hotel

● Command oro:migration:load

You can find more about Doctrine ORM in the documentationhttp://docs.doctrine-project.org/projects/doctrine-orm/en/latest/index.html

Doctrine Entity

Page 6: Working with oro crm entities

Working with OroCRM Entities

Oro Migrations

● Bundle defines it’s own tables in the database schema

● Incremental change of database schema is placed in separate migration class

● Each migration class has it own version

Doctrine Entity

Page 7: Working with oro crm entities

Working with OroCRM Entities

Configurable Entity

Page 8: Working with oro crm entities

Working with OroCRM Entities

Overview and Features• Two levels of configuration: entity and entity field• Support of different configuration scopes• Configuration schema:

BundleName/Resources/config/entity_config.yml

• Access to configuration field values is provided by services

• Users with the appropriate permissions can configure entities in the UI without changing the source code

Configurable Entity

Page 9: Working with oro crm entities

Working with OroCRM Entities

Define configuration schema

• Bundle may contain a file with the configuration schema:BundleName/Resources/config/entity_config.yml

• The file contains config property definitions of an entity, field levels, and options used in the UI to display properties of these configurations.

Configurable Entity

Page 10: Working with oro crm entities

Working with OroCRM Entities

Configuration Provider Service

Each configuration scope generates a service with specific id. For example, if the scope name is entity, the service id will be oro_entity_config.provider.entity. This service may be used to obtain configuration of the specific scope, class and field.

Implemented byOro\Bundle\EntityConfigBundle\Provider\

ConfigProviderInterface

Configurable Entity

Page 11: Working with oro crm entities

Working with OroCRM Entities

Add entity annotations

• Annotation classesOro\Bundle\EntityConfigBundle\Metadata\Annotation\Config

Oro\Bundle\EntityConfigBundle\Metadata\Annotation\ConfigField

• Example of @Config and @ConfigField annotations in an entity.

Configurable Entity

Page 12: Working with oro crm entities

Working with OroCRM Entities

Commandsoro:entity-config:updateThis command can be used to update configurable entities.

oro:entity-config:cache:clearThis command removes all data related to configurable entities from the application cache.

oro:entity-config:debugDebugging entity configuration.

Configurable Entity

Page 13: Working with oro crm entities

Working with OroCRM Entities

Extended Entity

Page 14: Working with oro crm entities

Working with OroCRM Entities

Features

• Add fields dynamically using configuration

• Add/remove fields dynamically using UI configuration

• Show dynamic fields on view, form and grid

• Support dynamic relations to other entities

Extended Entity

Page 15: Working with oro crm entities

Working with OroCRM Entities

Creating Extended Entity

1. Create extend entity class with special name2. Make inherit entity class from existing extend entity3. Create migration4. Run oro:migration:load command

Example Acme\Bundle\HotelBundle\Entity\Hotel extends Acme\Bundle\HotelBundle\Model\ExtendHotel

Extended Entity

Page 16: Working with oro crm entities

Working with OroCRM Entities

Adding Fields to Extended Entity

• Using UI

• Using migrations

Extended Entity

Page 17: Working with oro crm entities

Working with OroCRM Entities

oro:entity-extend:cache:clear

This command removes all entity extend functionality data from the application cache.

oro:entity-extend:update-config

This command prepares configuration for extended entities.

oro:migration:load

This command updates extend entity cache and makes the necessary schema updates.

CommandsExtended Entity

Page 18: Working with oro crm entities

Working with OroCRM Entities

Summary

• All entities in OroCRM are based on Doctrine Entity.

• Configurable entity can store an entity or a field metadata

• New fields can be added to an existing entity without alternating the entity source code

• All changes in the entity structure and entity configuration should be included into the migration classes

Extended Entity

Page 19: Working with oro crm entities

Working with OroCRM Entities

Q & A

Pavel [email protected]