0
votes

I made an extbase extension with a class Appointment with a property expertises und another one subExpertises of the same type.
This is how they look like in the Appointment class (subExpertises is the same):

    /**
     * expertises
     *
     * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<...\Domain\Model\Expertise>
     */
    protected $expertises = NULL;

    /**
     * Adds an expertise
     *
     * @param ...\Domain\Model\Expertise $expertise
     * @return void
     */
    public function addExpertise(...\Domain\Model\Expertise $expertise) {
        $this->expertises->attach($expertise);
    }

I get an error when executing this code in my controller after editing the appointment in a fluid form:

/**
 *
 * @param \Domain\Model\Appointment $appointment
 * @return void
 */
public function bookAction(\Domain\Model\Appointment $appointment) {

    //empty all expertises of appointment - then fill them with the selected from lawyer
    $appointment->setExpertises(new \TYPO3\CMS\Extbase\Persistence\ObjectStorage());
    $appointment->setSubExpertises(new \TYPO3\CMS\Extbase\Persistence\ObjectStorage());

    //add all checked expertises of lawyer to appointment
    foreach ($appointment->getLawyer()->getExpertises() as $expertise) {
        if ($expertise->getChecked()) {
            $appointment->addExpertise($expertise);
        }
        foreach ($expertise->getSubExpertises() as $subExpertise) {
            if ($subExpertise->getChecked()) {
                $appointment->addSubExpertise($subExpertise);
            }
        }
    }
    $this->appointmentRepository->update($appointment);
}

This is the error:

Fatal error: Call to undefined method \Domain\Model\Expertise::getPosition() in /var/www/typo3_src/typo3_src-6.2.25/typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php on line 453

Now it seems that TYPO3 thinks Expertise is of type ObjectStorage because it tries to call getPosition() but I have no clue why it does that and what I should change in order to successfully save my Appointment object with the new Expertises.

I tried debugging the appointment object, but I couldn't find the problem - it seems okay to me, it just shows that expertises und subExpertises have been modified.

1
... you have different spellings of expertise, singluar in the property, plural in the method.j4k3
I checked my text again, but it was fine - the props are objectStorage so plural expertises and subExpertises the class name is Expertise and addExpertise only adds one, so it should be singularCold_Class

1 Answers

2
votes

Getter methods in Extbase aren't magic, you have to explicitly define them.

If you're dealing with a n:n-relation, you also need to initialize the Property as ObjectStorage in your model and configure it in the TCA.

/**
 * Initialize all ObjectStorage properties.
 *
 * @return void
 */
protected function initStorageObjects() {
    $this->yourProperty = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
}