<p dir="auto">This is a follow-up to my comments in issue <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="13582476" data-permission-text="Title is private" data-url="https://github.com/symfony/symfony/issues/7828" data-hovercard-type="issue" data-hovercard-url="/symfony/symfony/issues/7828/hovercard" href="https://github.com/symfony/symfony/issues/7828">#7828</a>.</p>
<p dir="auto">All subscribers listening for a PRE_SET_DATA event will receive <em>model</em> data. This can be problematic since certain field types start to dictate a very specific format for data in the model. even with a data transformer in place.</p>
<p dir="auto">For example, in my usecase I have model data which could work with the CollectionType, which registers a ResizeListener internally. My data needs transforming before hitting the ResizeListener, as it expects a certain format of data. Since the ResizeListener receives <em>model</em> data on PRE_SET_DATA, there is no mechanism to prepare the data for the listener. The end result is I have to modify the model data itself to get it through the ResizeListener.</p>
<p dir="auto">Ultimately, a PRE_SET_DATA listener can introduce a specific data format requirement on the model, which can't be solved by simply adding a data transformer.</p>
<p dir="auto">My thoughts are that if listeners (or at least the ResizeListener specifically) received normalised data, which a transformer can take care of, it wouldn't be possible to impose specific format requirements on the model.</p>
<p dir="auto">Starting on a PR regarding another issue and I hooked up on of my applications to 2.8 instead of 2.6. For me this was 2 seconds to figure out it was caused by the old way of defining a factory service + method, but the error message might cause a lot of confusion for others. The message is thrown in the Definition class rather than the place where you expect it (Yaml Loader in this case).</p>
<p dir="auto">The fix for this is to change your service definition:</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    # old
    app.layout.menu.beta:
        class: Knp\Menu\MenuItem
        factory_service: app.layout.menu_builder
        factory_method: createBetaMenu
        tags:
            - { name: knp_menu.menu, alias: beta }

    # new
    app.layout.menu.beta:
        class: Knp\Menu\MenuItem
        factory: [@app.layout.menu_builder, createBetaMenu]
        tags:
            - { name: knp_menu.menu, alias: beta }"><pre class="notranslate">    <span class="pl-c"><span class="pl-c">#</span> old</span>
    <span class="pl-ent">app.layout.menu.beta</span>:
        <span class="pl-ent">class</span>: <span class="pl-s">Knp\Menu\MenuItem</span>
        <span class="pl-ent">factory_service</span>: <span class="pl-s">app.layout.menu_builder</span>
        <span class="pl-ent">factory_method</span>: <span class="pl-s">createBetaMenu</span>
        <span class="pl-ent">tags</span>:
            - <span class="pl-s">{ name: knp_menu.menu, alias: beta }</span>

    <span class="pl-c"><span class="pl-c">#</span> new</span>
    <span class="pl-ent">app.layout.menu.beta</span>:
        <span class="pl-ent">class</span>: <span class="pl-s">Knp\Menu\MenuItem</span>
        <span class="pl-ent">factory</span>: <span class="pl-s">[@app.layout.menu_builder, createBetaMenu]</span>
        <span class="pl-ent">tags</span>:
            - <span class="pl-s">{ name: knp_menu.menu, alias: beta }</span></pre></div>
<p dir="auto">The thing is that the error message below does not clearly reflect that. I don't think it's desired to put this information in the message below, but maybe someone has a nice idea where to put it instead.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Deprecated: The Symfony\Component\DependencyInjection\Definition::setFactoryMethod method is deprecated since version 2.6 and will be removed in 3.0. Use Definition::setFactory() instead. in /home/ivanderberg/projects/symfony/src/Symfony/Component/DependencyInjection/Definition.php on line 137"><pre class="notranslate"><code class="notranslate">Deprecated: The Symfony\Component\DependencyInjection\Definition::setFactoryMethod method is deprecated since version 2.6 and will be removed in 3.0. Use Definition::setFactory() instead. in /home/ivanderberg/projects/symfony/src/Symfony/Component/DependencyInjection/Definition.php on line 137
</code></pre></div>