Building a TYPO3 extension in Extbase/Fluid
Adding/registering a frontend plugin
In order to add a new frontend plugin to your extension you’ll need to change certain files. Use the standard plugins registered by the Extension Builder as an example. This is a basic example that lets you add a plugin with a list view of all records (list) and a detail view of a single record (show).
Change the following files (file paths are relative to the root of your extension /typo3conf/ext/your_extension/):
Configuration/TCA/Overrides/tt_content.php
Register the plugin
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
'Human Readable Plugin Name'
$_EXTKEY,
'PluginKey',
'Human Readable Plugin Name'
);
);
ext_localconf.php
Configure the plugin, defining the controller methods that will eventually call the views/templates
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
)
'VendorName.' . $_EXTKEY,
'PluginKey',
array(
'YourModelController' => 'list, show' // methods of class YourModelController: listAction() and showAction()
)
);
);
/Classes/Domain/Repository/YourModelRepository.php
Create an empty repository class that extends the Extbase Repository class
<?php
namespace VendorName\YourExtension\Domain\Repository;
namespace VendorName\YourExtension\Domain\Repository;
class YourModelRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
{
}
class YourModelRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
{
}
/Classes/Controller/YourModelController.php
Inject the above created Repository Class and set the controller methods that assign the database records to variables that will be used in the Fluid templates
<?php
}
namespace VendorName\YourExtension\Controller;
class YourModelController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
{
/**
* clientRepository
*
* @var \VendorName\YourExtension\Domain\Repository\YourModelRepository
* @inject
*/
protected $yourModelRepository = NULL;
/**
* action list
*
* @return void
*/
public function listAction()
{
$array_of_records = $this->yourModelRepository->findAll();
$this->view->assign('yourViewVariable', $array_of_records);
}
/**
* action show
*
* @param \VendorName\YourExtension\Domain\Model\YourModel $yourmodel
* @return void
*/
public function showAction(\VendorName\YourExtension\Domain\Model\YourModel $yourmodel)
{
$this->view->assign('yourViewVariable', $yourmodel);
}
}
}
/Resources/Private/Templates/YourModel/List.html
The Fluid template for the list view, using the view variables set in the respective controller method
<f:layout name="Default" ></f:layout>
</f:for>
<f:section name="main">
<f:flashMessages renderMode="div" ></f:flashMessages>
<table>
<tr>
<th><f:translate key="tx_yourext_domain_model_yourcontroller.main_property" ></f:translate></th>
<th><f:translate key="tx_yourext_domain_model_yourcontroller.another_property" ></f:translate></th>
</tr>
<f:for each="{yourViewVariable}" as="item" key="number">
<tr class="tr-{number}">
<td><f:link.action action="show" arguments="{yourViewVariable : item.uid}" title="{item.mainProperty}">{item.mainProperty}</f:link.action></td>
<td>{item.anotherProperty}</td>
</tr>
</f:for>
</table>
</f:section>
</table>
</f:section>
/Resources/Private/Templates/YourModel/Show.html
The Fluid template for the list view, using the view variables set in the respective controller method
<f:layout name="Default" ></f:layout>
<p>{yourViewVariable.anotherProperty}</p>
<f:section name="main">
<f:flashMessages renderMode="div" ></f:flashMessages>
<h2>{yourViewVariable.mainProperty}</h2>
<p>{yourViewVariable.anotherProperty}</p>
</f:section>
</f:section>