Build your datatypes
-
Upload
edi-modric -
Category
Technology
-
view
881 -
download
0
Transcript of Build your datatypes
![Page 1: Build your datatypes](https://reader033.fdocuments.net/reader033/viewer/2022052623/559b0d891a28abbd638b477e/html5/thumbnails/1.jpg)
Build your datatypes
![Page 2: Build your datatypes](https://reader033.fdocuments.net/reader033/viewer/2022052623/559b0d891a28abbd638b477e/html5/thumbnails/2.jpg)
About me
• Edi Modrić
• Computer engineering masters degree
• Working at Netgen for 5 years
• 1 year of .Net development
• 4 years of eZ Publish development
• Certified eZ Publish developer
• eZ Tags maintainer
• Collaborating with eZ Systems on ezp-next for 8 months
• @emodric
![Page 3: Build your datatypes](https://reader033.fdocuments.net/reader033/viewer/2022052623/559b0d891a28abbd638b477e/html5/thumbnails/3.jpg)
Agenda
• Primary agendas
• Build a field type using public API
• Test the hell out of it
• Secondary agendas (if time permits)
• Comparison to legacy datatypes
• Integration with eZ Publish 5 using Symfony
![Page 4: Build your datatypes](https://reader033.fdocuments.net/reader033/viewer/2022052623/559b0d891a28abbd638b477e/html5/thumbnails/4.jpg)
Workshop
• One hour of coding
• Try to build the field type and test it
• Ideas
• Try to port your existing datatype OR
• Try to modify the one presented today OR
• Some examples
• Storing dates < 1.1.1970
• Storing and validating IP address
• Storing and validating social security number
• …
• Work in groups, help each other
![Page 5: Build your datatypes](https://reader033.fdocuments.net/reader033/viewer/2022052623/559b0d891a28abbd638b477e/html5/thumbnails/5.jpg)
What is a datatype?
• Base building block of all content in eZ Publish
• Collection of methods to store, read and validate content
• Object oriented architecture of content model
• Class – blueprint of a single piece of content
• Collection of class attributes, which are of some (data)type
• Object – a single piece of content
• Instance of a class
• Collection of object attributes, values of class attribute
![Page 6: Build your datatypes](https://reader033.fdocuments.net/reader033/viewer/2022052623/559b0d891a28abbd638b477e/html5/thumbnails/6.jpg)
What is a datatype?
![Page 7: Build your datatypes](https://reader033.fdocuments.net/reader033/viewer/2022052623/559b0d891a28abbd638b477e/html5/thumbnails/7.jpg)
Datatype + public API = field type
• Initial idea was to demo the eZ Tags datatype
• Complicated
• We’re time limited
• eZ Publish 5 is nearly here
• Demo the future, not the past
![Page 8: Build your datatypes](https://reader033.fdocuments.net/reader033/viewer/2022052623/559b0d891a28abbd638b477e/html5/thumbnails/8.jpg)
Datatype + public API = field type
• Content class = Content type
• Content object = Content
• Content class attribute = Field definition
• Content object attribute = Field
• Object attribute content = Field value
• Datatype = Field type
![Page 9: Build your datatypes](https://reader033.fdocuments.net/reader033/viewer/2022052623/559b0d891a28abbd638b477e/html5/thumbnails/9.jpg)
Datatype + public API = field type
• $ cd /var/www/ezp-next/
• $ rm –rf settings/
• $ git remote add emodrichttps://github.com/emodric/ezp-next.git
• $ git checkout -b nginteger
• $ git pull emodric nginteger
• $ php composer.phar update --dev
• $ ./Netgen/runtests.sh
![Page 10: Build your datatypes](https://reader033.fdocuments.net/reader033/viewer/2022052623/559b0d891a28abbd638b477e/html5/thumbnails/10.jpg)
Datatype + public API = field type
![Page 11: Build your datatypes](https://reader033.fdocuments.net/reader033/viewer/2022052623/559b0d891a28abbd638b477e/html5/thumbnails/11.jpg)
Datatype + public API = field type
• eZ\Publish\SPI\FieldType\FieldType
• getFieldTypeIdentifier
• acceptValue / getEmptyValue
• fromHash / toHash
• fromPersistenceValue / toPersistenceValue
• getSettingsSchema / getValidatorConfigurationSchema
• validateFieldSettings / validateValidatorConfiguration
• validate
• getName
• isSearchable
![Page 12: Build your datatypes](https://reader033.fdocuments.net/reader033/viewer/2022052623/559b0d891a28abbd638b477e/html5/thumbnails/12.jpg)
Datatype + public API = field type
• eZ\Publish\SPI\FieldType\FieldStorage
• storeFieldData
• getFieldData
• deleteFieldData
• hasFieldData
• getIndexData
• eZ\Publish\SPI\FieldType\Indexable
• eZ\Publish\SPI\FieldType\ValidationError
![Page 13: Build your datatypes](https://reader033.fdocuments.net/reader033/viewer/2022052623/559b0d891a28abbd638b477e/html5/thumbnails/13.jpg)
Datatype + public API = field type
• eZ\Publish\Core\FieldType\FieldType
• Abstract that implements …\SPI\FieldType\FieldType
• Default behavior of some methods + validator handling
• eZ\Publish\Core\FieldType\[GatewayBasedStorage|Null
Storage]
• Abstracts that implement …\SPI\FieldType\FieldStorage
• eZ\Publish\Core\FieldType\StorageGateway
• Abstract for gateways to external storage
• used by GatewayBasedStorage
![Page 14: Build your datatypes](https://reader033.fdocuments.net/reader033/viewer/2022052623/559b0d891a28abbd638b477e/html5/thumbnails/14.jpg)
Datatype + public API = field type
• eZ\Publish\Core\FieldType\Value
• Abstract for field value
• Optional, but should be included
• eZ\Publish\Core\FieldType\ValidationError
• Implementation of …\SPI\FieldType\ValidationError
• eZ\Publish\Core\FieldType\Validator
• Abstract for all validators to extend
• eZ\Publish\Core\FieldType\FileService
![Page 15: Build your datatypes](https://reader033.fdocuments.net/reader033/viewer/2022052623/559b0d891a28abbd638b477e/html5/thumbnails/15.jpg)
“I thought I fixed that” - why testing matters
• Testing is an integral part of any software development
• Keeps your code rock solid
• Feature and future proof
• Gives you a piece of mind
• Testing framework in ezp-next is preconfigured BUT
• One „hack” is needed if you’re using external storage
• Updating database schema fixtures
• eZ\Publish\Core\Persistence\Legacy\Tests\_fixtures\
schema.sqlite.sql
• Dependency injection configuration
![Page 16: Build your datatypes](https://reader033.fdocuments.net/reader033/viewer/2022052623/559b0d891a28abbd638b477e/html5/thumbnails/16.jpg)
“I thought I fixed that” - why testing matters
• Testing field type integration with public API
• Using real world implementation of repository
• Tests if our field type plays well with others
• Testing field type integration with persistence SPI
• Hooks directly into persistence implementation
• Tests if our field type stores and loads data correctly
• Unit testing of the field type
• Tests the field type methods (units), one by one
![Page 17: Build your datatypes](https://reader033.fdocuments.net/reader033/viewer/2022052623/559b0d891a28abbd638b477e/html5/thumbnails/17.jpg)
What about legacy stack?
• Legacy datatypes are not going anywhere
• No admin interface based on Symfony stack
• To actually use your field type, you WILL need legacy datatype
• https://github.com/emodric/nginteger.git
• Legacy datatype prepared for comparison
![Page 18: Build your datatypes](https://reader033.fdocuments.net/reader033/viewer/2022052623/559b0d891a28abbd638b477e/html5/thumbnails/18.jpg)
Field type vs. datatype
• No difference in functionality
• Advantages over datatypes is obvious
• Much much much easier testing
• Clear separation of concerns
• No POST variables
• No SQL
• No file uploads
• More readable and understandable code
• Object oriented code