TYPO3 extbase, the php based views do not work when migrating from 9 to 10 version - typo3

I have developed a custom TYPO3 extbase extension that was perfectly worked on 8 and 9 version of TYPO3.
Recently I upgraded my installation to TYPO3 10 version but the php based views of my TYPO3 extbase extension do not work anymore.
The error that is displayed is:
Sorry, the requested view was not found.
The technical reason is: No template was found. View could not be resolved for action "getIcal" in class "Luc\Lucevents2\Controller\EventController"
I have read the instructions in the page
https://docs.typo3.org/m/typo3/book-extbasefluid/10.4/en-us/8-Fluid/9-using-php-based-views.html, but there is nothing different from what I have already done in my extension.
So, I am very confused because there is no explanation why the code stopped to work, the above link doesn't include any instructions about deprecated code or possible changes after migration!!
Could you give me any help?
Thank you very much!
George

I hit this problem today. The documentation for "php based views" seems to be outdated.Below is a description of my setup and the solution for TYPO3 10
What I had:
My situation was that I had a Controller with a showAction() action method.
In typoscript, I had setup a new format through the type parameter. Something like
rss = PAGE
rss {
typeNum = 58978
10 =< tt_content.list.20.skevents_eventfeeds
}
For this type (parameter type=58978) I had setup a class named View\EventFeeds\ShowRss with a render() method.
TYPO3 automatically resolved this class based on the type (rss) and the action name (show). This does not work any more.
What solves this issue:
in order for TYPO3 to find the correct class with the render method, it is sufficient to set the defaultViewObjectName variable of the Controller to the correct class name for the specific action. This can be done in the controller with the following new method
public function initializeShowAction()
{
$this->defaultViewObjectName = \Skar\Skevents\View\EventFeeds\ShowRss::class;
}
So now, before calling the showAction method, defaultViewObjectName is set to my ShowRss class which produces the output.
Please note that my ShowRss class extends \TYPO3\CMS\Extbase\Mvc\View\AbstractView . According to https://docs.typo3.org/m/typo3/book-extbasefluid/master/en-us/8-Fluid/9-using-php-based-views.html this is deprecated in TYPO3 11 and will have to change for TYPO3 12

the static template is already included and all the other operations of the extension are working very well except the php based views. The ext_localconf.php looks as follows: <?php
defined('TYPO3_MODE') || die('Access denied.');
$boot = function () {
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'Luc.Lucevents2',
'Luceventsdisplay',
[
'Event' => 'list, show, delete, edit, monthview, test, ajax, deleteConfirm, showRss, getIcal, addForm, add, editForm, importeventtoforum',
'Channel' => 'list, show',
'Tag' => 'filter, show'
],
// non-cacheable actions
[
'Event' => 'list, show, delete, edit, monthview, test, ajax, deleteConfirm, showRss, getIcal, addForm, add, editForm, importeventtoforum',
'Channel' => 'list, show',
'Tag' => 'filter, show'
]
);
};
$boot();
unset($boot);
The action is registered in EventController.php and looks as follows:
/**
* action geticalaction
*
* #param \Luc\Lucevents2\Domain\Model\Event $event
* #return void
*/
public function getIcalAction(\Luc\Lucevents2\Domain\Model\Event $event = NULL)
{
$base_url = $this->request->getBaseUri();
$channel=$this->settings['channel_for_simple_users'];
if($this->request->hasArgument('duration'))
{
if ($this->request->getArgument('duration')=='6month') {
$duration=$this->request->getArgument('duration');
}
else
{
$duration='month';
}
$events = $this->eventRepository->get_events_for_rss_and_ical($duration,$channel);
$eventsarray= array();
foreach ($events as $obj){
$this->uriBuilder->setCreateAbsoluteUri(true);
$uri = $this->controllerContext->getUriBuilder()
->setUseCacheHash(false)
->uriFor('show', array("event" => $obj->getUid()));
$eventsarray[] = array($obj->getTitle(), $obj->getDescription(), $obj->getStartdatetime(),$obj->getEnddatetime(), $obj->getBuildingid(), $obj->getRoomid(), $obj->getPlace(), $obj->getCrdate(), $uri, $obj->getUid());
}
$this->view->assign('events', $eventsarray);
$this->view->assign('baseurl', $base_url);
}
else
{
$this->uriBuilder->setCreateAbsoluteUri(true);
$uri = $this->controllerContext->getUriBuilder()
->setUseCacheHash(false)
->uriFor('show', array("event" => $event->getUid()));
$this->view->assign('event', $event);
$this->view->assign('baseurl', $base_url);
$this->view->assign('uri', $uri);
}
}
Thank you very much!

