Cannot edit paragraphs when using paragraphs_edit: ^4.0
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3591596. -->
Reported by: [alexortega_98](https://www.drupal.org/user/3711404)
Related to !173
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>
The <code>frontend_editing_paragraphs</code> sub-module is incompatible with<br>
<code>paragraphs_edit 4.x</code>. Attempting to open a paragraph's edit or<br>
delete form through the frontend editing sidebar throws:
</p>
<pre>
Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException: The "paragraph" entity type did not specify a "entity_edit" form class. in Drupal\Core\Entity\EntityTypeManager->getFormObject() (line 209 of core/lib/Drupal/Core/Entity/EntityTypeManager.php).
</pre><p>
<code>paragraphs_edit 3.x</code> registered two custom form operations on the<br>
paragraph entity type <code>entity_edit</code> and <code>entity_delete</code><br>
and provided dedicated routes <code>paragraphs_edit.edit_form</code> and<br>
<code>paragraphs_edit.delete_form</code> that carried <code>root_parent_type</code><br>
and <code>root_parent</code> as route parameters.
</p>
<p>
<code>paragraphs_edit 4.x</code> (Drupal 11 only) removed those custom<br>
operations and routes. It now registers the form classes under the standard<br>
<code>edit</code> and <code>delete</code> operations, uses the standard<br>
<code>entity.paragraph.edit_form</code> / <code>entity.paragraph.delete_form</code><br>
routes, and resolves the root parent automatically inside<br>
<code>ParagraphFormHelperTrait::buildForm()</code> rather than relying on<br>
<code>form_state</code> build args.
</p>
<p>
<code>FrontendEditingParagraphsFormBuilder</code> hardcoded <code>entity_edit</code><br>
and <code>entity_delete</code> as well as the 3.x route names, making it<br>
broken with 4.x.
</p>
<h4 id="summary-steps-reproduce">Steps to reproduce</h4>
<ol>
<li>Enable <code>frontend_editing</code>, <code>frontend_editing_paragraphs</code>,<br>
<code>paragraphs</code>, and <code>paragraphs_edit</code> 4.x on a Drupal 11 site.</li>
<li>Configure a paragraph and content type bundle in the <code>frontend_editing.settings</code>.<br>
Add the paragraph to a node.
</li>
<li>Create a node of that content type, that references that paragraph bundle, and enable frontend editing, clicking on the pencil on node view.</li>
<li>Click the edit action link on a paragraph.</li>
<li>The sidebar throws an <code>InvalidPluginDefinitionException</code>.</li>
</ol>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>
Make <code>FrontendEditingParagraphsFormBuilder</code> detect the installed<br>
version of <code>paragraphs_edit</code> at runtime by checking whether the<br>
<code>entity_edit</code> / <code>entity_delete</code> form classes are<br>
registered on the paragraph entity type definition.
</p>
<ul>
<li>
If <code>entity_edit</code> is present (3.x): keep the existing behaviour, use that operation, pass <code>root_parent</code> via<br>
<code>form_state</code> build args, and set the form action to<br>
<code>paragraphs_edit.edit_form</code>.
</li>
<li>
If it is absent (4.x): use the standard <code>edit</code> operation, omit<br>
the <code>root_parent</code> build arg (4.x resolves it automatically inside<br>
<code>ParagraphFormHelperTrait::buildForm()</code>), and set the form action<br>
to <code>entity.paragraph.edit_form</code>.
</li>
</ul>
<p>The same two-path logic is applied to <code>buildDeleteForm()</code>.</p>
<p>We can also just fix it for the 4.x version, but this would mean that we need to change the composer suggestion version of the <code>paragraphs_edit</code> module, probably not now as it's still on alpha version, but we could leave a patch for those using this version.</p>
<h3 id="summary-remaining-tasks">Remaining tasks</h3>
<ul>
<li>Decide how to move further.</li>
<li>Review the patch.</li>
<li>Add a functional test that covers the edit and delete flows under<br>
<code>paragraphs_edit</code> 4.x.</li>
</ul>
issue