0
votes

I don't know if I've set up my extension a little quirky.

I have one model, but two plugins, as I would like to display the same data in different ways.

What thought I'd do: assign pi1 and pi2 two different Fluid templates, where all the display logic is done. But as far as I understood now, there is no such switch, due to "Convention over configuration", I need a separate controller for pi2, right?

Now I have this in ext_tables.php:

\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
    'STUBR.' . $_EXTKEY,
    'Pi1',
    array(
        'Institution' => 'list, show',

    ),
    // non-cacheable actions
    array(
        'Institution' => '',

    )
);

\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
    'STUBR.' . $_EXTKEY,
    'Pi2',
    array(
        'Institution' => 'list, show',

    ),
    // non-cacheable actions
    array(
        'Institution' => '',

    )
);

Do I really have to adapt everything by re-naming "Institution" here, in the Controller(s) and in the template directories?

3

3 Answers

1
votes

To answer the question you asked in your answer ... it is possible to configure the TypoScript of your Extension on a per plugin base. Just add the pluginname with a leading underscore to your TS key like this

plugin.tx_stellen_pi2 {
    settings {
       displaymode = 1
    }
}

Instead of using a if condition you could also set a different TemplateRootPath so another template would be rendered for pi2.

1
votes

Remember that you can set the displayMode in a FlexForm. Every FlexForm property prefixed with settings. will be available in the {settings} array. Just configure the FlexForm in ext_tables.php:

$pluginSignature = str_replace('_','',$_EXTKEY) . '_pi1';
$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist'][$pluginSignature] = 'pi_flexform';
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue($pluginSignature, 'FILE:EXT:' . $_EXTKEY . '/Configuration/FlexForm/flexform_pi1.xml');

Then add the FlexForm XML to the path configured:

<T3DataStructure>
    <meta>
        <langDisable>1</langDisable>
    </meta>
    <sheets>
        <sDEF>
            <ROOT>
                <TCEforms>
                    <sheetTitle>Configuration</sheetTitle>
                </TCEforms>
                <type>array</type>
                <el>
                    <settings.displayMode>
                        <TCEforms>
                            <exclude>0</exclude>
                            <label>Display mode</label>
                            <config>
                                <type>select</type>
                                <items type="array">
                                    <numIndex index="0" type="array">
                                        <numIndex index="0">Neat</numIndex>
                                        <numIndex index="1">1</numIndex>
                                    </numIndex>
                                    <numIndex index="1" type="array">
                                        <numIndex index="0">Clean</numIndex>
                                        <numIndex index="1">2</numIndex>
                                    </numIndex>
                                </items>
                                <minitems>0</minitems>
                                <maxitems>1</maxitems>
                                <size>1</size>
                            </config>
                        </TCEforms>
                    </settings.displayMode>
                </el>
            </ROOT>
        </sDEF>
    </sheets>
</T3DataStructure>

In this example, a select box with two options "neat" and "clean" is added.

You can then use this in your Fluid template (you could also use the SwitchViewHelper instead of the if construct if you have more than two modes):

<f:if condition="{settings.displayMode} == 1">
    <f:then>
        <f:render partial="Neat/List" arguments="{_all}" />
    </f:then>
    <f:else>
        <f:render partial="Clean/List" arguments="{_all}" />
    </f:else
</f:if>

Remember that you can nest partials, so it's no problem to have a partial in a partial in a partial. So just use a partial for each view.

If you want to have it less hackish-looking, you could give the display mode a speaking value:

<numIndex index="0" type="array">
    <numIndex index="0">Neat</numIndex>
    <numIndex index="1">Neat</numIndex>
</numIndex>
<numIndex index="1" type="array">
    <numIndex index="0">Clean</numIndex>
    <numIndex index="1">Clean</numIndex>
</numIndex>

Then you can use this to call the partial like this

<f:render partial="List/{settings.displayMode}" arguments="{_all}" />

and get rid of the if construct that way.

0
votes

I'm doing it this way now. Keep one controller, just fork the template by setting some page TS on the page the plugin is on.

plugin.tx_stellen {
    settings {
       displaymode = 1
    }
}

and then <f:if condition="{settings.displaymode}==1"></f:if>

This is workaroundish, though, as it is valid for the entire page (and I wouldn't even need the three different plugins at all). Isn't it possible to define TypoScript "per Plugin" directly in the extension?