Issue #2368975 by damiankloip: Fixed ElementInfoManager::buildInfo() processes info data on every request.
parent
ec7b05625a
commit
b0c49c821f
|
@ -533,6 +533,11 @@ class FormBuilder implements FormBuilderInterface, FormValidatorInterface, FormS
|
|||
|
||||
$form['#type'] = 'form';
|
||||
|
||||
// Only update the action if it is not already set.
|
||||
if (!isset($form['#action'])) {
|
||||
$form['#action'] = $this->requestUri();
|
||||
}
|
||||
|
||||
// Fix the form method, if it is 'get' in $form_state, but not in $form.
|
||||
if ($form_state->isMethodType('get') && !isset($form['#method'])) {
|
||||
$form['#method'] = 'get';
|
||||
|
@ -1096,4 +1101,13 @@ class FormBuilder implements FormBuilderInterface, FormValidatorInterface, FormS
|
|||
return $this->currentUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current request URI.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function requestUri() {
|
||||
return request_uri();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ class Form extends RenderElement {
|
|||
public function getInfo() {
|
||||
return array(
|
||||
'#method' => 'post',
|
||||
'#action' => request_uri(),
|
||||
'#theme_wrappers' => array('form'),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
namespace Drupal\Core\Render;
|
||||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Cache\CacheBackendInterface;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Plugin\DefaultPluginManager;
|
||||
|
@ -65,6 +66,12 @@ class ElementInfoManager extends DefaultPluginManager implements ElementInfoMana
|
|||
* Builds up all element information.
|
||||
*/
|
||||
protected function buildInfo() {
|
||||
// Get cached definitions.
|
||||
if ($cache = $this->cacheBackend->get('element_info_build')) {
|
||||
return $cache->data;
|
||||
}
|
||||
|
||||
// Otherwise, rebuild and cache.
|
||||
// @todo Remove this hook once all elements are converted to plugins in
|
||||
// https://www.drupal.org/node/2311393.
|
||||
$info = $this->moduleHandler->invokeAll('element_info');
|
||||
|
@ -81,12 +88,15 @@ class ElementInfoManager extends DefaultPluginManager implements ElementInfoMana
|
|||
}
|
||||
$info[$element_type] = $element_info;
|
||||
}
|
||||
|
||||
foreach ($info as $element_type => $element) {
|
||||
$info[$element_type]['#type'] = $element_type;
|
||||
}
|
||||
// Allow modules to alter the element type defaults.
|
||||
$this->moduleHandler->alter('element_info', $info);
|
||||
|
||||
$this->cacheBackend->set('element_info_build', $info, Cache::PERMANENT);
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
|
@ -99,4 +109,15 @@ class ElementInfoManager extends DefaultPluginManager implements ElementInfoMana
|
|||
return parent::createInstance($plugin_id, $configuration);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function clearCachedDefinitions() {
|
||||
$this->elementInfo = NULL;
|
||||
$this->cacheBackend->delete('element_info_build');
|
||||
|
||||
parent::clearCachedDefinitions();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -327,6 +327,13 @@ class TestFormBuilder extends FormBuilder {
|
|||
static::$seenIds = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function requestUri() {
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -69,6 +69,21 @@ class ElementInfoManagerTest extends UnitTestCase {
|
|||
return $info;
|
||||
}));
|
||||
|
||||
$this->cache->expects($this->at(0))
|
||||
->method('get')
|
||||
->with('element_info_build')
|
||||
->will($this->returnValue(FALSE));
|
||||
$this->cache->expects($this->at(1))
|
||||
->method('get')
|
||||
->with('element_info')
|
||||
->will($this->returnValue(FALSE));
|
||||
$this->cache->expects($this->at(2))
|
||||
->method('set')
|
||||
->with('element_info');
|
||||
$this->cache->expects($this->at(3))
|
||||
->method('set')
|
||||
->with('element_info_build');
|
||||
|
||||
$this->assertEquals($expected_info, $this->elementInfo->getInfo($type));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue