Skip to content

Nice RealUrl with mm_forum 2

Fabian Auer edited this page Aug 22, 2014 · 5 revisions

We implemented mm_forum with great looking urls like this:

Forums:

domain.de/forum

Topics:

domain.de/forum/topic

Profil:

domain.de/profil/username

New Topic:

domain.de/newTopic/forum

New Conversation:

domain.de/conversations/newconversation

TYPOSCRIPT

Basic trick is to include plugin via typoscript and switch the controller/action with a Typoscript condition like this:

lib.forummessages = USER
lib.forummessages {
    userFunc = tx_extbase_core_bootstrap->run
    extensionName = MmForum
    pluginName = Pi1
    controller = User
    action = dashboard
    switchableControllerActions.User.1 = dashboard
    settings =< plugin.tx_mmforum.settings
    settings.display.dashboard = messages
    persistence =< plugin.tx_mmforum.persistence
    view =< plugin.tx_mmforum.view
}

lib.forumraw = USER
lib.forumraw {
    userFunc = tx_extbase_core_bootstrap->run
    extensionName = MmForum
    pluginName = Pi1
    settings =< plugin.tx_mmforum.settings
    persistence =< plugin.tx_mmforum.persistence
    view =< plugin.tx_mmforum.view
}

lib.forumsingle < lib.forumraw
lib.forumsingle {
    controller = Topic
    action = show
    switchableControllerActions.Topic.1 = show
}

lib.forumcat < lib.forumraw
lib.forumcat {
    pluginName = Pi1
    controller = Forum
    action = show
    switchableControllerActions.Forum.1 = show
}

lib.newTopic < lib.forumraw
lib.newTopic {
    pluginName = Pi1
    controller = Topic
    action = new
    switchableControllerActions.Topic.1 = new
}

lib.forumquote < lib.forumraw
lib.forumquote{
    pluginName = Pi1
    controller = Post
    action = new
    switchableControllerActions.Post.1 = new
}

lib.forumedit < lib.forumraw
lib.forumedit {
    pluginName = Pi1
    controller = Post
    action = edit
    switchableControllerActions.Post.1 = edit
}

