0

I've been trying to extend the Location and Organizer models from tx_eventnews, but without any luck. The custom fields are not showing up in the frontend.

Everything in the backend works and is getting saved to the DB without any problems. It's mainly the frontend. I could solve this by using the signalslot "detailaction" from the NewsController and getting the saved values from my own repository, but this seems unnecessary if overriding/extending should work according to the Documentation "Add custom fields"

If I debug the Location (newsItem.location) and/or Organizer (newsItem.organizer) in the frontend, the default fields are rendered, but not the custom added fields. What am I missing?

Note: I have cleared the cache in the install tool multiple times throughout debugging.

ext_localconf:

$GLOBALS['TYPO3_CONF_VARS']['EXT']['eventnews']['classes']['Domain/Model/News'][] = 'my_website_extension';
$GLOBALS['TYPO3_CONF_VARS']['EXT']['eventnews']['classes']['Domain/Model/Location'][] = 'my_website_extension';
$GLOBALS['TYPO3_CONF_VARS']['EXT']['eventnews']['classes']['Domain/Model/Organizer'][] = 'my_website_extension';

I tried extending eventnews' News model because it did not work without. Classes\Domain\Model\News

/**
 * News
 */
class News extends \GeorgRinger\Eventnews\Domain\Model\News
{

    /**
     * organizer
     *
     * @var \ThisIs\MyWebsiteExtension\Domain\Model\Organizer
     */
    protected $organizer = null;

    /**
     * location
     *
     * @var \ThisIs\MyWebsiteExtension\Domain\Model\Location
     */
    protected $location = null;

    /**
     * Returns the organizer
     *
     * @return \ThisIs\MyWebsiteExtension\Domain\Model\Organizer $organizer
     */
    public function getOrganizer(): ?\ThisIs\MyWebsiteExtension\Domain\Model\Organizer
    {
        return $this->organizer;
    }

    /**
     * Sets the organizer
     *
     * @param \ThisIs\MyWebsiteExtension\Domain\Model\Organizer $organizer
     * @return void
     */
    public function setOrganizer($organizer)
    {
        $this->organizer = $organizer;
    }

    /**
     * Returns the location
     *
     * @return \ThisIs\MyWebsiteExtension\Domain\Model\Location $location
     */
    public function getLocation(): ?\ThisIs\MyWebsiteExtension\Domain\Model\Location
    {
        return $this->location;
    }

    /**
     * Sets the location
     *
     * @param \ThisIs\MyWebsiteExtension\Domain\Model\Location $location
     * @return void
     */
    public function setLocation($location)
    {
        $this->location = $location;
    }
}

Classes\Domain\Model\Location:

/**
 * Location
 */
class Location extends \GeorgRinger\Eventnews\Domain\Model\Location
{

    /**
     * @var string
     */
    protected $telephone;

    /**
     * @var string
     */
    protected $isOnline;

    /**
     * @return string
     */
    public function getTelephone(): string
    {
        return $this->telephone;
    }

    /**
     * @param string $telephone
     */
    public function setTelephone(string $telephone): void
    {
        $this->telephone = $telephone;
    }

    /**
     * @return string
     */
    public function getIsOnline(): string
    {
        return $this->isOnline;
    }

    /**
     * @param string $isOnline
     */
    public function setIsOnline(string $isOnline): void
    {
        $this->isOnline = $isOnline;
    }
}

Configuration\Extbase\Persistence\Classes:

return [
    \ThisIs\MyWebsiteExtension\Domain\Model\News::class => [
        'tableName' => 'tx_eventnews_domain_model_news',
    ],
    \ThisIs\MyWebsiteExtension\Domain\Model\Location::class => [
        'tableName' => 'tx_eventnews_domain_model_location',
    ],
    \ThisIs\MyWebsiteExtension\Domain\Model\Organizer::class => [
        'tableName' => 'tx_eventnews_domain_model_organizer',
    ],
];

