Commit db0ece00 authored by alexpott's avatar alexpott

Issue #2579847 by marcvangend, hussainweb, YesCT, dawehner, chx, Wim Leers:...

Issue #2579847 by marcvangend, hussainweb, YesCT, dawehner, chx, Wim Leers: /node/add is lacking cacheability metadata, causes problems when cached by Dynamic Page Cache and "Use admin theme when editing or creating content" is turned off
parent 3d18097a
......@@ -72,13 +72,22 @@ public static function create(ContainerInterface $container) {
* type.
*/
public function addPage() {
$build = [
'#theme' => 'node_add_list',
'#cache' => [
'tags' => $this->entityManager()->getDefinition('node_type')->getListCacheTags(),
],
];
$content = array();
// Only use node types the user has access to.
foreach ($this->entityManager()->getStorage('node_type')->loadMultiple() as $type) {
if ($this->entityManager()->getAccessControlHandler('node')->createAccess($type->id())) {
$access = $this->entityManager()->getAccessControlHandler('node')->createAccess($type->id(), NULL, [], TRUE);
if ($access->isAllowed()) {
$content[$type->id()] = $type;
}
$this->renderer->addCacheableDependency($build, $access);
}
// Bypass the node/add listing if only one content type is available.
......@@ -87,10 +96,9 @@ public function addPage() {
return $this->redirect('node.add', array('node_type' => $type->id()));
}
return array(
'#theme' => 'node_add_list',
'#content' => $content,
);
$build['#content'] = $content;
return $build;
}
/**
......
......@@ -64,6 +64,13 @@ function testNodeTypeCreation() {
// Create a content type via the user interface.
$web_user = $this->drupalCreateUser(array('bypass node access', 'administer content types'));
$this->drupalLogin($web_user);
$this->drupalGet('node/add');
$this->assertCacheTag('config:node_type_list');
$this->assertCacheContext('user.permissions');
$elements = $this->cssSelect('dl.node-type-list dt');
$this->assertEqual(3, count($elements));
$edit = array(
'name' => 'foo',
'title_label' => 'title for foo',
......@@ -72,6 +79,10 @@ function testNodeTypeCreation() {
$this->drupalPostForm('admin/structure/types/add', $edit, t('Save and manage fields'));
$type_exists = (bool) NodeType::load('foo');
$this->assertTrue($type_exists, 'The new content type has been created in the database.');
$this->drupalGet('node/add');
$elements = $this->cssSelect('dl.node-type-list dt');
$this->assertEqual(4, count($elements));
}
/**
......
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