Commit b0c49c82 authored by alexpott's avatar alexpott

Issue #2368975 by damiankloip: Fixed ElementInfoManager::buildInfo() processes...

Issue #2368975 by damiankloip: Fixed ElementInfoManager::buildInfo() processes info data on every request.
parent ec7b0562
......@@ -533,6 +533,11 @@ public function prepareForm($form_id, &$form, FormStateInterface &$form_state) {
$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 @@ protected function currentUser() {
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 @@ public function getInfo($type) {
* 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 @@ protected function buildInfo() {
}
$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 @@ public function createInstance($plugin_id, array $configuration = array()) {
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 @@ public function drupalStaticReset($name = NULL) {
static::$seenIds = array();
}
/**
* {@inheritdoc}
*/
protected function requestUri() {
return '';
}
}
}
......
......@@ -69,6 +69,21 @@ public function testGetInfo($type, $expected_info, $element_info, callable $alte
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));
}
......
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