Project

General

Profile

Actions

Bug #99949

closed

Repository initializeObject is never called

Added by Miladin Bojic over 1 year ago. Updated about 1 year ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Extbase
Target version:
-
Start date:
2023-02-14
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
11
PHP Version:
7.4
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

I have this code in my repository class

<?php

namespace Vendor\ExtensionName\Domain\Repository;

use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface;
use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings;
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
use TYPO3\CMS\Extbase\Persistence\Repository;

/**
 * Class ProductRepository
 */
class ProductRepository extends Repository
{
    public function initializeObject()
    {
        $querySettings = GeneralUtility::makeInstance(Typo3QuerySettings::class);
        $querySettings->setLanguageOverlayMode(false);
        $querySettings->setRespectStoragePage(false);
        $this->setDefaultQuerySettings($querySettings);
    }
...

in the controller I have

/**
     * Inject the product repository
     *
     * @param ProductRepository $productRepository
     */
    public function injectProductRepository(ProductRepository $productRepository)
    {
        $this->productRepository = $productRepository;
    }

I also could notice, that this works if Dependency Injection is defined in Services.yml. But, I think, this should work also without using Services.yml

So, I would say - this is a bug or the docu https://docs.typo3.org/m/typo3/reference-coreapi/11.5/en-us/ExtensionArchitecture/Extbase/Reference/Domain/Repository.html is not acurate.

Actions #1

Updated by Miladin Bojic over 1 year ago

  • Subject changed from Repository initializeObject is never calld to Repository initializeObject is never called
Actions #2

Updated by Torben Hansen over 1 year ago

  • Status changed from New to Needs Feedback

I do not think this is a bug, since TYPO3 extensions require a services.yaml in order to get DI working properly. See https://docs.typo3.org/m/typo3/reference-coreapi/11.5/en-us/ApiOverview/DependencyInjection/Index.html#configure-dependency-injection-in-extensions

Actions #3

Updated by Miladin Bojic over 1 year ago

However, it does not work with method injection inject*(), only with constructor injection __construct() if I define arguments in Services.yaml
Maybe, I miss some configuration for it to work?

Actions #4

Updated by Stefan Froemken about 1 year ago

  • Status changed from Needs Feedback to Closed

Hello Miladin,

thank you for providing that issue to us.
I had a look into the documentation you posted here and I have requested a patch to the documentation team:
https://github.com/TYPO3-Documentation/TYPO3CMS-Reference-CoreApi/pull/3180

I added a note to create a Service.yaml and, that you have to flush the cache in maintenance module of TYPO3.

I will close the ticket now. If you feel this is the wrong decision, let me know, and I will re-open it.

Stefan

Actions

Also available in: Atom PDF