From dffb305079d265f2bef4cafabad3c2deec2a80e3 Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Thu, 17 Dec 2015 19:11:28 +0000
Subject: [PATCH] Issue #2617590 by aspilicious, Berdir: ConfigEntityBundleBase
 needs to clear bundle cache when updating a bundle

---
 .../Core/Config/Entity/ConfigEntityBundleBase.php    |  1 +
 core/modules/node/src/Tests/NodeTypeTest.php         | 12 ++++++++++++
 2 files changed, 13 insertions(+)

diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBundleBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBundleBase.php
index 8e27aef731dd..47a8f308a8e3 100644
--- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBundleBase.php
+++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBundleBase.php
@@ -54,6 +54,7 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) {
       }
       // Entity bundle field definitions may depend on bundle settings.
       $entity_manager->clearCachedFieldDefinitions();
+      $entity_manager->clearCachedBundles();
     }
   }
 
diff --git a/core/modules/node/src/Tests/NodeTypeTest.php b/core/modules/node/src/Tests/NodeTypeTest.php
index 07117f709b69..945c83fd7072 100644
--- a/core/modules/node/src/Tests/NodeTypeTest.php
+++ b/core/modules/node/src/Tests/NodeTypeTest.php
@@ -10,6 +10,7 @@
 use Drupal\field\Entity\FieldConfig;
 use Drupal\node\Entity\NodeType;
 use Drupal\Core\Url;
+use Drupal\node\NodeTypeInterface;
 
 /**
  * Ensures that node type functions work correctly.
@@ -124,6 +125,17 @@ function testNodeTypeEditing() {
     $this->assertRaw('Foo', 'Title field was found.');
     $this->assertRaw('Body', 'Body field was found.');
 
+    // Change the name through the API
+    /** @var NodeTypeInterface $node_type */
+    $node_type = NodeType::load('page');
+    $node_type->set('name', 'NewBar');
+    $node_type->save();
+
+    /** @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface $bundle_info */
+    $bundle_info = \Drupal::service('entity_type.bundle.info');
+    $node_bundles = $bundle_info->getBundleInfo('node');
+    $this->assertEqual($node_bundles['page']['label'], 'NewBar', 'Node type bundle cache is updated');
+
     // Remove the body field.
     $this->drupalPostForm('admin/structure/types/manage/page/fields/node.page.body/delete', array(), t('Delete'));
     // Resave the settings for this type.
-- 
GitLab