Aswathy S
Aswathy S

Reputation: 731

switchable controller action is not working TYPO3 7.6

Hi I have an extension in TYPO3 7.6. I have two actions list and show. In my flexform there is a switchable controller action.list action is working. But show action not working. Please check my code.

Flexform

                   <switchableControllerActions>
                        <TCEforms>
                            <label>Display Type</label>
                            <onChange>reload</onChange>
                            <config>
                                <type>select</type>
                                <items type="array">
                                    <numIndex index="1" type="array">
                                        <numIndex index="0">List</numIndex>
                                        <numIndex index="1">News->list</numIndex>
                                    </numIndex>
                                    <numIndex index="2" type="array">
                                        <numIndex index="0">Detail</numIndex>
                                        <numIndex index="1">News->show</numIndex>
                                    </numIndex>
                                </items>
                                <minitems>0</minitems>
                                <maxitems>1</maxitems>
                                <size>1</size>
                            </config>
                        </TCEforms>
                    </switchableControllerActions> 

list view

  <f:if condition="{news}">
    <ul>
        <f:for each="{news}" as="item">
            <li>
                <f:link.action action="show" controller="News" arguments="{news:'{item}'}" noCacheHash="false" pageUid="{settings.detailPid}" >
                    {item.title}
                </f:link.action>
            </li>
        </f:for>
    </ul>
</f:if>

I selected list from configuration in list page and select detail from detail page. List is working perfectly but detail is not working.

Upvotes: 0

Views: 1450

Answers (2)

Philipp Wrann
Philipp Wrann

Reputation: 1849

Not gtting any error message.only a blank page is shown

You might want to change that first

  1. check your error_reporting on php level (display_errors)
  2. set your Environment to Development (you can select the preset in the install tool)
  3. Look Debug options up in the install tool (all configuration)

Keep in mind, that you dont want to make those adjustments in Production Environment.

Then you should be able to see the error.

I selected list from configuration in list page and select detail from detail page. List is working perfectly but detail is not working.

Did you add the show action to the plugin configuration? Look that up in your extensions ext_localconf.php

Look for this call: ExtensionUtility::configurePlugin

Your Controller->action combinations have to exist in the first array parameter you pass. That might look like:

\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
    'Vendor.ext_key',
    'News',
    array(
        'News' => 'list,show'
    )
);

If you pass a 4th parameter with Controller->action combinations (like the other), you can define actions, that should not be cached. You would use such to configure form actions or filterable result-lists.

note: Allways use the full namespace in ext_localconf.php and other bootstrap files, if you make use of "use" statements you might have another fatal error, typo3 concatenates all those bootstrap files.

Also - you could have misunderstood the switchableControllerActions pattern. If you want one plugin (the ce) to show both actions, the option has to be

<switchableControllerActions>
    <TCEforms>
        ...
        <config>
            <type>select</type>
            <items type="array">
                ...
                <numIndex index="3" type="array">
                    <numIndex index="0">List with Details</numIndex>
                    <numIndex index="1">News->list;News->show</numIndex>
                </numIndex>
            </items>
            ...
        </config>
    </TCEforms>
</switchableControllerActions> 

The selected option will be saved in the xml datastructure and is used as configuration, so if only one action is available for this instance then you will receive an error.

If you use different content elements to show the list and detail view you have to select the correct switchableControllerAction option in both content elements.

Upvotes: 1

Ashish Patel
Ashish Patel

Reputation: 1031

Try to add arguments like this:

arguments="{news: item.uid}"

in showAction you can get argument like this:

$newsId = $this->request->getArgument('news');
$news = $this->newsRepository->findByUid($newsId); 
$this->view->assign('news', $news);

It will work perfectly as you required.

Upvotes: 1

Related Questions