diff --git a/core/modules/filter/filter.module b/core/modules/filter/filter.module index 3d13bbb..e68e1b2 100644 --- a/core/modules/filter/filter.module +++ b/core/modules/filter/filter.module @@ -7,6 +7,7 @@ use Drupal\Component\Utility\String; use Drupal\Core\Cache\CacheBackendInterface; +use Drupal\Core\Language\Language; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Template\Attribute; use Drupal\filter\FilterFormatInterface; @@ -203,9 +204,17 @@ function filter_permission() { function filter_formats(AccountInterface $account = NULL) { $formats = &drupal_static(__FUNCTION__, array()); + // All available formats are cached for performance. if (!isset($formats['all'])) { - $formats['all'] = entity_load_multiple_by_properties('filter_format', array('status' => '1')); - uasort($formats['all'], 'Drupal\Core\Config\Entity\ConfigEntityBase::sort'); + $language_interface = Drupal::languageManager()->getLanguage(Language::TYPE_INTERFACE); + if ($cache = Drupal::cache()->get("filter_formats:{$language_interface->id}")) { + $formats['all'] = $cache->data; + } + else { + $formats['all'] = Drupal::entityManager()->getStorageController('filter_format')->loadByProperties(array('status' => '1')); + uasort($formats['all'], 'Drupal\Core\Config\Entity\ConfigEntityBase::sort'); + Drupal::cache()->set("filter_formats:{$language_interface->id}", $formats['all'], CacheBackendInterface::CACHE_PERMANENT, array('filter_formats' => TRUE)); + } } // If no user was specified, return all formats. diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/FilterFormatUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/FilterFormatUpgradePathTest.php index 2725aa9..4c082ee 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/FilterFormatUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/FilterFormatUpgradePathTest.php @@ -73,7 +73,7 @@ public function testFilterFormatUpgrade() { $this->assertNoFieldChecked('edit-5-use-text-format-format-two', 'Use text format format_two permission for role is set correctly.'); // Check that the format has the missing filter. - $two = filter_format_load('format_two'); + $two = entity_load('filter_format', 'format_two'); $this->assertTrue($two->filters()->has('missing_filter')); // Try to use a filter format with a missing filter, this should not throw @@ -86,7 +86,7 @@ public function testFilterFormatUpgrade() { $this->assertRaw(t('The %filter filter is missing, and will be removed once this format is saved.', array('%filter' => 'missing_filter'))); $this->drupalPost(NULL, array(), t('Save configuration')); filter_formats_reset(); - $two = filter_format_load('format_two'); + $two = entity_load('filter_format', 'format_two'); $this->assertFalse($two->filters()->has('missing_filter')); }