Extension Development with Extbase

Extension Development with Extbase

The Extbase MVC framework has been actively used in the TYPO3 world for almost ten years. Shifting from individual applications to a streamlined framework providing routing, object-relational mapping, form & validation handling and connecting to the Fluid rendering engine improved defined common processes for developing applications. Albeit Extbase has strict conventions concerning naming, configuration, and implementation details, it offers already a good foundation for building new applications - considering a couple of key aspects allows developers to create even more individual and stable components.

This session focuses on analyzing the distinct sub-components of the Extbase MVC framework. It aims to demonstrate and explain technical details for different use-cases and aims to enable developers using the appropriate techniques that are required according to building applications.

D16de7219f9aafbb6f83eff20ba86229?s=128

Benjamin Kott

August 02, 2019
Tweet

Transcript

  1. EXTENSION DEVELOPMENT WITH EXTBASE TYPO3 info@typo3.com @typo3 August 2nd, 2019

    Karlsruhe, Germany
  2. OLIVER HADER  Research & Development  Security Team Lead

     Darth Hader @ohader oliver.hader@typo3.org
  3. BENJAMIN KOTT  Developer Advocate  Consultant  UI/UX Lead

    @benjaminkott benjamin.kott@typo3.com
  4. 1. Introduction 2. Persistence Variations 3. Software Architecture 4. Caching

    5. Bonus+
  5. EXTBASE IN A NUTSHELL

  6. EXTBASE LAYERS Application Layer Repository query builder Object Relational Mapping

    model reconstitution Services reusable processing Infrastructure Layer View output rendering Validation controller / domain Domain Model business logic Schema Doctrine DBAL Relation Handling (basically based on TCA) Behavior (often mixed in controllers) Extbase Routing Property Mapping model reconstitution View Helpers output functions Controller orchestration & delegation TYPO3 Routing Invocation CLI request HTTP request Domain Layer Presentation Layer Application Dispatcher symfony/routing plugin configuration TypoScript settings Orchestration controller actions action arguments domain invocation infrastructure invocation presentation invocation Templating Engine Fluid, Twig, Blade, … HTML, XML, JSON, …
  7. EXTBASE SECURITY ASPECTS  Extbase application is "accessible" by everybody

     no user or permission management in frontend  controller-action can be called directly .../?tx[controller]=User&tx[action]=delete&…  access control must be done individually  either by using dedicated plugins & frontend groups  or in each controller, authorizing actins (suggested)
  8. This "protection" just concerns the visual output

  9. PERSISTENCE

  10.  Kickstarted with Extension Builder  Good for getting started

     Must be adjusted
  11. CAR RENTAL EXAMPLE # vin: string # color: string #

    brand: Brand # charge: Charge # tires: Tire[] # rentals: Rental[] # maintenances: Maintenance[] # images: FileReference[] <<Aggregate Root>> Car + get…() + set…() # startDate: DateTime # endDate: DateTime # returnDate: DateTime # customer: Customer # agent: Agent # car: Car Rental + get…() + set…() # name: string Brand + get…() + set…() # treadDepth: float # pressure: float Tire + get…() + set…() # issueDate: DateTime # mechanic: Mechanic # car: Car Maintenance + get…() + set…() # name: string # price: float Charge + get…() + set…() # employeeNumber <<abstract>> Employee + get…() + set…() Customer Mechanic Agent # username # password # firstName # lastName # email # telephone # … Extbase\…\FrontendUser + get…() + set…() 1 1 1 1 1 n 1 1 1 1 1 1 1 1 n n # uidLocal: int Extbase\…\FileReference + getOriginalResource(): FileReference # originalResource: ResourceInterface Extbase\…\AbstractFileFolder + getOriginalResource(): ResourceInterface
  12. None
  13.  LazyLoading 1:n (ObjectStorage)  LazyLoading 1:1 (LazyLoadingProxy)  and

    current drawbacks in implementation
  14. None
  15.  Using Doctrine DBAL QueryBuilder  Using custom query statements

     In order to be more flexible  Submitted data must be escaped/casted (security)
  16.  Omitting ORM layer, retrieve raw-data (array)  Pros &

    Cons of working with arrays or objects
  17. SOFTWARE ARCHITECTURE

  18. CAR RENTAL EXAMPLE # vin: string # color: string #

    brand: Brand # charge: Charge # tires: Tire[] # rentals: Rental[] # maintenances: Maintenance[] # images: FileReference[] <<Aggregate Root>> Car + get…() + set…() # startDate: DateTime # endDate: DateTime # returnDate: DateTime # customer: Customer # agent: Agent # car: Car Rental + get…() + set…() # name: string Brand + get…() + set…() # treadDepth: float # pressure: float Tire + get…() + set…() # issueDate: DateTime # mechanic: Mechanic # car: Car Maintenance + get…() + set…() # name: string # price: float Charge + get…() + set…() # employeeNumber <<abstract>> Employee + get…() + set…() Customer Mechanic Agent # username # password # firstName # lastName # email # telephone # … Extbase\…\FrontendUser + get…() + set…() 1 1 1 1 1 n 1 1 1 1 1 1 1 1 n n # uidLocal: int Extbase\…\FileReference + getOriginalResource(): FileReference # originalResource: ResourceInterface Extbase\…\AbstractFileFolder + getOriginalResource(): ResourceInterface
  19. CAR RENTAL EXAMPLE

  20. CAR RENTAL EXAMPLE PRO  Car aggregate root  Everything

    available  Single entry point  Comfortable CON  Lots of DB queries  Memory footprint  Performance impact  Growing amount of associations
  21. CAR RENTAL EXAMPLE – BOUNDED CONTEXTS  Separate into contexts/scenarios

     Rental  Presenting cars  Handling reservations & rentals  Handle booking & pricing  Maintenance  Maintaining car  Check tires  Document actions
  22. CAR RENTAL EXAMPLE – BOUNDED CONTEXTS Extbase Maintenance Common Rental

    # vin: string # color: string # brand: Brand # tires: Tire[] # maintenances: Maintenance[] <<Aggregate Root>> Maintenance\Car + get…() + set…() # startDate: DateTime # endDate: DateTime # returnDate: DateTime # customer: Customer # agent: Agent # car: Car Rental + get…() + set…() # name: string Brand + get…() + set…() # treadDepth: float # pressure: float Tire + get…() + set…() # issueDate: DateTime # mechanic: Mechanic # car: Car Maintenance + get…() + set…() # name: string # price: float Charge + get…() + set…() # employeeNumber <<abstract>> Employee + get…() + set…() Customer Mechanic Agent # username # password # firstName # lastName # email # telephone # … Extbase\…\FrontendUser + get…() + set…() 1 1 1 1 1 1 1 1 n n # uidLocal: int Extbase\…\FileReference + getOriginalResource(): FileReference # originalResource: ResourceInterface Extbase\…\AbstractFileFolder + getOriginalResource(): ResourceInterface # vin: string # color: string # brand: Brand # rentals: Rental[] # images: FileReference[] <<Aggregate Root>> Rental\Car + get…() + set…() 1 1 1 1 n 1 1 1
  23. None
  24. None
  25. None
  26. CAR RENTAL EXAMPLE – BOUNDED CONTEXTS

  27. CAR RENTAL EXAMPLE - INHERITANCE  Agent extends Employee extends

    FrontendUser  Inheritance tree is probably too large  Superfluous information is retrieved  Only customerId, employeeId, … are required  Full FrontendUser used for authentication (In this case: username & password in View)
  28. CAR RENTAL EXAMPLE - INHERITANCE Extbase Maintenance Common Rental #

    vin: string # color: string # brand: Brand # tires: Tire[] # maintenances: Maintenance[] <<Aggregate Root>> Maintenance\Car + get…() + set…() # startDate: DateTime # endDate: DateTime # returnDate: DateTime # customer: Customer # agent: Agent # car: Car Rental + get…() + set…() # name: string Brand + get…() + set…() # treadDepth: float # pressure: float Tire + get…() + set…() # issueDate: DateTime # mechanic: Mechanic # car: Car Maintenance + get…() + set…() # name: string # price: float Charge + get…() + set…() # frontendUserId: int # customerId: string Customer + get…() + set…() # frontendUserId: int # employeeNumber: string Mechanic + get…() + set…() # frontendUserId: int # employeeNumber: string Agent + get…() + set…() # username # password # firstName # lastName # email # telephone # … Extbase\…\FrontendUser + get…() + set…() 1 1 1 1 1 1 1 1 n n # uidLocal: int Extbase\…\FileReference + getOriginalResource(): FileReference # originalResource: ResourceInterface Extbase\…\AbstractFileFolder + getOriginalResource(): ResourceInterface # vin: string # color: string # brand: Brand # rentals: Rental[] # images: FileReference[] <<Aggregate Root>> Rental\Car + get…() + set…() 1 1 1 1 n 1 1 1 FrontendUserService + retrieveUserById(int $id)
  29. CAR RENTAL EXAMPLE – PLUGIN & CONTROLLER ORCHESTRATION  Using

    Extbase plugin configuration  Should only contain required controller-actions  Permissions on plugin level (frontend groups)  Avoids potential side effects
  30. None
  31. None
  32. None
  33. None
  34. None
  35. None
  36. None
  37. PROBLEMS  Every request fetches data from an external endpoint

     Reaching API-Limits quickly  Probably gets expensive  Bonus: Slow  Question: How often does the weather change?
  38. CACHING FRAMEWORK

  39. None
  40. None
  41. None
  42. None
  43. SOLUTION  Minimum effort / high impact  System only

    fetches new data after lifetime expired  Limited requests to API  Lot´s cheaper  Bonus: Faster  Answer: 30 minutes should be fine
  44. CACHING FRAMEWORK  The caching framework is really easy to

    use.  If you have a lot of requests fetching the same data, you can fetch them once, prepare them and save them for later.  Keep in mind that cache CAN have a lifetime.  If you do not set a lifetime you need to take care of invalidation
  45. SHIPPING FORMS TO THE UNKNOWN

  46. Form Template Flash Message Template Error Message Template No validation

    error at the property EXT:BLOG 9.1
  47. EVERY CHANGE TO THESE TEMPLATES WILL BREAK SOMEONE'S INSTANCE

  48. REQUIREMENTS  Needs to validate input  Needs to show

    validation errors on property  Needs to persist data  Needs to be translatable  Needs to be dynamically created  Needs to add features through configuration  Needs to send notifications  Needs to be extendable in the future  Needs to work in every frontend environment
  49. Extbase EXT:form Validate Input Validation Error on Property Persist Data

    Dynamically Created Translateable Notifications Yes custom optional Yes Hard custom Yes Yes optional Yes Easy custom FEATURE COMPARISON
  50. Extbase EXT:form Extendable API Frontend Independent Custom Templates Result Hard

    No Yes 2 Easy Yes No 7 FEATURE COMPARISON
  51. Local Closed Disqus

  52. Local

  53. FormFactory & FormFinisher

  54. None
  55. None
  56. None
  57. None
  58. None
  59. None
  60. None
  61. None
  62. 316 ADDITIONS 276 DELETIONS [!!!][TASK] USE TYPO3 FORM FRAMEWORK FOR

    COMMENT FORM 407A2AF699961F3C2726204F4A6C49E22E162A07
  63. QUESTIONS? OLIVER HADER & BENJAMIN KOTT @ohader & @benjaminkott info@typo3.com

  64. THANK YOU