Related

Laravel From Request Validaton doesn't show errors

My Laravel Framework is 5.4.19
I have followed the tutorial:
http://www.easylaravelbook.com/blog/2015/08/17/creating-and-validating-a-laravel-5-form-the-definitive-guide/
and created form request file tours2_create_tableRequest.php:
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class tours2_create_tableRequest extends FormRequest
{
public function authorize()
{
return true;
}
public function rules()
{
return [
'doc_fullnumber' => 'unique:tourists'
];
}
}
(it tests if "doc_fullnumber" from request has no duplicates in 'tourists" model)
I have added this code to the form blade.php file:
#if($errors->count() > 0 )
<div>
#foreach ($errors->all() as $error)
{{ $error }}
#endforeach
</div>
#endif
it seems to me that validation works fine (it redirects the user back to create form page when "doc_fullnumber" is not unique), but it doesn't pass $errors variable.
I've browsed Stackoverflow and found several topics with the same problem. They suggest to wrap all my routes (in web.php) in:
Route::group(['middleware' => ['web']], function () {
});
I've done it, but it doesn't help...
here is the form page, actually (temporary): http://f832ee57.ngrok.io/tours_2/create
(the "doc_fullnumber" field is the last one. You can add "2001" there to check validation).
my project on git: https://github.com/Sergey1983/first
Appreciate any help!
To make the unique rule work, you need to have `'doc_fullnumber' field in DB or you need to specify a custom name field:
'doc_fullnumber' => 'unique:tourists,custom_fullnumber_field'

Passing arguments to a different controller or alternatives

Inside my extbase extension I have an appointment model and users can write feedback to how the appointment was.
So I created a feedback model with different fields.
Now what should I implement for when the user clicks on the "Create Feedback" button?
So far I got this, but it's not working:
<f:link.action action="edit" controller="Feedback" arguments="{appointment:appointment}">
I get the the error:
Argument 1 passed to
...Controller\FeedbackController::newAction() must be an instance of
...\Model\Appointment, none given
FeedbackController:
/**
* action new
* #param ...\Domain\Model\Appointment $appointment
* #return void
*/
public function newAction(...\Domain\Model\Appointment $appointment) {
$this->view->assign('appointment', $appointment);
}
Why do I get this error? (the appointment object was definitely there, I debugged it)
I figure it must've something to do with the switch from AppointmentController to FeedbackController.
What's the best way to implement this?
You need the pluginName parameter in your link generation if you use different plugins.
<f:link.action action="edit" controller="Feedback" pluginName="your_plugin" arguments="{appointment:appointment}">
When generating a link TYPO3 prepends the "namespace" of the argument to the link like this: tx_myplugin[action]=new. Make sure, that the pluginName is the same one you defined in ext_localconf.php. In this case the pluginName would be your_plugin.
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'Vendor.' . $_EXTKEY,
'your_plugin',
array(
'Feedback' => 'new',
),
// non-cacheable actions
array(
'Feedback' => '',
)
);
Check the plugin-controller-action array in your ext_localconf.php and post it. Maybe there is something wrong.
If you get this error :
Argument 1 passed to ...Controller\FeedbackController::newAction()
must be an instance of ...\Model\Appointment, none given
it's because you give the controler a NULL object and taht's not allowed with your controller.
To avoid this error, you could allow NULL object in your controller :
/**
* action new
* #param ...\Domain\Model\Appointment $appointment
* #return void
*/
public function newAction(...\Domain\Model\Appointment $appointment=NULL) {
$this->view->assign('appointment', $appointment);
}
this is weird because in your link, you call an action 'edit' and you have an error in 'newAction' controller instead of 'editAction' controller, you should have the 'edit' action allowed for your plugin (cachable or not) :
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'Vendor.' . $_EXTKEY,
'your_plugin',
array(
'Feedback' => 'edit',
),
// non-cacheable actions
array(
'Feedback' => 'edit',
)
);
and as Natalia wrote add the plugin name if the action you want to call belongs to another plugin.
<f:link.action action="edit" controller="Feedback" pluginName="your_plugin" arguments="{appointment:appointment}">
Florian

Zend Framework 1 add single custom rule for routing

I am having problem with adding custom routing into my application. Zend Framework 1:
I have already working application with default Zend routing. I have a lot of controllers and for some of them I want to use friendly urls, for example:
domain.com/cities/edit/id/3
to
domain.com/cities/edit/abu-dhabi
There are some controllers to switch into that url (in that format).
I tried to configure it by ini file:
resources.router.routes.slugurl.route = /:controller/:action/:slug
And also by Bootstrap method:
protected function _initSlugRouter()
{
$this->bootstrap('FrontController');
$router = $this->frontController->getRouter();
$route = new Zend_Controller_Router_Route('/:controller/:action/:slug/',
array(
'controller' => 'slug',
'action' => 'forward',
'slug' => ':slug'
)
);
$router->addRoute('slug',$route);
}
The main problem - with ini configuration - request goes directly to controller city (not slug). Second one (bootstrap) - also executes the city controller, but the default routing not working as it was, I am not able to execute:
domain.com/cities/ but domain.com/cities/index/ works. The error without action defined:
Action "forward" does not exist and was not trapped in __call()
I can monitor the "slug" in controllers/move check into some library, but I would like to do it only with routing - that way looks much better for me.. Please, how to solve that issue?
edit with summary of solution
Thank you Max P. for interesting. I solved it at last - in last 2 minutes:) I had wrong rules at application.ini with routing. Right now it is defined that:
resources.router.routes.slugurl.route = /:controller/:action/:slug
resources.router.routes.slugurl.defaults.controller = :controller
resources.router.routes.slugurl.defaults.action = :action
resources.router.routes.slugurl.defaults.slug = :slug
The controller is defined like that:
class CitiesController extends Crm_Abstract
The Crm_Abstract has code:
<?php
class Crm_Abstract extends Zend_Controller_Action {
public function __construct(\Zend_Controller_Request_Abstract $request, \Zend_Controller_Response_Abstract $response, array $invokeArgs = array()) {
$params = $request->getParams();
if (!empty($params['slug'])) {
$modelSlug = Crm_Helper_Slug::getInstance();
$parameters = $modelSlug->redirectRequest($request);
if ($parameters !== false) {
foreach ($parameters as $key => $value) {
$request->setParam($key, $value);
}
}
}
parent::__construct($request, $response, $invokeArgs);
}
public function __call($methodName, $args) {
parent::__call($methodName, $args);
}
}
The slug helper get parameters for slug at defined controller. The url to access the slug is defined/calculated in place of $this->url - to $this->slug and there rest of code is done in slug helper. I am not sure if my solution is 100% sure, because that is my first time with routing.
The major thing is that - I just needed to change Zend_Controller_Action to Crm_Abstract which extends the Zend_Controller_Action. Single line - no additional custom code in each controller.
I created two route rules:
resources.router.routes.slugurl.type = "Zend_Controller_Router_Route"
resources.router.routes.slugurl.route = /:controller/:action/:slug/
resources.router.routes.slugurl.defaults.module = "default"
resources.router.routes.slugurl.defaults.controller = :controller
resources.router.routes.slugurl.defaults.action = :action
resources.router.routes.slugurl.defaults.slug = :slug
resources.router.routes.plain1.route = "/:controller/:action/"
resources.router.routes.plain1.defaults.module = "default"
resources.router.routes.plain1.defaults.controller = "index"
resources.router.routes.plain1.defaults.action = "index"
And for now that works fine. Bad thing - I don't understand routing (htaccess rules), but the time spent on that problem and solve it is better than modify all controllers...

TYPO3-6.2 Extbase custom content type -> invalid value

I made an extbase Extension for custom content elements. Since this is my first extension I started with a simple "hello_world_ce". This are my files:
ext_tables.php
<?php
$TCA['tt_content']['types']['hello_world_ce']['showitem'] = '--palette--;LLL:EXT:hello_world/Resources/Private/Language/locallang_mod.xlf:content_element.hello_world.general;general, --palette--;LLL:EXT:hello_world/Resources/Private/Language/locallang_mod.xlf:content_element.hello_world.header;header';
ext_localconf.php
<?php
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig('<INCLUDE_TYPOSCRIPT: source="FILE:EXT:'.$_EXTKEY.'/Configuration/TypoScript/ModWizards.ts">');
ModWizards.ts
mod.wizards {
newContentElement {
wizardItems {
hello_world {
header = LLL:EXT:hello_world/Resources/Private/Language/locallang_mod.xlf:content_tab_header
elements {
hello_world_ce {
icon = gfx/c_wiz/regular_header.gif
title = LLL:EXT:hello_world/Resources/Private/Language/locallang_mod.xlf:content_element.hello_world
description = LLL:EXT:hello_world/Resources/Private/Language/locallang_mod.xlf:content_element.hello_world.description
tt_content_defValues {
CType = hello_world_ce
}
}
}
}
show = *
}
}
}
In the TYPO3 Backend I see my content element and can add it to a page but the dropdown menu for the content type says INVALID VALUE ("hello_world_ce")
What am I missing?
EDIT: I found the missing part. I needed to add my content type to the CType array
ext_tables.php
$backupCTypeItems = $GLOBALS['TCA']['tt_content']['columns']['CType']['config']['items'];
$GLOBALS['TCA']['tt_content']['columns']['CType']['config']['items'] = array(
array(
'LLL:EXT:'.$_EXTKEY.'/Resources/Private/Language/locallang_mod.xlf:content_tab_header',
'--div--'
),
array(
'LLL:EXT:'.$_EXTKEY.'/Resources/Private/Language/locallang_mod.xlf:content_element.hello_world',
'hello_world_ce',
'i/tt_content_header.gif'
)
);
foreach($backupCTypeItems as $key => $value){
$GLOBALS['TCA']['tt_content']['columns']['CType']['config']['items'][] = $value;
}
The question was edited, but I think there is a better way to achieve the solution.
Only to be clear about the problem:
The content element hello_world_ce was not added to the "types" dropdown by adding a new content element.
The hint in the question is correct it was not defined for the CType field.
But instead of manipulating the array you could use a core function:
// Adds the content element to the "Type" dropdown
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPlugin(
array(
'LLL:EXT:your_extension_key/Resources/Private/Language/locallang_mod.xlf:content_element.hello_world',
'hello_world_ce',
'i/tt_content_header.gif'
),
'CType',
'your_extension_key'
);
Here is a very good example of how to add your own content element in the version TYPO3 7.6.
Note: This function is accessible in TYPO3 6.2 as well.

Full dynamic router in Zend Framework

By default you have the following URL-syntax in ZF: /module/controller/action. What i want, is to build an menu-system where i can use any URL I want.
Lets say I make an menu-item called 'news'. When i call http://www.site.com/news i want to have the folowing loaded:
module: news
controller: frontpage
action: display
These config-values must be configured in the database-record for the menu-item.
How can I do this in zend? I spend a lot of time searching for it, but I still can't figure out how to. Does anybody?
I'd suggest using a front controller plugin to scan your database for all the entries, create routing rules based on those entries and add them to the router (see this).
Of course caching strategy is recommended so that you don't do a lot of processing on every request.
You can create a plugin and in routeStartup define something that intercept your request and route /module/controller/action to /action, but for this all your action names must be unique :
class My_CustomRouterPlugin extends Zend_Controller_Plugin_Abstract
{
public function routeStartup(Zend_Controller_Request_Abstract $request)
{
$fc = Zend_Controller_Front::getInstance();
$action =$fc->getRequest()->getActionName();
$router = $fc->getRouter();
$model= new myModel();
$myPage = $model->getPageByAction($action);
$route = new Zend_Controller_Router_Route('/action', array(
'module' => $myPage->getModule();
'controller' => $myPage->getController();
'action' => $action;
));
$router->addRoute($action, $route);
return $router;
}
}
In myModel define a method can get you an object(or an array) that contains module, controller names (from you DB ).
and register this plugin in your bootstrap:
$front->registerPlugin(new My_CustomRouterPlugin());