Example #1
0
 /**
  * {@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);
 }
Example #2
0
 /**
  * {@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);
 }
Example #3
0
 /**
  * Simulates a form submission within a request, bypassing submitForm().
  *
  * Calling submitForm() will reset the form builder, if two forms were on the
  * same page, they will be submitted simultaneously.
  *
  * @param string $form_id
  *   The unique string identifying the form.
  * @param \Drupal\Core\Form\FormInterface $form_arg
  *   The form object.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The current state of the form.
  * @param bool $programmed
  *   Whether $form_state->setProgrammed() should be passed TRUE or not. If it
  *   is not set to TRUE, you must provide additional data in $form_state for
  *   the submission to take place.
  *
  * @return array
  *   The built form.
  */
 protected function simulateFormSubmission($form_id, FormInterface $form_arg, FormStateInterface $form_state, $programmed = TRUE)
 {
     $input = $form_state->getUserInput();
     $input['op'] = 'Submit';
     $form_state->setUserInput($input)->setProgrammed($programmed)->setSubmitted();
     return $this->formBuilder->buildForm($form_arg, $form_state);
 }
Example #4
0
 /**
  * Invokes the form and returns the result.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request object.
  *
  * @return array
  *   The render array that results from invoking the controller.
  */
 public function getContentResult(Request $request)
 {
     $form_object = $this->getFormObject($request, $this->formDefinition);
     // Add the form and form_state to trick the getArguments method of the
     // controller resolver.
     $form_state = array();
     $request->attributes->set('form', array());
     $request->attributes->set('form_state', $form_state);
     $args = $this->controllerResolver->getArguments($request, array($form_object, 'buildForm'));
     $request->attributes->remove('form');
     $request->attributes->remove('form_state');
     // Remove $form and $form_state from the arguments, and re-index them.
     unset($args[0], $args[1]);
     $form_state['build_info']['args'] = array_values($args);
     return $this->formBuilder->buildForm($form_object, $form_state);
 }
Example #5
0
 /**
  * Invokes the form and returns the result.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request object.
  * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  *   The route match.
  *
  * @return array
  *   The render array that results from invoking the controller.
  */
 public function getContentResult(Request $request, RouteMatchInterface $route_match)
 {
     $form_arg = $this->getFormArgument($route_match);
     $form_object = $this->getFormObject($route_match, $form_arg);
     // Add the form and form_state to trick the getArguments method of the
     // controller resolver.
     $form_state = new FormState();
     $request->attributes->set('form', []);
     $request->attributes->set('form_state', $form_state);
     $args = $this->controllerResolver->getArguments($request, [$form_object, 'buildForm']);
     $request->attributes->remove('form');
     $request->attributes->remove('form_state');
     // Remove $form and $form_state from the arguments, and re-index them.
     unset($args[0], $args[1]);
     $form_state->addBuildInfo('args', array_values($args));
     return $this->formBuilder->buildForm($form_object, $form_state);
 }
Example #6
0
 /**
  * Simulates a form submission within a request, bypassing submitForm().
  *
  * Calling submitForm() will reset the form builder, if two forms were on the
  * same page, they will be submitted simultaneously.
  *
  * @param string $form_id
  *   The unique string identifying the form.
  * @param \Drupal\Core\Form\FormInterface $form_arg
  *   The form object.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The current state of the form.
  * @param bool $programmed
  *   Whether $form_state['programmed'] should be set to TRUE or not. If it is
  *   not set to TRUE, you must provide additional data in $form_state for the
  *   submission to take place.
  *
  * @return array
  *   The built form.
  */
 protected function simulateFormSubmission($form_id, FormInterface $form_arg, FormStateInterface $form_state, $programmed = TRUE)
 {
     $form_state['build_info']['callback_object'] = $form_arg;
     $form_state['build_info']['args'] = array();
     $form_state['input']['op'] = 'Submit';
     $form_state['programmed'] = $programmed;
     $form_state['submitted'] = TRUE;
     return $this->formBuilder->buildForm($form_arg, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 public function getWizardForm(FormWizardInterface $wizard, array $parameters = [], $ajax = FALSE)
 {
     $form_state = $this->getFormState($wizard, $parameters, $ajax);
     $form = $this->builder->buildForm($wizard, $form_state);
     if ($ajax) {
         $form['#attached']['library'][] = 'core/drupal.dialog.ajax';
         $status_messages = array('#type' => 'status_messages');
         // @todo properly inject the renderer. Core should really be doing this work.
         if ($messages = \Drupal::service('renderer')->renderRoot($status_messages)) {
             if (!empty($form['#prefix'])) {
                 // Form prefix is expected to be a string. Prepend the messages to
                 // that string.
                 $form['#prefix'] = '<div class="wizard-messages">' . $messages . '</div>' . $form['#prefix'];
             }
         }
     }
     return $form;
 }