diff --git a/core/lib/Drupal/Core/ContentNegotiation.php b/core/lib/Drupal/Core/ContentNegotiation.php
index d2ffa456d779d48e55985f61ff91089b9353385c..500200cf75135c828d20e3eadad2379b389a67bc 100644
--- a/core/lib/Drupal/Core/ContentNegotiation.php
+++ b/core/lib/Drupal/Core/ContentNegotiation.php
@@ -38,9 +38,9 @@ public function getContentType(Request $request) {
 
     // Check all formats, if priority format is found return it.
     $first_found_format = FALSE;
+    $priority = array('html', 'drupal_ajax', 'drupal_modal', 'drupal_dialog');
     foreach ($request->getAcceptableContentTypes() as $mime_type) {
       $format = $request->getFormat($mime_type);
-      $priority = array('html', 'drupal_ajax', 'drupal_modal', 'drupal_dialog');
       if (in_array($format, $priority, TRUE)) {
         return $format;
       }