[TYPO3-dev] Extbase: Create ObjectStorage from a group of pages

Caspar Stuebs caspar at gosign.de
Tue Oct 7 16:31:40 CEST 2014


Hi,

afaik you just have to add the getter/setter/add/remove functions for the
object storage:

getPage() {
  return $this->page;
}
setPage(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $objectStorage) {
  $this->page = $objectStorage;
}
addPage(\Vendor\Extension\Domain\Model\Page $page) {
  $this->page->attach($page);
}
removePage(\Vendor\Extension\Domain\Model\Page $page) {
  $this->page->detach($page);
}

Kind Regards
Caspar

2014-10-07 15:42 GMT+02:00 pcworld <0188801 at googlemail.com>:

> Hi all,
>
> I have a model Foo with a property "pages", so the user can create a
> record of type "Foo" and select pages to use with the record. TYPO3
> stores it in the model's database column "pages" as a comma-separated
> string of page UIDs.
> Foo's TCA:
>
> $GLOBALS['TCA']['tx_masterpages_domain_model_foo'] = array(
>         // snip
>         'columns' => array(
>                 'pages' => array(
>                         'label' => 'Select pages',
>                         'config' => array(
>                                 'type' => 'group',
>                                 'internal_type' => 'db',
>                                 'allowed' => 'pages',
>                                 'show_thumbs' => 1,
>                                 'maxitems' => 999,
>                         ),
>                 )
>         )
> );
>
> I also have a model "Page" that maps to the "pages" table (I took it
> from the pw_teaser extension).
> How can I get TYPO3 to let Foo's property "pages" be an ObjectStorage of
> Page instances (instead of just the comma-separated string)?
>
> Basically what I want in my model is a property of this type:
>         /**
>          * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\
> Vendor\Extension\Domain\Model\Page>
>          */
>         public $pages;
>
> What's the cleanest solution to this (it doesn't look like TYPO3
> automatically handles this, I just get an empty ObjectStorage)?
>
> I could keep $pages as a string, and then invoke a method to explode()
> the string, create Page objects and store them in an array in a
> different property. That doesn't sound very straightforward though.
>
> Thanks!
> _______________________________________________
> TYPO3-dev mailing list
> TYPO3-dev at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-dev
>

-- 
-- 

Gosign media. GmbH | We web ideas.
Langenfelder Damm 67 Gewerbehof | 22525 Hamburg
Telefon 040-609 40 79-0

Handelsregister AG HH HRB 112197 | Geschäftsführung Bert Gogolin
Greenpeace energy: Gosign läuft mit ehrlichem Strom und Gas.
GLS Bank: Gosign wirtschaftet mit Gewissen. 



More information about the TYPO3-dev mailing list