[TYPO3-mvc] Define a PID per object, not by configuration

Adrien Crivelli adrien.crivelli at gmail.com
Tue Aug 9 21:44:08 CEST 2011


Answering my own question. It's actually pretty easy once we figured out the
injection system in ExtBase:

1. Extends the class with your own and override whatever method you need,
eg:

class Tx_Newsletter_Persistence_BackendPidFriendly extends
Tx_Extbase_Persistence_Backend {
protected function
determineStoragePageIdForNewRecord(Tx_Extbase_DomainObject_DomainObjectInterface
$object = NULL) {
if ($object !== NULL &&
Tx_Extbase_Reflection_ObjectAccess::isPropertyGettable($object, 'pid')) {
$pid = Tx_Extbase_Reflection_ObjectAccess::getProperty($object, 'pid');
if (isset($pid)) {
return (int) $pid;
}
}

return parent::determineStoragePageIdForNewRecord($object);
}
}

2. Configure ExtBase to use it (in Configuration/TypoScript/setup.txt):


config.tx_extbase {

objects {

Tx_Extbase_Persistence_BackendInterface {

className = Tx_Newsletter_Persistence_BackendPidFriendly

}

}

}

That's it. More details available in the repository:
http://forge.typo3.org/projects/extension-newsletter/repository/revisions/50827




On 9 August 2011 09:33, Adrien Crivelli <adrien.crivelli at gmail.com> wrote:

> Oh this is great ! It is exactly what I need.
>
> Unfortunately it's not released yet... Any recommendations on how to
> reproduce this behavior with 4.5 ? Would it be possible to inherit
> Tx_Extbase_Persistence_Backend and use our own instance of it ?
>
> Thanks !
>
>
> On 9 August 2011 00:11, Marc Bastian Heinrichs <typo3 at mbh-web.de> wrote:
>
> > Hey,
> >
> > > Of course I tried things like:
> > > $newNewsletter->setPid(12345);
> > >  $this->newsletterRepository->add($newNewsletter);
> > >
> > > But, as many before me, it wasn't long before I figured out that the
> PID
> > is
> > > always overwritten by the configuration
> > > (via
> > Tx_Extbase_Persistence_Backend::determineStoragePageIdForNewRecord()).
> > >
> > >
> > > So the first question is simple: Why can't we manually set a PID
> without
> > > being overwritten ?
> >
> > This feature was added some days ago in current dev-version and will be
> > released with T3 4.6. Here is the commit
> >
> >
> http://git.typo3.org/TYPO3v4/CoreProjects/MVC/extbase.git?a=commit;h=6edb4c885bac63bff8accfcae5ea2ae496201ed8
> >
> > I think it's already in 4.6-beta1.
> >
> > Best
> > Marc Bastian
> > _______________________________________________
> > TYPO3-project-typo3v4mvc mailing list
> > TYPO3-project-typo3v4mvc at lists.typo3.org
> > http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
> >
> _______________________________________________
> TYPO3-project-typo3v4mvc mailing list
> TYPO3-project-typo3v4mvc at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
>


More information about the TYPO3-project-typo3v4mvc mailing list