Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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.

Benjamin Kott

August 02, 2019
Tweet

More Decks by Benjamin Kott

Other Decks in Programming

Transcript

  1. EXTENSION
    DEVELOPMENT
    WITH EXTBASE
    TYPO3
    [email protected]
    @typo3
    August 2nd, 2019
    Karlsruhe, Germany

    View full-size slide

  2. OLIVER
    HADER
     Research & Development
     Security Team Lead
     Darth Hader
    @ohader
    [email protected]

    View full-size slide

  3. BENJAMIN
    KOTT
     Developer Advocate
     Consultant
     UI/UX Lead
    @benjaminkott
    [email protected]

    View full-size slide

  4. 1. Introduction
    2. Persistence Variations
    3. Software Architecture
    4. Caching
    5. Bonus+

    View full-size slide

  5. EXTBASE IN A
    NUTSHELL

    View full-size slide

  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, …

    View full-size slide

  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)

    View full-size slide

  8. This "protection" just concerns the visual output

    View full-size slide

  9.  Kickstarted with Extension Builder
     Good for getting started
     Must be adjusted

    View full-size slide

  10. CAR RENTAL EXAMPLE
    # vin: string
    # color: string
    # brand: Brand
    # charge: Charge
    # tires: Tire[]
    # rentals: Rental[]
    # maintenances: Maintenance[]
    # images: FileReference[]
    <>
    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
    <>
    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

    View full-size slide

  11.  LazyLoading 1:n (ObjectStorage)
     LazyLoading 1:1 (LazyLoadingProxy)
     and current drawbacks in implementation

    View full-size slide

  12.  Using Doctrine DBAL QueryBuilder
     Using custom query statements
     In order to be more flexible
     Submitted data must be escaped/casted (security)

    View full-size slide

  13.  Omitting ORM layer, retrieve raw-data (array)
     Pros & Cons of working with arrays or objects

    View full-size slide

  14. SOFTWARE
    ARCHITECTURE

    View full-size slide

  15. CAR RENTAL EXAMPLE
    # vin: string
    # color: string
    # brand: Brand
    # charge: Charge
    # tires: Tire[]
    # rentals: Rental[]
    # maintenances: Maintenance[]
    # images: FileReference[]
    <>
    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
    <>
    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

    View full-size slide

  16. CAR RENTAL EXAMPLE

    View full-size slide

  17. 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

    View full-size slide

  18. 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

    View full-size slide

  19. CAR RENTAL EXAMPLE – BOUNDED CONTEXTS
    Extbase
    Maintenance
    Common
    Rental
    # vin: string
    # color: string
    # brand: Brand
    # tires: Tire[]
    # maintenances: Maintenance[]
    <>
    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
    <>
    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[]
    <>
    Rental\Car
    + get…()
    + set…()
    1
    1
    1
    1
    n
    1 1
    1

    View full-size slide

  20. CAR RENTAL EXAMPLE – BOUNDED CONTEXTS

    View full-size slide

  21. 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)

    View full-size slide

  22. CAR RENTAL EXAMPLE - INHERITANCE
    Extbase
    Maintenance
    Common
    Rental
    # vin: string
    # color: string
    # brand: Brand
    # tires: Tire[]
    # maintenances: Maintenance[]
    <>
    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[]
    <>
    Rental\Car
    + get…()
    + set…()
    1
    1
    1
    1
    n
    1 1
    1
    FrontendUserService
    + retrieveUserById(int $id)

    View full-size slide

  23. 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

    View full-size slide

  24. 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?

    View full-size slide

  25. CACHING
    FRAMEWORK

    View full-size slide

  26. 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

    View full-size slide

  27. 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

    View full-size slide

  28. SHIPPING FORMS
    TO THE UNKNOWN

    View full-size slide

  29. Form
    Template
    Flash Message
    Template
    Error Message
    Template
    No validation error
    at the property
    EXT:BLOG 9.1

    View full-size slide

  30. EVERY CHANGE TO THESE
    TEMPLATES WILL BREAK
    SOMEONE'S INSTANCE

    View full-size slide

  31. 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

    View full-size slide

  32. 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

    View full-size slide

  33. Extbase EXT:form
    Extendable API
    Frontend Independent
    Custom Templates
    Result
    Hard
    No
    Yes
    2
    Easy
    Yes
    No
    7
    FEATURE COMPARISON

    View full-size slide

  34. Local
    Closed
    Disqus

    View full-size slide

  35. FormFactory &
    FormFinisher

    View full-size slide

  36. 316 ADDITIONS
    276 DELETIONS
    [!!!][TASK] USE TYPO3 FORM
    FRAMEWORK FOR COMMENT FORM
    407A2AF699961F3C2726204F4A6C49E22E162A07

    View full-size slide

  37. QUESTIONS?
    OLIVER HADER &
    BENJAMIN KOTT
    @ohader & @benjaminkott
    [email protected]

    View full-size slide