-1

Hy, I'm trying to call my action with allways a fixed Uid (configured by TS) so I could put a plugin on my page to register for a specific Event. And don't have to go over a Event List click the Event click register.

I tried the following which did not work out:

public function newAction(
    \XYZ\xyz\Domain\Model\Registration $newRegistration = NULL, 
    \XYZ\xyz\Domain\Model\Event $event = 'DD8B2164290B40DA240D843095A29904'
)

The next didn't one work either!

public function newAction(
    \XYZ\xyz\Domain\Model\Registration $newRegistration = NULL, 
    \XYZ\xyz\Domain\Model\Event $event = Null
) {
    $myinstance = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
        'XYZ\\xyz\\Domain\\Model\\Event'
    );
    $event = $myinstance->findByUid('DD8B2164290B40DA240D843095A29904');

    .......
}

So I was woundering is there a way to give my fixed Uid to the action?

Oliver Hader
  • 4,093
  • 1
  • 25
  • 47
im_gm
  • 3
  • 4
  • In TYPO3 tables the UID is an integer value. Where did you get this kind of string? This can't be the UID. – Thomas Löffler Mar 23 '18 at 17:04
  • Well the events aren't inside Typo3 it's from an source outside. But I checked the Uid on the Detail Page and its inside the URL as well. http://example.com/xyz.html?tx_xyz_event%5Bevent%5D=DD8B2164290B40DA240D843095A29904&tx_xyz_event%5Baction%5D=new&tx_xyz_event%5Bcontroller%5D=Registration – im_gm Mar 23 '18 at 17:11
  • Then you need to overwrite the `findByUid()` function because Extbase checks if the UID is an integer. – Thomas Löffler Mar 23 '18 at 17:18
  • Please do not override the `findByUid` method since it has a dedicated meaning already. Instead, implement a new method e.g. `findByIdentifier(string $identifier)` in the custom `EventRepository` – Oliver Hader Mar 26 '18 at 12:53

1 Answers1

1

In TYPO3 calling Extbase actions is done in the routing and dispatching components - to pass anything from the outside that is different from a numeric uid value a custom property TypeConverter would have to be implemented that transforms a particular string pattern into a value domain object of type Event.

However, there's a simpler approach by using configuration:

1) Provide configuration in TypoScript

Extbase uses a strong naming convention based on the extension name and optionally the plugin name. Thus, either tx_myextension or tx_myextension_someplugin can be used - latter is more specific for for according somePlugin. Besides that settings are automatically forwarded and provided in an Extbase controller context - accessible by $this->settings.

plugin.tx_xyz {
  settings {
    newActionEventIdentifier = DD8B2164290B40DA240D843095A29904
  }
}

2) Retrieve data via repository

\XYZ\xyz\Domain\Repository\EventRepository

Use a dedicated EventRepository::findByIdentifier(string) method to retrieve the data. The property names are just assumptions since there are no explicit mentions how exactly the event data is persisted and whether it is persisted in a relational DBMS at all.

<?php
namespace XYZ\xyz\Domain\Repository;
class EventRepository
{
    public function findByIdentifier($identifier)
    {
        $query = $this->createQuery();
        $query->matching(
            $query->equals('event_id', $identifier)
        );
        return $query->execute();
    }
}

3) Putting all together in the according controller

The $event property was removed from the action since that entity is pre-defined and cannot be submitted from the outside (and to support the string to Event entity transformation a custom TypeConverter would be required as mentioned earlier).

public function newAction(
    \XYZ\xyz\Domain\Model\Registration $newRegistration = null
) {
    $event = $this->eventRepository->findByIdentifier(
        $this->settings['newActionEventIdentifier']
    );
    if ($event === null) {
        throw new \RuntimeException('No event found', 1522070079);
    }
    // the regular controller tasks
    $this->view->assign(...);
}
Oliver Hader
  • 4,093
  • 1
  • 25
  • 47
  • Thank you. I'll try that. But I guess I'll haveing a hard time figuring out how to get the Data in my repository as the plugin allready gets the right Data if I'm comming List View/Deatil View/Registration. – im_gm Mar 27 '18 at 14:23
  • (quote from one of your comments to the initial question) `Well the events aren't inside Typo3 it's from an source outside. But I checked the Uid on the Detail Page and its inside the URL as well.` Okay, where is the data coming from then, if it's not managed within TYPO3? – Oliver Hader Mar 28 '18 at 09:01