Commit 82eb2924 authored by alexpott's avatar alexpott

Issue #2112807 by tim.plunkett: Move the form builder functions in form.inc to a form service.

parent 4649f481
......@@ -113,6 +113,11 @@ services:
factory_class: Drupal\Core\Database\Database
factory_method: getConnection
arguments: [default]
form_builder:
class: Drupal\Core\Form\FormBuilder
arguments: ['@module_handler', '@keyvalue.expirable', '@event_dispatcher', '@url_generator', '@string_translation', '@?csrf_token', '@?http_kernel']
calls:
- [setRequest, ['@?request']]
keyvalue:
class: Drupal\Core\KeyValueStore\KeyValueFactory
arguments: ['@service_container', '@settings']
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -13,6 +13,7 @@
use Drupal\Core\StringTranslation\Translator\FileTranslation;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
......@@ -455,6 +456,16 @@ function install_begin_request(&$install_state) {
$container->register('url_generator', 'Drupal\Core\Routing\NullGenerator');
$container->register('form_builder', 'Drupal\Core\Form\FormBuilder')
->addArgument(new Reference('module_handler'))
->addArgument(new Reference('keyvalue.expirable'))
->addArgument(new Reference('event_dispatcher'))
->addArgument(new Reference('url_generator'))
->addArgument(new Reference('string_translation'))
->addArgument(new Reference('csrf_token', ContainerInterface::IGNORE_ON_INVALID_REFERENCE))
->addArgument(new Reference('http_kernel', ContainerInterface::IGNORE_ON_INVALID_REFERENCE))
->addMethodCall('setRequest', array(new Reference('request')));
// Register UUID.
CoreServiceProvider::registerUuid($container);
......
......@@ -547,4 +547,14 @@ public static function transliteration() {
return static::$container->get('transliteration');
}
/**
* Returns the form builder service.
*
* @return \Drupal\Core\Form\FormBuilderInterface
* The form builder.
*/
public static function formBuilder() {
return static::$container->get('form_builder');
}
}
......@@ -64,8 +64,9 @@ public function content(Request $request, $_form) {
unset($args[0], $args[1]);
$form_state['build_info']['args'] = array_values($args);
$form_id = _drupal_form_id($form_object, $form_state);
return drupal_build_form($form_id, $form_state);
$form_builder = $this->container->get('form_builder');
$form_id = $form_builder->getFormId($form_object, $form_state);
return $form_builder->buildForm($form_id, $form_state);
}
/**
......
This diff is collapsed.
This diff is collapsed.
......@@ -204,13 +204,16 @@ public function fieldForm(EntityInterface $entity, $field_name, $langcode, $view
$this->tempStoreFactory->get('edit')->set($entity->uuid(), $entity);
}
$form_object = EditFieldForm::create($this->container);
$form_state = array(
'langcode' => $langcode,
'no_redirect' => TRUE,
'build_info' => array('args' => array($entity, $field_name)),
'build_info' => array(
'args' => array($entity, $field_name),
'callback_object' => $form_object,
),
);
$form_id = _drupal_form_id(EditFieldForm::create($this->container), $form_state);
$form = drupal_build_form($form_id, $form_state);
$form = drupal_build_form($form_object->getFormId(), $form_state);
if (!empty($form_state['executed'])) {
// The form submission saved the entity in tempstore. Return the
......
......@@ -1538,7 +1538,6 @@ function theme_file_managed_file($variables) {
* This function is assigned as a #pre_render callback in file_element_info().
*
* @see file_managed_file_process()
* @see form_builder()
*/
function file_managed_file_pre_render($element) {
// If we already have a file, we don't want to show the upload controls.
......
......@@ -46,7 +46,7 @@ public function setUp() {
* Tests the form cache with a logged-in user.
*/
function testCacheToken() {
$GLOBALS['user'] = new UserSession(array('uid' => 1));
$this->container->set('current_user', new UserSession(array('uid' => 1)));
form_set_cache($this->form_build_id, $this->form, $this->form_state);
$cached_form_state = form_state_defaults();
......@@ -75,7 +75,7 @@ function testCacheToken() {
* Tests the form cache without a logged-in user.
*/
function testNoCacheToken() {
$GLOBALS['user'] = new UserSession(array('uid' => 0));
$this->container->set('current_user', new UserSession(array('uid' => 0)));
$this->form_state['example'] = $this->randomName();
form_set_cache($this->form_build_id, $this->form, $this->form_state);
......
This diff is collapsed.
......@@ -174,9 +174,7 @@ protected function getBlockMockWithMachineName($machine_name) {
* A MockBuilder of \Drupal\Core\StringTranslation\TranslationInterface
*/
public function getStringTranslationStub() {
$translation = $this->getMockBuilder('Drupal\Core\StringTranslation\TranslationManager')
->disableOriginalConstructor()
->getMock();
$translation = $this->getMock('Drupal\Core\StringTranslation\TranslationInterface');
$translation->expects($this->any())
->method('translate')
->will($this->returnArgument(0));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment