commit c0ffa0dc255c95becf43c2bd1e83b2997e8e94b7
Author: Julien Dubois <julien@happyculture.coop>
Date:   Wed Jun 22 17:01:56 2016 +0200

    Issue #2721727: Move the Display modes link from Structure to inside Field UI

diff --git a/core/modules/field_ui/src/Form/EntityDisplayFormBase.php b/core/modules/field_ui/src/Form/EntityDisplayFormBase.php
index cfa5c39..4cfa38f 100644
--- a/core/modules/field_ui/src/Form/EntityDisplayFormBase.php
+++ b/core/modules/field_ui/src/Form/EntityDisplayFormBase.php
@@ -11,7 +11,9 @@
 use Drupal\Core\Field\FieldTypePluginManagerInterface;
 use Drupal\Core\Field\PluginSettingsInterface;
 use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Link;
 use Drupal\Core\Routing\RouteMatchInterface;
+use Drupal\Core\Url;
 use Drupal\field_ui\Element\FieldUiTable;
 use Drupal\field_ui\FieldUI;
 
@@ -151,6 +153,41 @@ public function form(array $form, FormStateInterface $form_state) {
       return $form;
     }
 
+    // Custom display settings.
+    if ($this->entity->getMode() == 'default') {
+      // Only show the settings if there is at least one custom display mode.
+      $display_mode_options = $this->getDisplayModeOptions();
+      // Unset default option.
+      unset($display_mode_options['default']);
+      if ($display_mode_options) {
+        $form['modes'] = array(
+          '#type' => 'details',
+          '#title' => $this->t('Enable more display modes'),
+        );
+        // Prepare default values for the 'Custom display settings' checkboxes.
+        $default = array();
+        if ($enabled_displays = array_filter($this->getDisplayStatuses())) {
+          $default = array_keys(array_intersect_key($display_mode_options, $enabled_displays));
+        }
+        $form['modes']['display_modes_custom'] = array(
+          '#type' => 'checkboxes',
+          '#title' => $this->t('Use custom display settings for the following modes'),
+          '#options' => $display_mode_options,
+          '#default_value' => $default,
+        );
+        // Add a link to create a new display mode.
+        if ($this->entity->getEntityTypeId() == 'entity_form_display') {
+          $route_label = $this->t('Manage form modes');
+        }
+        else if ($this->entity->getEntityTypeId() == 'entity_view_display') {
+          $route_label = $this->t('Manage view modes');
+        }
+        $route_name = 'entity.entity_form_mode.collection';
+        $route_arguments = ['entity_type_id' => $this->entity->getTargetEntityTypeId()];
+        $form['modes']['add_new_display_mode'] = Link::createFromRoute($route_label, $route_name, $route_arguments)->toRenderable();
+      }
+    }
+
     $table = array(
       '#type' => 'field_ui_table',
       '#header' => $this->getTableHeader(),
@@ -187,31 +224,6 @@ public function form(array $form, FormStateInterface $form_state) {
 
     $form['fields'] = $table;
 
-    // Custom display settings.
-    if ($this->entity->getMode() == 'default') {
-      // Only show the settings if there is at least one custom display mode.
-      $display_mode_options = $this->getDisplayModeOptions();
-      // Unset default option.
-      unset($display_mode_options['default']);
-      if ($display_mode_options) {
-        $form['modes'] = array(
-          '#type' => 'details',
-          '#title' => $this->t('Custom display settings'),
-        );
-        // Prepare default values for the 'Custom display settings' checkboxes.
-        $default = array();
-        if ($enabled_displays = array_filter($this->getDisplayStatuses())) {
-          $default = array_keys(array_intersect_key($display_mode_options, $enabled_displays));
-        }
-        $form['modes']['display_modes_custom'] = array(
-          '#type' => 'checkboxes',
-          '#title' => $this->t('Use custom display settings for the following modes'),
-          '#options' => $display_mode_options,
-          '#default_value' => $default,
-        );
-      }
-    }
-
     // In overviews involving nested rows from contributed modules (i.e
     // field_group), the 'plugin type' selects can trigger a series of changes
     // in child rows. The #ajax behavior is therefore not attached directly to
