示例#1
0
  /**
   * {@inheritdoc}
   */
  public function entityForm($entity_form, FormStateInterface $form_state) {
    $operation = 'default';
    $controller = $this->entityTypeManager->getFormObject($entity_form['#entity']->getEntityTypeId(), $operation, FALSE);
    $controller->setEntity($entity_form['#entity']);
    $form_state->set(['inline_entity_form', $entity_form['#ief_id'], 'entity_form'], $controller);

    $child_form_state = $this->buildChildFormState($controller, $form_state, $entity_form['#entity'], $operation, $entity_form['#parents']);

    $entity_form = $controller->buildForm($entity_form, $child_form_state);

    if (!$entity_form['#display_actions']) {
      unset($entity_form['actions']);
    }

    // TODO - this is field-only part of the code. Figure out how to refactor.
    if ($child_form_state->get('inline_entity_form')) {
      foreach ($child_form_state->get('inline_entity_form') as $id => $data) {
        $form_state->set(['inline_entity_form', $id], $data);
      }
    }

    $form_state->set('field', $child_form_state->get('field'));

    $entity_form['#element_validate'][] = [get_class($this), 'entityFormValidate'];

    $entity_form['#ief_element_submit'][] = [get_class($this), 'entityFormSubmit'];
    $entity_form['#ief_element_submit'][] = [get_class($this), 'submitCleanFormState'];

    // Allow other modules to alter the form.
    $this->moduleHandler->alter('inline_entity_form_entity_form', $entity_form, $form_state);

    return $entity_form;
  }
 /**
  * Gets the entity form for this menu.
  *
  * @param \Drupal\system\MenuInterface $entity
  *   The menu entity.
  *
  * @return \Drupal\Core\Entity\EntityFormInterface
  *   The entity form.
  */
 protected function getEntityForm(MenuInterface $entity)
 {
     $entity_form = $this->entityTypeManager->getFormObject('menu', 'edit');
     $entity_form->setEntity($entity);
     return $entity_form;
 }