Coder Social home page Coder Social logo

Comments (11)

khepin avatar khepin commented on May 28, 2024

Can you show what you did put in your config here?

from fosmessagebundle.

Chrysweel avatar Chrysweel commented on May 28, 2024

My config.yml I have:

fos_message:
    db_driver:    orm
    thread_class:    myproject\MessageBundle\Entity\Thread
    message_class:    myproject\MessageBundle\Entity\Message

When I write all the config of documentation :

(
message_manager: fos_message.message_manager # See ModelManager\MessageManagerInterface
thread_manager: fos_message.thread_manager # See ModelManager\ThreadManagerInterface
...... )
I get the error.

In my composer.json:

"require" : {
....
 "friendsofsymfony/message-bundle": "dev-master",
}

from fosmessagebundle.

stof avatar stof commented on May 28, 2024

Well, if you want to set explicitly the default value for the message_manager service, you should set fos_message.message_manager.default (which is the default value). You cannot ask the bundle to use fos_message.message_manager as target of the alias as this is the alias.

from fosmessagebundle.

stof avatar stof commented on May 28, 2024

and btw, you don't need to set it explicitly to personalize the form if you rely on the default value

from fosmessagebundle.

khepin avatar khepin commented on May 28, 2024

You can define your own classes as follows:

fos_message:
    db_driver: mongodb
    thread_class: Xxxx\MessageBundle\Document\MessageThread
    message_class: Xxxx\MessageBundle\Document\Message
    new_thread_form:
        type: Xxxx.type.new_thread_form
        handler: Xxxx.message_bundle.form_handler
        model: Xxxx\MessageBundle\FormModel\NewThreadMessage

Where Xxxx.type.new_thread_form references a service that you have defined in your configuration.

from fosmessagebundle.

Chrysweel avatar Chrysweel commented on May 28, 2024

Ok thank you very much @khepin

from fosmessagebundle.

Chrysweel avatar Chrysweel commented on May 28, 2024

But I have a question.
I can create my service and define my fields of form, in my services.yml:

message.type.new_thread_form:
        class: myProject\MessageBundle\Form\MyMessageType

But handler and model ??
How it works?

Thanks for you time!

from fosmessagebundle.

khepin avatar khepin commented on May 28, 2024

There are a few versions of your models in this bundle.

  • A generic abstract one
  • One tied to your specific database (RDBMS / MongoDB as of today)
  • One for the forms

So here the model is the one used by the forms. Example: check https://github.com/FriendsOfSymfony/FOSMessageBundle/blob/master/FormModel/NewThreadMessage.php

The form handler takes the form and does whatever should be done with it (validate / send the message etc...)
https://github.com/FriendsOfSymfony/FOSMessageBundle/blob/master/FormHandler/NewThreadMessageFormHandler.php

from fosmessagebundle.

Chrysweel avatar Chrysweel commented on May 28, 2024

Ok.
I have a other problem.
Now it is my config.yml


fos_message:
    db_driver:    orm
    thread_class:    chatea\MessageBundle\Entity\Thread
    message_class:    chatea\MessageBundle\Entity\Message
    new_thread_form:
        type: message.type.new_thread_form
        handler: message.message_bundle.form_handler
        model: chatea\MessageBundle\FormModel\NewThreadMessage

My services.yml

services:
    message.type.new_thread_form:
        class: chatea\MessageBundle\Form\MessageType
    message.message_bundle.form_handler:
        class: chatea\MessageBundle\FormHandler\NewThreadMessageFormHandler

I had created folder Form, FormHandler and FormModel.
MessageType.php , NewThreadMessageFormHandler.php and NewThreadMessage.php

But I get the following error:

Catchable Fatal Error: Argument 1 passed to FOS\MessageBundle\FormHandler\AbstractMessageFormHandler::__construct() must be an instance of Symfony\Component\HttpFoundation\Request, none given, called in /var/www/workspace/chateagratis/app/cache/dev/appDevDebugProjectContainer.php on line 2521 and defined in /var/www/workspace/chateagratis/vendor/friendsofsymfony/message-bundle/FOS/MessageBundle/FormHandler/AbstractMessageFormHandler.php line 25 

So I think that I have include arguments in my service, message.message_bundle.form_handler..

 message.message_bundle.form_handler:
        class: chatea\MessageBundle\FormHandler\NewThreadMessageFormHandler
       arguments: [ @Request , @ComposerInterface, @SenderInterface, @ParticipantProviderInterface ]

But I get this error:

ScopeWideningInjectionException: Scope Widening Injection detected: The definition "message.message_bundle.form_handler" references the service "request" which belongs to a narrower scope. Generally, it is safer to either move "message.message_bundle.form_handler" to scope "request" or alternatively rely on the provider pattern by injecting the container itself, and requesting the service "request" each time it is needed. In rare, special cases however that might not be necessary, then you can set the reference to strict=false to get rid of this error.

I include:

scope: request

But now this problem!

ServiceNotFoundException: The service "message.message_bundle.form_handler" has a dependency on a non-existent service "composerinterface".

How can I add this arguments ?What am I doing wrong ?

Thanks! ; )

from fosmessagebundle.

khepin avatar khepin commented on May 28, 2024

Well it's pretty easy, you're asking the container to create your service with the @ComposerInterface service as a parameter!

So you want something more like:

xxx.message_bundle.form_handler:
    class: xxx\MessageBundle\FormHandler\NewThreadMessageFormHandler
    arguments: [@request, @fos_message.composer, @fos_message.sender, @fos_message.participant_provider]
    scope: request

from fosmessagebundle.

Chrysweel avatar Chrysweel commented on May 28, 2024

Ok @khepin thank you very much
Not understand why it did not work, took many hours with this problem.
You're a genius, Now it works! you saved me. :)

from fosmessagebundle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.