Feature #8736

Implement generic Identity RoutePartHandler

Added by Bastian Waidelich about 5 years ago. Updated almost 4 years ago.

Status:Resolved Start date:
Priority:Should have Due date:
Assigned To:Bastian Waidelich % Done:

100%

Category:MVC - Routing
Target version:TYPO3 Flow Base Distribution - 1.0.0
PHP Version: Complexity:
Has patch:

Description

We should provide a generic RoutePart handler, that allows to match/resolve Identities. This should be configurable through the "options" setting that was implemented with #2825.
Instead of

  uriPattern:    'posts/{post}'
  defaults:
    '@package':    Blog
    '@controller': Post
    '@action':     show
  routeParts:
    post:
      handler: F3\Blog\RoutePartHandlers\PostRoutePartHandler

I could imagine something like
  uriPattern:    'posts/{post}'
  defaults:
    '@package':    Blog
    '@controller': Post
    '@action':     show
  routeParts:
    post:
      handler: IdentityRoutePartHandler
      options:
        model: F3\Blog\Domain\Model\Post
        pattern: '{date}/{title}'

Then you wouldn't need a custom RoutePart handler anymore most cases..

Note1: the namespace of the handler can be omitted when it is in the FLOW3 package
Note2: the line "handler: IdentityRoutePartHandler" could be implicit for domain models
Note3: how to handle the date format here? should we somehow support regular expressions in the pattern?


Related issues

related to TYPO3.Flow - Feature #29972: Configurable Redirects Under Review 2011-09-18
duplicated by TYPO3.Flow - Feature #26688: Magic Object Routes Closed 2011-05-06

Associated revisions

Revision 38232efb
Added by Bastian Waidelich almost 4 years ago

[FEATURE] Add generic Identity RoutePartHandler

This implements improved routing for persisted objects.

When an object type is specified in the routing configuration,
the new "IdentityRoutePart" is used to match/resolve the route
part.

By default the resolved URI representation (path segment) is
built from the identity properties of the domain model. If no
identity properties are defined, the technical identifier (UUID)
is used.

Additionally a custom URI pattern can be defined in the route.
For properties of type DateTime the date format can be specified
prefixed by a colon.

If a path segment already exists, the IdentityRoutePart handler
will append an increasing counter to ensure unique URIs.

Sample Route:
-
uriPattern: 'posts/{post}'
defaults:
'@package': 'TYPO3.Blog'
'@controller': 'Post'
'@action': 'show'
'@format': 'html'
routeParts:
post:
objectType: TYPO3\Blog\Domain\Model\Post

Change-Id: I8fb5d4f4be3649e2f6307f83af2f3bbaa2191b5b
Resolves: #8736

History

#1 Updated by Bastian Waidelich about 5 years ago

  • Due date deleted (2009-03-16)
  • Start date deleted (2009-03-12)
  • % Done changed from 100 to 0
  • Estimated time changed from 2.00 to 4.00

#2 Updated by Bastian Waidelich about 5 years ago

  • Status changed from New to Needs Feedback

One more addition:
According to "Convention over Configuration" the above example could be

  uriPattern:    'posts/{post}'
  defaults:
    '@package':    Blog
    '@controller': Post
    '@action':     show
  routeParts:
    post:
      options:
        pattern: '{date}/{title}'

-> By default FLOW3s IdentityRoutePart would be used for the domain model. And - if not specified - the model would be @package\Domain\Model\ and uppercase RoutePart-getName(). Would that work?
IMO even the routParts configuration could be ommited - then all @identity properties would be used to build the Uri segments..

What do you think?

#3 Updated by Bastian Waidelich about 5 years ago

  • Subject changed from Routing: Implement generic Identity RoutePartHandler to Implement generic Identity RoutePartHandler
  • Category changed from MVC to MVC - Routing

#4 Updated by Karsten Dambekalns almost 5 years ago

I like the concept. As for date formatting, this needs to be configurable. Since the handler could find out about the types of the properties used, it could look for type-specific information in the pattern. E.g. like this:

uriPattern:    'posts/{post}'
defaults:
  '@package':    Blog
  '@controller': Post
  '@action':     show
routeParts:
  post:
    options:
      pattern: '{date format:Y-m-d}/{title}'

Then it could use format as needed.

#5 Updated by Bastian Waidelich almost 5 years ago

Karsten Dambekalns wrote:

As for date formatting, this needs to be configurable.

Yes, but I'm unhappy about yet another syntax

{date format:Y-m-d}

Why hasn't the DateTime object more getters.. Then one could write
pattern: '{date.year}-{date.month}-{date.day}/{title}'

