/** * {@inheritdoc} */ public function getForm(EntityInterface $entity, $operation = 'default', array $form_state_additions = array()) { $form_object = $this->entityManager->getFormObject($entity->getEntityTypeId(), $operation); $form_object->setEntity($entity); $form_state = (new FormState())->setFormState($form_state_additions); return $this->formBuilder->buildForm($form_object, $form_state); }
/** * {@inheritdoc} */ public function getForm(EntityInterface $entity, $operation = 'default', array $form_state = array()) { $form_object = $this->entityManager->getFormObject($entity->getEntityTypeId(), $operation); $form_object->setEntity($entity); $form_state['build_info']['callback_object'] = $form_object; $form_state['build_info']['base_form_id'] = $form_object->getBaseFormID(); $form_state['build_info'] += array('args' => array()); return $this->formBuilder->buildForm($form_object, $form_state); }
/** * {@inheritdoc} * * Instead of a class name or service ID, $form_arg will be a string * representing the entity and operation being performed. * Consider the following route: * @code * path: '/foo/{node}/bar' * defaults: * _entity_form: 'node.edit' * @endcode * This means that the edit form for the node entity will used. * If the entity type has a default form, only the name of the * entity {param} needs to be passed: * @code * path: '/foo/{node}/baz' * defaults: * _entity_form: 'node' * @endcode */ protected function getFormObject(RouteMatchInterface $route_match, $form_arg) { // If no operation is provided, use 'default'. $form_arg .= '.default'; list($entity_type_id, $operation) = explode('.', $form_arg); $form_object = $this->entityManager->getFormObject($entity_type_id, $operation); // Allow the entity form to determine the entity object from a given route // match. $entity = $form_object->getEntityFromRouteMatch($route_match, $entity_type_id); $form_object->setEntity($entity); return $form_object; }
/** * {@inheritdoc} * * Instead of a class name or service ID, $form_arg will be a string * representing the entity and operation being performed. * Consider the following route: * @code * path: '/foo/{node}/bar' * defaults: * _entity_form: 'node.edit' * @endcode * This means that the edit form for the node entity will used. * If the entity type has a default form, only the name of the * entity {param} needs to be passed: * @code * path: '/foo/{node}/baz' * defaults: * _entity_form: 'node' * @endcode */ protected function getFormObject(Request $request, $form_arg) { // If no operation is provided, use 'default'. $form_arg .= '.default'; list($entity_type, $operation) = explode('.', $form_arg); if ($request->attributes->has($entity_type)) { $entity = $request->attributes->get($entity_type); } else { $entity = $this->manager->getStorage($entity_type)->create(array()); } return $this->manager->getFormObject($entity_type, $operation)->setEntity($entity); }
/** * {@inheritdoc} */ public function submitForm(array &$form, array &$form_state) { $current_user_id = $this->currentUser()->id(); // Clear out the accounts from the temp store. $this->tempStoreFactory->get('user_user_operations_cancel')->delete($current_user_id); if ($form_state['values']['confirm']) { foreach ($form_state['values']['accounts'] as $uid => $value) { // Prevent programmatic form submissions from cancelling user 1. if ($uid <= 1) { continue; } // Prevent user administrators from deleting themselves without confirmation. if ($uid == $current_user_id) { $admin_form_mock = array(); $admin_form_state = $form_state; unset($admin_form_state['values']['user_cancel_confirm']); // The $user global is not a complete user entity, so load the full // entity. $account = $this->userStorage->load($uid); $admin_form = $this->entityManager->getFormObject('user', 'cancel'); $admin_form->setEntity($account); // Calling this directly required to init form object with $account. $admin_form->buildForm($admin_form_mock, $admin_form_state); $admin_form->submit($admin_form_mock, $admin_form_state); } else { user_cancel($form_state['values'], $uid, $form_state['values']['user_cancel_method']); } } } $form_state['redirect_route']['route_name'] = 'user.admin_account'; }
/** * {@inheritdoc} */ public function entityForm($entity_form, FormStateInterface $form_state) { $operation = 'default'; $controller = $this->entityManager->getFormObject($entity_form['#entity']->getEntityTypeId(), $operation); $controller->setEntity($entity_form['#entity']); $child_form_state = $this->buildChildFormState($controller, $form_state, $entity_form['#entity'], $operation); $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; }
/** * {@inheritdoc} */ public function getFormObject($entity_type, $operation) { return $this->entityManager->getFormObject($entity_type, $operation); }