Skip to content
Snippets Groups Projects
Commit ad920b97 authored by ghost of drupal past's avatar ghost of drupal past Committed by Andrii Podanenko
Browse files

Issue #2637880 by Charlie ChX Negyesi: Ability to reference an entity and auto open its edit form

parent dcdd91ed
No related branches found
No related tags found
1 merge request!99Closes #3359875
......@@ -2,6 +2,7 @@
namespace Drupal\inline_entity_form\Plugin\Field\FieldWidget;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityDisplayRepositoryInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
......@@ -397,7 +398,7 @@ abstract class InlineEntityFormBase extends WidgetBase implements ContainerFacto
$widget_state['entities'][$delta] = [
'entity' => $entity,
'weight' => $delta,
'form' => NULL,
'form' => self::entityIsOpenFromQuery($entity, $form_state) ? 'edit' : NULL,
'needs_save' => $entity->isNew(),
];
}
......@@ -405,6 +406,19 @@ abstract class InlineEntityFormBase extends WidgetBase implements ContainerFacto
}
}
public static function entityIsOpenFromQuery(ContentEntityInterface $entity, FormStateInterface $form_state) {
$query = \Drupal::request()->query;
if ($query->has('ief_open') && !$form_state->has('inline_entity_form_open')) {
$form_state->set('inline_entity_form_open', $query->get('ief_open'));
}
if ($form_state->has('inline_entity_form_open')) {
$ief_open = $form_state->get('inline_entity_form_open');
$query_value = sprintf('%s:%s', $entity->getEntityTypeId(), $entity->id());
return in_array($query_value, $ief_open);
}
return FALSE;
}
/**
* Gets inline entity form element.
*
......
......@@ -368,6 +368,8 @@ class InlineEntityFormComplex extends InlineEntityFormBase implements ContainerF
$entity = $value['entity'];
$element['entities'][$key]['#label'] = $this->inlineFormHandler->getEntityLabel($value['entity']);
$element['entities'][$key]['#entity'] = $value['entity'];
$element['entities'][$key]['#id'] = sprintf('ief-scrollto--%s-%s', $entity->getEntityTypeId(), $entity->id());
$element['entities'][$key]['#needs_save'] = $value['needs_save'];
// Handle row weights.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment