In my Typo3 plugins I want to give the admin the ability to select some items from a dropdown, the contents of which are stored in a "facilities" database, using the respository "FacilitiesRepository.php".
By default the system uses the UID as the value of each item. Therefore I want to use a custom function to ensure both the label and value of each item in the dropdown uses what I want.
I am using a flexform, and the "itemsProcFunc" tag to call my custom function. The custom function is in a controller called "FacilitiesController.php"
The controller uses inject to reference the respository, like so:
/* @var \MyCompany\MyPlugin\Domain\Repository\FacilitiesRepository
* @inject
*/
protected $facilitiesRepository;
All functions within the controller successfully connect to the repository, so I know that it works.
I am trying to use the findAll() repository function.
My custom function is successfully called from the flexform, however whenever it references the facilitiesRepository it gives me the error: Call to a member function findAll() on null.
I tried replacing findAll with a test() function in the repository, but I still get : Call to a member function test() on null.
Null is always returned.
I have tried to inject the repo via other methods (I believe there are 3 ways) but the outcome is the same.
Here is my custom function:
public function findAllForFlexForm($config){
$categories = $this->facilitiesRepository->findAll(); // <--here is the problem
// create option list
$optionList = array();
foreach($categories as $key=>$item){
$label = $item['id'];
$value = $item['titel_de'];
$optionList[] = array(0 => $label, 1 => $value);
}
// return config
$config['items'] = array_merge($config['items'], $optionList);
return $config;
}
Is there any reason why my facilitiesRepository is not recognised? If I ran this function from the FE it would return correctly.
In the FE your are in your Extbase context which is not the case in a hook in the backend. As extbase bootstrapping is rather expensive I propose you do a query using Doctrine DBAL and fetch the data directly.