And this is not the only case where this was useful..
Maybe we can use our own DateTime implementation in FLOW3!?

#6 Updated by Karsten Dambekalns almost 5 years ago

Bastian Waidelich wrote:

Yes, but I'm unhappy about yet another syntax
[...]
Why hasn't the DateTime object more getters.. Then one could write

So, in the pattern one could use the object path syntax as in Fluid. Nice idea.

Maybe we can use our own DateTime implementation in FLOW3!?

Yeah, one more reason to have one...

#7 Updated by Bastian Waidelich about 4 years ago

  • Status changed from Needs Feedback to Accepted
  • Target version set to 1.0 beta 1
  • % Done changed from 0 to 30
  • Estimated time deleted (4.00)

Note: One reason that prevented me from implementing this, was the missing "transliteration" feature of the I18n sub package, that would be needed to convert special characters (e.g. "รค" -> "ae").
As transliteration will most probably not make it into FLOW3 1.0, we'll have to find another (temporary) solution anyways.
Maybe we can make use of some built-in Doctrine functionality here (for example the sluggable behavior: http://www.doctrine-project.org/documentation/manual/1_0/en/behaviors:core-behaviors:sluggable -> https://github.com/l3pp4rd/DoctrineExtensions/tree/doctrine2.0.x/lib/Gedmo/Sluggable)

#8 Updated by Karsten Dambekalns about 4 years ago

Bastian Waidelich wrote:

As transliteration will most probably not make it into FLOW3 1.0, we'll have to find another (temporary) solution anyways.

Why not? The basics are all there, even in TYPO3 (v4).

Maybe we can make use of some built-in Doctrine functionality here (for example the sluggable behavior: http://www.doctrine-project.org/documentation/manual/1_0/en/behaviors:core-behaviors:sluggable -> https://github.com/l3pp4rd/DoctrineExtensions/tree/doctrine2.0.x/lib/Gedmo/Sluggable)

Oh, well, looks interesting, why not mix and match the best from our and their code. Either way, having this in I18n by 1.0 should be no problem. Even it's some kind of "workaround", I'd put it there. We should discuss your needs and just do it.

#9 Updated by Sebastian Kurfuerst almost 5 years ago

  • Target version changed from 1.0 beta 1 to 1.0 beta 2

#10 Updated by Robert Lemke almost 4 years ago

  • Target version changed from 1.0 beta 2 to 1.0.0

#11 Updated by Mr. Hudson almost 4 years ago

  • Status changed from Accepted to Under Review

Patch set 1 of change I8fb5d4f4be3649e2f6307f83af2f3bbaa2191b5b has been pushed to the review server.
It is available at http://review.typo3.org/5076

#12 Updated by Bastian Waidelich almost 4 years ago

FYI: The current implementation supports following syntax:

 1-
 2  name: 'Single Post Actions'
 3  uriPattern:    'posts/{post}(/{@action})'
 4  defaults:
 5    '@package':    'TYPO3.Blog'
 6    '@controller': 'Post'
 7    '@action':     'show'
 8    '@format':     'html'
 9  routeParts:
10    post:
11      objectType: TYPO3\Blog\Domain\Model\Post

By default the @identity property/ies of the specified object type are used to create the URI section, or - if they're not specified - the technical identifier (UUID) of the respective object.
Alternatively a custom URI pattern can be specified:

 1-
 2  name: 'Single Post Actions'
 3  uriPattern:    'posts/{post}(/{@action})'
 4  defaults:
 5    '@package':    'TYPO3.Blog'
 6    '@controller': 'Post'
 7    '@action':     'show'
 8    '@format':     'html'
 9  routeParts:
10    post:
11      objectType: TYPO3\Blog\Domain\Model\Post
12      uriPattern: '{date:Y}/{date:m}/{date:d}/{title}'

#13 Updated by Mr. Hudson almost 4 years ago

Patch set 2 of change I8fb5d4f4be3649e2f6307f83af2f3bbaa2191b5b has been pushed to the review server.
It is available at http://review.typo3.org/5076

#14 Updated by Mr. Hudson almost 4 years ago

Patch set 3 of change I8fb5d4f4be3649e2f6307f83af2f3bbaa2191b5b has been pushed to the review server.
It is available at http://review.typo3.org/5076

#15 Updated by Mr. Hudson almost 4 years ago

Patch set 4 of change I8fb5d4f4be3649e2f6307f83af2f3bbaa2191b5b has been pushed to the review server.
It is available at http://review.typo3.org/5076

#16 Updated by Karsten Dambekalns almost 4 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 30 to 100

Also available in: Atom PDF