[TYPO3-mvc] pi_getPidList in extbase

sunixzs sunixzs at gmail.com
Wed Dec 11 22:05:10 CET 2013


Hi at all,

in an plugins flexform I tried to use the tt_content.pages-field from the plugin in a type-select part. This does not work, because the value in field pages is something like "pages_666|Plugin" and not only the page-UID (testet with ###REC_FIELD_pages###).

To test another way I tried to build an items-array with the itemsProcFunc Methodic and I found the solution from Patrick. But this solution didn't work for me, because there is no cObj which i can use in itemsProcFunc. Maybe there is a way to set the cObj - this would be the best solution.

Now I use a dirty way, but this is still working. (but not for field tt_content.recursive):

File "flexform_pi1.xml":
-----------------
<config>
<type>select</type
<itemsProcFunc>VENDOR\MyExt\Domain\Repository\MyModelRepository->findForTCASelect</itemsProcFunc> 
[...]
</config>
-----------------

File "VENDOR\MyExt\Domain\Repository\MyModelRepository"
-----------------
namespace VENDOR\MyExt\Domain\Repository;
class MyModelRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {
	/**
	 * @param \array $params
	 * @param \array $conf
	 * @return \array
	 */
	public function findForTCASelect($params, $conf) {
		// get the storage-pages
		// In $params['row']['pages'] and $params['row']['recursive'] are the storagePids of the content-element defined, where the list should be shown - use them.
		// pages is something like "pages_666|Plugin,pages_667|Plugin"
		

		// The following does not work, because there must be a cObj for the treelist
		#$pi = $this->objectManager->create('TYPO3\CMS\Frontend\Plugin\AbstractPlugin');
		#$pi->cObj = $this->configurationManager->getContentObject();
		#$pidList = $pi->pi_getPidList($params['row']['pages'], $params['row']['recursive']);
		

		// This is the alternative way - but without recursion.
		$fieldPagesEx = \TYPO3\CMS\Extbase\Utility\ArrayUtility::trimExplode( ",", $params['row']['pages'], true );
		$pidList = array ();
		foreach ( $fieldPagesEx as $section ) {
			$sectionEx = \TYPO3\CMS\Extbase\Utility\ArrayUtility::trimExplode( "|", $section, true );
			$parts = \TYPO3\CMS\Extbase\Utility\ArrayUtility::trimExplode( "_", $sectionEx[0], true );
			if (is_numeric( $parts[1] )) {
				$pidList[] = $parts[1];
			}
		}
		
		// build the query
		$query = $this->createQuery();
		$query->getQuerySettings()->setRespectStoragePage( false );
		$query->matching( $query->in( "pid", $pidList ) );
		$query->setOrderings( array (
				"title" => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING 
		) );
		$myModels = $query->execute();
		
		// build the items-array
		foreach ( $myModels as $myModel ) {
			$params['items'][] = array (
					$myModel->getTitle(),
					$myModel->getUid() 
			);
		}
		
		return $params;
	}
}
-----------------

Maybe this is helpful for someone.

Have a nice evening.

sun



More information about the TYPO3-project-typo3v4mvc mailing list