I try to add additional fields to the extension seminars (5.7.0) in TYPO3 10.4.34 but they don't show up in the single view in frontend.
What I did so far:
I created the extension my_seminar with the new field precondition. The field is shown in the backend.
I extended the seminars event model in the file my_seminar/Classes/Domain/Model/Event.php:
namespace MyVendor\MySeminar\Domain\Model;
class Event extends \OliverKlee\Seminars\Model\Event
{
/**
* precondition
*
* @var string
*/
protected $precondition = '';
/**
* Returns the precondition
*
* @return string $precondition
*/
public function getPrecondition()
{
return $this->precondition;
}
/**
* Sets the precondition
*
* @param string $precondition
* @return void
*/
public function setPrecondition($precondition)
{
$this->precondition = $precondition;
}
}
namespace MyVendor\MySeminar\Hooks;
use \OliverKlee\Seminars\Hooks\Interfaces\SeminarSingleView;
class EventSingleView implements SeminarSingleView
{
public function modifySingleView(\OliverKlee\Seminars\FrontEnd\DefaultController $controller): void
{
// deprecated
// $data = $controller->pi_getRecord('tx_seminars_seminars', $controller->piVars['showUid']);
$precondition = $controller->getPrecondition();
$controller->setMarker('PRECONDITION', $precondition);
}
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['seminars'][\OliverKlee\Seminars\Hooks\Interfaces\SeminarSingleView::class][] = \MyVendor\MySeminar\Hooks\EventSingleView::class; $GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][\OliverKlee\Seminars\Model\Event::class] = \MyVendor\MySeminar\Domain\Model\Event::class;
How can I get the value of $precondition and show it in the marker PRECONDITION?
I finally found out how to extend seminars with custom fields. This way it works:
my_seminar/ext_localconf.php
use MyVendor\MySeminar\Domain\Model\Event;
if (!defined('TYPO3_MODE')) die ('Access denied.');
$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][\OliverKlee\Seminars\OldModel\LegacyEvent::class] = [
'className' => MyVendor\MySeminar\Domain\Model\Event::class
];
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['seminars'][\OliverKlee\Seminars\Hooks\Interfaces\SeminarSingleView::class] = [
'className' => MyVendor\MySeminar\Hooks\EventSingleView::class
];
my_seminar/Configuration/Extbase/Persistence/Classes.php
return [
\MyVendor\MySeminar\Domain\Model\Event::class => [
'tableName' => 'tx_seminars_seminars',
],
];
my_seminar/Classes/Domain/Model/Event.php
namespace MyVendor\MySeminar\Domain\Model;
class Event extends \OliverKlee\Seminars\OldModel\LegacyEvent
{
/**
* precondition
*
* @var string
*/
protected $precondition = '';
/**
* Returns the precondition
*
* @return string $precondition
*/
public function getPrecondition()
{
return $this->getTopicString('precondition');
}
/**
* Sets the precondition
*
* @param string $precondition
* @return void
*/
public function setPrecondition($precondition)
{
$this->precondition = $precondition;
}
}
my_seminar/Classes/Hooks/Event.php
namespace MyVendor\MySeminar\Hooks;
use OliverKlee\Seminars\Hooks\Interfaces\SeminarSingleView;
use OliverKlee\Seminars\Frontend\DefaultController;
class EventSingleView implements SeminarSingleView
{
/**
* Modifies the seminar details view.
*
* This function will be called for all types of seminars (single events, topics, and dates).
*
* @param DefaultController $controller the calling controller
*/
public function modifySingleView(\OliverKlee\Seminars\FrontEnd\DefaultController $controller): void
{
$seminar = $controller->getSeminar();
$precondition = $seminar->getPrecondition();
if ($precondition != '') {
$controller->setMarker('precondition', $precondition);
} else {
$controller->hideSubparts('precondition', 'field_wrapper');
}
}
}
Furthermore you have to adjust TCA/Overrides/tx_seminars_seminars.php and ext_tables.sql.