`

Conditions

Then the switch via Conditions:

    [globalVar = GP:tx_mmforum_pi1|forum > 0]
    lib.forumraw < lib.forumcat
    config.tx_extbase.mvc.callDefaultActionIfActionCantBeResolved = 0
    [global]
    [globalVar = GP:tx_mmforum_pi1|topic > 0]
    lib.forumraw < lib.forumsingle
    [global]
    [globalVar = GP:tx_mmforum_pi1|quote > 0]
    lib.forumraw < lib.forumquote
    [end]
    [globalVar = GP:tx_mmforum_pi1|post > 0] && [globalVar = GP:tx_mmforum_pi1|forum > 0] && [globalVar = GP:tx_mmforum_pi1|topic > 0] 
    lib.forumraw < lib.forumedit
    [end]

For new Topic we added a special page with pid 252:

    [globalVar = TSFE:id = 252]
    lib.forumraw < lib.newTopic
    config.tx_extbase.mvc.callDefaultActionIfActionCantBeResolved = 0
    [global]

Realurl Config

And finally the realurl magic:

...
'fixedPostVars' => array(
...
'forumThema' => array(
            array(
                'GETvar' => 'tx_mmforum_pi1[forum]',
                'lookUpTable' => array(
                    'table' => 'tx_mmforum_domain_model_forum_forum',
                    'id_field' => 'uid',
                    'alias_field' => 'title',
                    'addWhereClause' => ' AND NOT deleted',
                    'useUniqueCache' => 1,
                    'useUniqueCache_conf' => array(
                        'strtolower' => 1,
                        'spaceCharacter' => '-'
                    ),
                    'enable404forInvalidAlias' => 1,
                ),
            ),
            array(
                'GETvar' => 'tx_mmforum_pi1[topic]',
                'lookUpTable' => array(
                    'table' => 'tx_mmforum_domain_model_forum_topic',
                    'id_field' => 'uid',
                    'alias_field' => 'subject',
                    'addWhereClause' => ' AND NOT deleted',
                    'useUniqueCache' => 1,
                    'useUniqueCache_conf' => array(
                        'strtolower' => 1,
                        'spaceCharacter' => '-'
                    ),
                    'enable404forInvalidAlias' => 0,
                ),
            ),
            array(
                'GETvar' => 'tx_mmforum_pi1[subscribe]',
                'valueMap' => array(
                    'abonnieren' => '1',
                ),
                'noMatch' => 'bypass',
            ),
             array(
                'GETvar' => 'tx_mmforum_pi1[unsubscribe]',
                'valueMap' => array(
                    'nicht-mehr-abonnieren' => '1',
                ),
                'noMatch' => 'bypass',
            ),
            array(
                'GETvar' => 'tx_mmforum_pi1[post]',
            ),
            array(
                'GETvar' => 'tx_mmforum_pi1[quote]',
            ),
            array(
                'GETvar' => 'tx_mmforum_pi1[controller]',
                'noMatch' => 'bypass',
            ),
            array(
                'GETvar' => 'tx_mmforum_pi1[action]',
                'noMatch' => 'bypass',
            ),
        ),
        'user' => array(
            array(
                'GETvar' => 'tx_mmforum_pi1[user]',
                'lookUpTable' => array(
                    'table' => 'fe_users',
                    'id_field' => 'uid',
                    'alias_field' => 'username',
                    'addWhereClause' => ' AND NOT deleted',
                    'useUniqueCache' => 1,
                    'useUniqueCache_conf' => array(
                        'strtolower' => 1,
                        'spaceCharacter' => '-'
                    )
                )
            ),
            array(
                'GETvar' => 'tx_mmforum_pi1[controller]',
                'noMatch' => 'bypass',
            ),
            array(
                'GETvar' => 'tx_mmforum_pi1[action]',
                'noMatch' => 'bypass',
            ),
        ),
        'nachrichtenzentrale' => array(
            array(
                'GETvar' => 'tx_mmforum_pi1[action]',
                'valueMap' => array(
                    'nachrichtschreiben' => 'newMessage',
                ),
                'noMatch' => 'bypass',
            ),
            array(
                'GETvar' => 'tx_mmforum_pi1[recipient]',
                'lookUpTable' => array(
                    'table' => 'fe_users',
                    'id_field' => 'uid',
                    'alias_field' => 'username',
                    'addWhereClause' => ' AND NOT deleted',
                    'useUniqueCache' => 1,
                    'useUniqueCache_conf' => array(
                        'strtolower' => 1,
                        'spaceCharacter' => '-'
                    )
                )
            ),
            array(
                'GETvar' => 'tx_mmforum_pi1[controller]',
                'noMatch' => 'bypass',
            ),
        ),
        'createTopic' => array(
            array(
                'GETvar' => 'tx_mmforum_pi1[forum]',
                'lookUpTable' => array(
                    'table' => 'tx_mmforum_domain_model_forum_forum',
                    'id_field' => 'uid',
                    'alias_field' => 'title',
                    'addWhereClause' => ' AND NOT deleted',
                    'useUniqueCache' => 1,
                    'useUniqueCache_conf' => array(
                        'strtolower' => 1,
                        'spaceCharacter' => '-'
                    ),
                ),
            #'noMatch' => 'bypass',
            ),
            array(
                'GETvar' => 'tx_mmforum_pi1[controller]',
                'noMatch' => 'bypass',
            ),
            array(
                'GETvar' => 'tx_mmforum_pi1[action]',
                'noMatch' => 'bypass',
            ),
        ),
        '29' => 'forumThema', #29 = Forum PID
        '33' => 'user', #33 = Profil PID
        '252' => 'createTopic', #252 = New Topic PID
        '30' => 'nachrichtenzentrale' #30 = Messages PID
...
),
...

Include Libs

Last step: Include the lib.forummessages for the Message Page, and the lib.forumraw to the other PIDs. (For example via gridelements, typoscript or fluid.)

Nice looking paginator links

There is a way to include the paginator links in this fashion:

Forums

forum/2

Topics

forum/topics/2

First we add :

        array(
            'GETvar' => 'tx_mmforum_pi1[@widget_0][currentPage]',
        ),

after the tx_mmforum_pi1[unsubscribe] part. Now we already have great urls for articles. But in the forum list view we get something like: forum//1 Doubleshlashes are not a big issue but still not good looking. problem with the doubleslash is that realurl can not find a article in the forum view. To solve this we tricked the paginator widget by including it a second time in the forum/list partial. The first time we set the widget to not show anything:

<f:widget.paginate objects="{posts}" as="paginatedPosts" configuration="'insertBelow':'0','insertAbove':'0'">

The second widget is our real paginator and than has the url param tx_mmforum_pi1[@widget_1][currentPage], now we can configure that one seperately. We added this one between forum and topic:

        array(
            'GETvar' => 'tx_mmforum_pi1[@widget_1][currentPage]',
            'valueMap' => array(
                  '1' => '1'
                     ....
                   '99' => '99'
            ),
            'noMatch' => 'bypass',                
        ),

Unfortunately it only works for fixed maximum of pages per forum, but you can increase the number anytime so it should ok.