Giter Club home page Giter Club logo

typo3-dynamic-routing-pages's Introduction

Dynamic Routing Pages

Instead of hardcoding the limitToPages configuration for your route enhancers this package can automatically detect the necessary pages for you and generate the configuration on the fly.

Problem

Imagine the following typical routing configuration for the news plugin.

routeEnhancers:
  NewsPages:
    type: Extbase
    # add every page-ID that contains a News Plugin
    limitToPages:
      - 23
      - 42
      - 123
      - 242
    extension: News
    plugin: Pi1
    routes:
      - { routePath: '/{myNewsTitle}', _controller: 'News::detail', _arguments: {'myNewsTitle': 'news'} }
      - { routePath: '/{myPagination}', _controller: 'News::list', _arguments: {'myPagination': '@widget_0/currentPage'} }
      - { routePath: '/{year}/{month}', _controller: 'News::list', _arguments: {'year' : 'overwriteDemand/year', 'month' : 'overwriteDemand/month'} }
    defaultController: 'News::list'
    # ...

Hardcoding the page ids for your plugin routes has the major drawback that you have to adapt the configuration as soon as someone creates a new page with a plugin (which might happen in a CMS). With the route enhancers configuration not available in the Site module this means you have to ship an updated configuration file every time an editor creates a plugin page.

Solution

routeEnhancers:
  NewsPages:
    type: Extbase
    dynamicPages:
        withPlugin: news_pi1
    extension: News
    plugin: Pi1
    routes:
      - { routePath: '/{myNewsTitle}', _controller: 'News::detail', _arguments: {'myNewsTitle': 'news'} }
      - { routePath: '/{myPagination}', _controller: 'News::list', _arguments: {'myPagination': '@widget_0/currentPage'} }
      - { routePath: '/{year}/{month}', _controller: 'News::list', _arguments: {'year' : 'overwriteDemand/year', 'month' : 'overwriteDemand/month'} }
    defaultController: 'News::list'
    # ...

Notice the dynamicPages configuration. This package will populate the limitToPages with matching pages.

Reference

dynamicPages has three possible properties.

withPlugin

Can be a string or an array of tt_content.list_type values. Will find all pages that contain at least one of the given plugins.

containsModule

Can be a string or an array of pages.module values. Will find all pages that have "Contains Plugin" set to one of the given values.

withSwitchableControllerAction

Can be a string or an array of switchableControllerActions values. Will find all pages that contain plugins with the given action configured.

withCType

Can be a string or an array of withCType values. Will find all pages that contain content element with given CType.

withDoktypes

Can be an integer or an array of withDoktypes values. Will find all pages with given doktype.

typo3-dynamic-routing-pages's People

Contributors

amirarends avatar ftrojahn avatar kitzberger avatar kszymukowicz avatar saitho avatar smichaelsen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

typo3-dynamic-routing-pages's Issues

Patch release?

Wow, guys, switching from a v10 compatible version to v11 should not get released as patch level version, please. Please respect Semantic Versioning. So it should be a version 2.0.0.

Filter generated list by their sites?

Currently the generated limitPerPages properties are containing PIDs independent of the site they're belonging to. So the same PID shows up on all sites route enhancer configurations for (let's say) the news singlepage route enhancer.

Is that a problem?
Should that list be filtered?

a new option for CType

hi, tnx for the interesting idea.

While using your extension I got some more use case. I needed to set limitToPages set on CType. Do you think you can integrate this case into you extension? I can prepare a PR then.

    protected static function findDynamicPages(array $dynamicPagesConfiguration): array
    {
        $pageUids = [];
        if (isset($dynamicPagesConfiguration['withPlugin'])) {
            $withPlugins = is_array($dynamicPagesConfiguration['withPlugin']) ? $dynamicPagesConfiguration['withPlugin'] : [$dynamicPagesConfiguration['withPlugin']];
            array_push($pageUids, ...self::findPagesWithPlugins($withPlugins));
        }
        if (isset($dynamicPagesConfiguration['containsModule'])) {
            $containsModules = is_array($dynamicPagesConfiguration['containsModule']) ? $dynamicPagesConfiguration['containsModule'] : [$dynamicPagesConfiguration['containsModule']];
            array_push($pageUids, ...self::findPagesContainingModules($containsModules));
        }
        if (isset($dynamicPagesConfiguration['withSwitchableControllerAction'])) {
            $withSwitchableControllerActions = is_array($dynamicPagesConfiguration['withSwitchableControllerAction']) ? $dynamicPagesConfiguration['withSwitchableControllerAction'] : [$dynamicPagesConfiguration['withSwitchableControllerAction']];
            array_push($pageUids, ...self::findPagesWithSwitchableControllerActions($withSwitchableControllerActions));
        }
        if (isset($dynamicPagesConfiguration['withCType'])) {
            $withCType = is_array($dynamicPagesConfiguration['withCType']) ? $dynamicPagesConfiguration['withCType'] : [$dynamicPagesConfiguration['withCType']];
            array_push($pageUids, ...self::findPagesWithCType($withCType));
        }
        return array_unique($pageUids);
    }

    protected static function findPagesWithCType(array $withCType): array
    {
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content');
        $contentElementRecords = $queryBuilder
            ->select('pid')
            ->from('tt_content')
            ->where(
                $queryBuilder->expr()->in('CType', $queryBuilder->createNamedParameter($withCType, Connection::PARAM_STR_ARRAY))
            )
            ->execute()
            ->fetchAll();
        return array_column($contentElementRecords, 'pid');
    }

withPlugin should check on CType too

First off: nice extension ;-)

When playing around with it, I've noticed it's gathering too many pids though. E.g. of pages that had a news plugin in the past but the CE got changed to another CType.

So when checking for withPlugin it should probably check on CType='list' too.

Consider using a cache

In an environment with n sites having the same routing configuration there are n - 1 superflous sql queries.

Fix changes introduced by typo3-core-sa-2022-016

see https://typo3.org/security/advisory/typo3-core-sa-2022-016

  [ TYPO3\CMS\Core\Error\Exception ]                                                                                                  
  Warning: Declaration of Smic\DynamicRoutingPages\Xclass\SiteConfiguration::write(string $siteIdentifier, array $configuration): vo  
  id should be compatible with TYPO3\CMS\Core\Configuration\SiteConfiguration::write(string $siteIdentifier, array $configuration, b  
  ool $protectPlaceholders = false): void in /var/www/html/src/public/typo3conf/ext/dynamic_routing_pages/Classes/Xclass/SiteConfigu  
  ration.php line 39                                                                                                                  
                                      

Tag for current Version

Hello,
I want to ask, if it posible to set a tag for the current verison? So If the extension get an update for TYPO3 11 LTS it is still posible to install a version for TYPO3 10.
Thanks and Best Regards
Goldi42

Support lookup by doktype

We're using custom doktypes to provide fixed elements on websites, which may also be plugins.
That's why I suggest adding a "withDoktype" setting as well.

I'll be happy to provide a PR for that. :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.