nextbox/neos-urlshortener

NextBox Neos url shortener

1.1.0 2023-04-12 08:01 UTC

This package is auto-updated.

Last update: 2024-05-12 10:21:12 UTC


README

This package provides an url shortening for Neos.

Configuration

Default

Add the following mixin to your document NodeType: NextBox.Neos.UrlShortener:Identifier

Create a new Routes.yaml with the following content:

# Configuration/Routes.yaml

-
  name: 'Redirect for default'
  uriPattern: 'short/{shortIdentifier}' # replace `short` with your preferences
  defaults:
    '@package': 'NextBox.Neos.UrlShortener'
    '@controller': 'Redirect'
    '@action': 'redirectToPage'
    'shortType': 'default' # if you are using the default Mixin then do not change this line
  appendExceedingArguments: false
  httpMethods: ['GET']

Extensibility

If you want to have different path names for url shortening than you can create your own configuration.

  1. Create a Mixin or use an existing NodeType:
# Configuration/NodeTypes.UrlIdentifier.yaml

'Foo.Bar:ProductIdentifier': # change with your name
  abstract: true
  superTypes:
    'NextBox.Neos.UrlShortener:BaseIdentifier': true
  properties:
    productId: # you can change the property name individually
      type: string
      ui:
        label: 'URL Short Identifier'
        reloadIfChanged: true
        inspector:
          group: 'document'
  1. Create the setting
# Configuration/Settings.yaml

NextBox:
  Neos:
    UrlShortener:
      shortTypes:
        'product': # change the name of the type
          nodeType: 'Foo.Bar:ProductIdentifier' # change the NodeType name to the new created Mixin or to the existing NodeType
          property: 'productId' # the property name of the identification - this field must be globally unique for the used Mixin
          rootNodePath: '/sites/siteOne' # optional, the base path for the Flow Query to search for the nodes 
  1. Create a route:
# Configuration/Routes.yaml

-
  name: 'Redirect for product'
  uriPattern: 'product/{shortIdentifier}' # do not change `shortIdentifier`, just change the path for your preferences
  defaults:
    '@package': 'NextBox.Neos.UrlShortener'
    '@controller': 'Redirect'
    '@action': 'redirectToPage'
    'shortType': 'product' # change this to the name of the type from the settings
  appendExceedingArguments: false
  httpMethods: ['GET']