InvalidArgumentException: Field is unknown in frontend_editing_form_alter() when entity has no accessible bundle key field
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3587089. --> Reported by: [paulwoodhead](https://www.drupal.org/user/729734) Related to !167 >>> <p>Problem/Motivation</p> <p>When using frontend_editing with a non-paragraph entity type (e.g. the<br> Employee Directory content type in the Open Intranet distribution),<br> editing any entity via the frontend sidebar throws a fatal error:</p> <p> InvalidArgumentException: Field is unknown. in<br> Drupal\Core\Entity\ContentEntityBase-&gt;getTranslatedField()</p> <p>The cause is in frontend_editing_form_alter() at line 544, where<br> -&gt;get() is called on the bundle key without first checking hasField():</p> <p> $bundle_key = $entity-&gt;getEntityType()-&gt;getKey('bundle');<br> if ($bundle_entity = $entity-&gt;get($bundle_key)-&gt;entity) {</p> <p>If the bundle key is not accessible as a field on the given entity,<br> Drupal throws InvalidArgumentException.</p> <p>Steps to reproduce</p> <p>1. Install Open Intranet (drupal/openintranet)<br> 2. Configure frontend_editing to support the Employee Directory entity type<br> 3. Visit an Employee Directory page on the frontend<br> 4. Click the frontend editing link<br> 5. Fatal error: InvalidArgumentException: Field is unknown</p> <p>Proposed resolution</p> <p>Add a hasField() guard before calling -&gt;get():</p> <p> $bundle_key = $entity-&gt;getEntityType()-&gt;getKey('bundle');<br> if ($bundle_key &amp;&amp; $entity-&gt;hasField($bundle_key) &amp;&amp; ($bundle_entity = $entity-&gt;get($bundle_key)-&gt;entity)) {</p> <p>Patch attached, applies cleanly to 1.9.1.</p>
issue