Not sure if I need the propertymapping beside the tablenames. I've tried both.

ext_tables:

#
# Extend table structure for table 'tx_eventnews_domain_model_location'
#
CREATE TABLE tx_eventnews_domain_model_location (
    telephone varchar(255) DEFAULT '' NOT NULL,
    is_online tinyint(4) DEFAULT '0' NOT NULL,
);

#
# Extend table structure for table 'tx_eventnews_domain_model_organizer'
#
CREATE TABLE tx_eventnews_domain_model_organizer (
    email varchar(255) DEFAULT '' NOT NULL,
    telephone varchar(255) DEFAULT '' NOT NULL,
    website varchar(255) DEFAULT '' NOT NULL,
);

TCA isn't the problem, so I left that out.

UPDATE: When extending tx_news itself it works like a charm, but eventnews (which is extended from tx_news already) is not working.

Kees Sonnema
  • 5,759
  • 6
  • 51
  • 106
  • Did you clear the system cache? Either via the dropdown in the backend or in the module Admin Tools. – Siva May 23 '23 at 10:22
  • @Siva I forgot to mention, but I've been on this for quite a while and yes I did clear the cache in the install tool multiple times :) – Kees Sonnema May 23 '23 at 10:36
  • EXT:eventsnews extends EXT:news and its models/classes. I would try the registration in `ext_localconf.php` for `$GLOBALS['TYPO3_CONF_VARS']['EXT']['news']`. – Julian Hofmann May 23 '23 at 13:26
  • @JulianHofmann the Location and Organizer models are specific to eventnews, they're not part of tx_news, so no. This should be correct. – Kees Sonnema May 23 '23 at 14:00
  • Good point ;-) - and maybe the hint, we needed. The registration in *ext_localconf.php* above is part of EXT:news' ProxyClassGenerator, not a part of TYPO3 in general. When handling these registrations, the namespace is checked - and limited to the domain and controllers of EXT:news (https://github.com/georgringer/news/blob/main/Classes/Utility/ClassLoader.php#L132). – Julian Hofmann May 23 '23 at 18:08
  • @JulianHofmann the ext_localconf.php above is the one from my extension, not from EXT:news. So how would I "force" eventnews to load, instead of news? It seems to be loaded, because no errors are thrown when calling them like this, if I would change it to ['news'] instead of ['eventnews'] it would throw an error telling me the Location and Organizer models do not exist (because they don't). So this the above ClassLoader actually cause a 'silent' false return for eventnews? – Kees Sonnema May 23 '23 at 20:12
  • Not showing any error is not "It seems to be loaded". The code is just not processed or the class loading is ignored due to the wrong namespace. Not every error results in an error message. xclassing good be a way for you: https://www.derhansen.de/2019/03/extending-extbase-domain-models-and.html – Julian Hofmann May 24 '23 at 06:36
  • @JulianHofmann xclass is definitely an option, but for me it does not make sense to have a strict classloader like this, but that is Georg's choice. – Kees Sonnema May 24 '23 at 06:50
  • I'm sure PRs for EXT:eventnews with a classloading feature are welcome ;-) – Julian Hofmann May 24 '23 at 06:57
  • @JulianHofmann I think we can use a workaround for this case. I will look into creating a PR if we need it again. We will not use xclassing in our case. Thanks for the help. – Kees Sonnema May 24 '23 at 08:03
  • @JulianHofmann what if we wanted to use XClassing. I've tried it, but nothing happens. I'm not even sure if this would work with XClass. Could you elaborate? – Kees Sonnema Jun 27 '23 at 11:52

1 Answers1

0

Installing the extension EXT:extender (example) works like a charm. My problem was that I used a website extension that didn't include a composer.json, so no extension-key was set that way. Extender expects to find a composer.json file with an extension_key.

Kees Sonnema
  • 5,759
  • 6
  • 51
  • 106