Jump to content

ServiceNotFoundError : How retrieve a custom Repository in Module


Recommended Posts

Hi !

I'm trying to create a module to add content on our cms pages. I use hookActionCmsPageFormBuilderModifier to add custom fields to cms pages back office form and hookActionAfterUpdateCmsPageFormHandler/hookActionAfterCreateCmsPageFormHandler to store my custom fields value in my database through a Repository. To save my data I get my repository :

$cmsPageRepository = $this->get('foo.module.extendcmsform.repository.cms_extra_data_repository');

Declared in services.yml :

services:
	_defaults:
		public: true

foo.module.extendcmsform.repository.cms_extra_data_repository:
  class: Foo\Module\ExtendCmsForm\Repository\CmsPageExtraDataRepository
  factory: ['@doctrine.orm.entity_manager', getRepository]
  arguments:
  	- Foo\Module\ExtendCmsForm\Entity\CmsExtraData

Until now everything works fine. Then I'm trying to get my custom data and show it through a widget so I have implemented renderWidget and getWidgetVariables in my Module class that implements WidgetInterface. In the renderWidget I try to retrieve my repository using the same method has before :

$cmsPageRepository = $this->get('foo.module.extendcmsform.repository.cms_extra_data_repository');

But I'm getting a ServiceNotFoundException when I try to reach my cms page. What am I doing wrong ? How can I retrieve then show my custom data in my cms pages ?

 

Thank You !

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...