WSOD when other contrib modules provide forms that are incompatible with EntityForm::buildEntity()
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3551825. -->
Reported by: [starlight-sparkle](https://www.drupal.org/user/3804225)
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>Some contrib module forms extend <code>\Drupal\Core\Entity\EntityForm</code>, and thus inherits all its public methods, but then override <code>::buildForm()</code> in a way that makes them incompatible with <code>::buildEntity()</code>, because they add fields that are not present in the entity.</p>
<p>ECA Form universally applies a form submit hook to all forms implementing <code>\Drupal\Core\Entity\EntityFormInterface</code>.<br>
In this hook, it calls <code>EntityFormInterface::buildEntity()</code>.<br>
When the above mentioned forms are submitted, this results in WSOD, due to the mentioned incompatibility.</p>
<h4 id="summary-steps-reproduce">Steps to reproduce</h4>
<ol>
<li>Enable ECA, ECA Form modules.</li>
<li>Enable Commerce, Commerce payment, Commerce product, Commerce order modules.</li>
<li>Create a manual payment gateway in Commerce.</li>
<li>Create a Commerce order with manual payment.</li>
<li>Navigate to the admin order payment page, and click "receive".</li>
<li>Submit the operations form.</li>
<li>WSOD</li>
</ol>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>Optimally, this should be resolved in the other contrib modules so they don't break their public interface methods.<br>
However, it would probably be prudent for ECA Form to clone the form state, check for invalid fields, and strip them out before calling <code>::buildEntity()</code>.<br>
If this results in a form state object with no fields, fall back to just using <code>::getEntity()</code>.</p>
<p>Alternatively, wrap the <code>::buildEntity()</code> call in a try catch and fall back to using <code>::getEntity()</code> in the catch.</p>
<h3 id="summary-remaining-tasks">Remaining tasks</h3>
<h3 id="summary-ui-changes">User interface changes</h3>
<h3 id="summary-api-changes">API changes</h3>
<h3 id="summary-data-model-changes">Data model changes</h3>
issue