Skip to content

Instantly share code, notes, and snippets.

@ahebrank
Created June 25, 2018 11:30
Show Gist options
  • Select an option

  • Save ahebrank/2df7bed51cb9eb2a58794a8bf61b6a25 to your computer and use it in GitHub Desktop.

Select an option

Save ahebrank/2df7bed51cb9eb2a58794a8bf61b6a25 to your computer and use it in GitHub Desktop.
diff --git a/src/Element/InlineEntityForm.php b/src/Element/InlineEntityForm.php
index 0fbe233..f47e2de 100644
--- a/src/Element/InlineEntityForm.php
+++ b/src/Element/InlineEntityForm.php
@@ -8,6 +8,7 @@ use Drupal\Core\Render\Element;
use Drupal\Core\Render\Element\RenderElement;
use Drupal\inline_entity_form\ElementSubmit;
use Drupal\inline_entity_form\TranslationHelper;
+use Drupal\Core\Entity\ContentEntityInterface;
/**
* Provides an inline entity form element.
@@ -128,9 +129,12 @@ class InlineEntityForm extends RenderElement {
$entity_form['#op'] = $entity_form['#entity']->isNew() ? 'add' : 'edit';
}
}
- // Prepare the entity form and the entity itself for translating.
- $entity_form['#entity'] = TranslationHelper::prepareEntity($entity_form['#entity'], $form_state);
- $entity_form['#translating'] = TranslationHelper::isTranslating($form_state) && $entity_form['#entity']->isTranslatable();
+
+ if ($entity_form['#entity'] instanceof ContentEntityInterface) {
+ // Prepare the entity form and the entity itself for translating.
+ $entity_form['#entity'] = TranslationHelper::prepareEntity($entity_form['#entity'], $form_state);
+ $entity_form['#translating'] = TranslationHelper::isTranslating($form_state) && $entity_form['#entity']->isTranslatable();
+ }
$inline_form_handler = static::getInlineFormHandler($entity_form['#entity_type']);
$entity_form = $inline_form_handler->entityForm($entity_form, $form_state);
diff --git a/src/Form/EntityInlineForm.php b/src/Form/EntityInlineForm.php
index 1ff5073..fef1148 100644
--- a/src/Form/EntityInlineForm.php
+++ b/src/Form/EntityInlineForm.php
@@ -2,7 +2,7 @@
namespace Drupal\inline_entity_form\Form;
-use Drupal\Core\Entity\ContentEntityInterface;
+use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityFieldManagerInterface;
@@ -279,12 +279,12 @@ class EntityInlineForm implements InlineFormInterface {
*
* @param array $entity_form
* The entity form.
- * @param \Drupal\Core\Entity\ContentEntityInterface $entity
+ * @param \Drupal\Core\Entity\FieldableEntityInterface $entity
* The entity.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*/
- protected function buildEntity(array $entity_form, ContentEntityInterface $entity, FormStateInterface $form_state) {
+ protected function buildEntity(array $entity_form, FieldableEntityInterface $entity, FormStateInterface $form_state) {
$form_display = $this->getFormDisplay($entity, $entity_form['#form_mode']);
$form_display->extractFormValues($entity, $entity_form, $form_state);
// Invoke all specified builders for copying form values to entity fields.
@@ -330,7 +330,7 @@ class EntityInlineForm implements InlineFormInterface {
/**
* Gets the form display for the given entity.
*
- * @param \Drupal\Core\Entity\ContentEntityInterface $entity
+ * @param \Drupal\Core\Entity\FieldableEntityInterface $entity
* The entity.
* @param string $form_mode
* The form mode.
@@ -338,7 +338,7 @@ class EntityInlineForm implements InlineFormInterface {
* @return \Drupal\Core\Entity\Display\EntityFormDisplayInterface
* The form display.
*/
- protected function getFormDisplay(ContentEntityInterface $entity, $form_mode) {
+ protected function getFormDisplay(FieldableEntityInterface $entity, $form_mode) {
return EntityFormDisplay::collectRenderDisplay($entity, $form_mode);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment