0

I want to create some kind of sitemap in extbase/fluid (based on the pagetree). I have loaded the pages table into a model:

config.tx_extbase.persistence.classes.Tx_MyExt_Domain_Model_Page.mapping.tableName = pages

I have created a controller and repository, but get stuck on the part wich can load the subpages as relation into my model.

For example:

$page = $this->pageRepository->findByPid($rootPid);

Returns my rootpage. But how can I extend my model that I can use $page->getSubpages() or $page->getNestedPages()?

Do I have to create some kind of query inside my model? Or do I have to resolve this with existing functions (like the object storage) and how?

I tried a lot of things but can simply figure out how this should work.

Arek van Schaijk
  • 1,432
  • 11
  • 34

2 Answers2

1

you have to overwrite your findByPid repository-method and add

public function findByPid($pid) {
    $querySettings = $this->objectManager->create('Tx_Extbase_Persistence_Typo3QuerySettings');
    $querySettings->setRespectStoragePage(FALSE);
    $this->setDefaultQuerySettings($querySettings);
    $query = $this->createQuery();
    $query->matching($query->equals('pid', $pid));
    $pages = $query->execute();
    return $pages;
}

to get all pages. Than you can write your own getSubpages-method like

function getSubpages($currentPid) {
    $subpages = $this->pagesRepository->findByPid($currentPid);
    if (count($subpages) > 0) {
        $i = 0;
        foreach($subpages as $subpage) {
            $subpageUid = $subpage->getUid();
            $subpageArray[$i]['page'] = $subpage;
            $subpageArray[$i]['subpages'] = $this->getSubpages($subpageUid);
            $i++;
        }
    } else {
        $subpageArray = Array();
    }
    return $subpageArray;
}

i didn't test this method, but it looks like this to get alle subpages.

konsolenfreddy
  • 9,551
  • 1
  • 25
  • 36
freshp
  • 525
  • 5
  • 20
0

i wonder that i could“t find a typo3 method that return the complete Page-Tree :( So i write a little function (you can use in an extbase extension), for sure not the best or fastes way, but easy to extend or customize ;)

first you need an instance of the PageRepository

$this->t3pageRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');

this->t3pageRepository->init();

make the init, to set some basic confs, like "WHERE deletet = 0 AND hidden = 0..."

then with this function you get an array with the page data and subpages in. I implement yust up to three levels:

 function getPageTree($pid,$deep=2){
    $fields = '*';
    $sortField = 'sorting';
    $pages = $this->t3pageRepository->getMenu($pid,$fields,$sortField);
    if($deep>=1){
        foreach($pages as &$page) {
            $subPages1 = $this->t3pageRepository->getMenu($page['uid'],$fields,$sortField);
            if(count($subPages1)>0){
                if($deep>=2){
                    foreach($subPages1 as &$subPage1){
                        $subPages2 = $this->t3pageRepository->getMenu($subPage1['uid'],$fields,$sortField);
                        if(count($subPages2>0)){
                            $subPage1['subpages'] = $subPages2;
                        }
                    }
                }
                $page['subpages'] = $subPages1;
            }
        }
    }
    return $pages;
}
trayan.dev
  • 87
  • 4