Comments

tim.plunkett created an issue. See original summary.

tim.plunkett’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new7.59 KB
new199.19 KB

I've never worked on a patch with four uncommitted dependencies before!

tim.plunkett’s picture

Added a custom form that simplifies the Field UI.

tim.plunkett’s picture

Issue summary: View changes
StatusFileSize
new672 bytes
new209.22 KB

\Drupal\outside_in\OutsideInManager::isApplicable() is way too specific to a single use-case. Skipping it for this new stuff so far.

tim.plunkett’s picture

Here's the last patch without all the other dependencies.

tedbow’s picture

@tim.plunkett tried out the patch and I love the effect!!!!!

Couple thoughts,

1. Do we want all forms that trigger the Settings Tray "Edit mode" to live in the Settings tray module. Or would it make sense to have things like outside_in_entity_view_alter to be field_layout_in_entity_view_alter. Then other modules could define their own links/forms that should trigger "edit mode".

2. If we did #1 then maybe field_layout could be an example for how contrib could designate links to trigger edit mode.

3. Looking at the patch it points out that now that every module creates a contextual link that uses the offcanvas try that link will also trigger edit module b/c in outside_in.js

var blockConfigureSelector = '[data-dialog-renderer="offcanvas"]';
.......
// Bind a listener to all 'Quick edit' links for blocks
    // Click "Edit" button in toolbar to force Contextual Edit which starts
    // Settings Tray edit mode also.
    data.$el.find(blockConfigureSelector)
      .on('click.outsidein', function () {
        if (!isInEditMode()) {
          $(toggleEditSelector).trigger('click.outsidein');
        }
      });

Do we want that?

tim.plunkett’s picture

Not posting any more patches right now because it's rather pointless, but this would move the above code into field_layout.

diff --git a/core/modules/field_layout/field_layout.links.contextual.yml b/core/modules/field_layout/field_layout.links.contextual.yml
new file mode 100644
index 0000000..1f2f4ac
--- /dev/null
+++ b/core/modules/field_layout/field_layout.links.contextual.yml
@@ -0,0 +1,6 @@
+field_layout.entity_view.edit_layout:
+  title: 'Edit layout'
+  deriver: \Drupal\field_layout\Plugin\Derivative\EntityViewOffcanvasContextualLinks
+  options:
+    dialog-type: dialog
+    dialog-renderer: offcanvas
diff --git a/core/modules/field_layout/field_layout.module b/core/modules/field_layout/field_layout.module
index 1a4806a..56e4c26 100644
--- a/core/modules/field_layout/field_layout.module
+++ b/core/modules/field_layout/field_layout.module
@@ -14,6 +14,7 @@
 use Drupal\field_layout\Entity\FieldLayoutEntityFormDisplay;
 use Drupal\field_layout\Entity\FieldLayoutEntityViewDisplay;
 use Drupal\field_layout\FieldLayoutBuilder;
+use Drupal\field_layout\Form\EntityViewDisplayEditOffcanvasForm;
 use Drupal\field_layout\Form\FieldLayoutEntityFormDisplayEditForm;
 use Drupal\field_layout\Form\FieldLayoutEntityViewDisplayEditForm;
 
@@ -41,6 +42,7 @@ function field_layout_entity_type_alter(array &$entity_types) {
   // The form classes are only needed when Field UI is installed.
   if (\Drupal::moduleHandler()->moduleExists('field_ui')) {
     $entity_types['entity_view_display']->setFormClass('edit', FieldLayoutEntityViewDisplayEditForm::class);
+    $entity_types['entity_view_display']->setFormClass('offcanvas', EntityViewDisplayEditOffcanvasForm::class);
     $entity_types['entity_form_display']->setFormClass('edit', FieldLayoutEntityFormDisplayEditForm::class);
   }
 }
@@ -53,6 +55,21 @@ function field_layout_entity_view_alter(array &$build, EntityInterface $entity,
     \Drupal::classResolver()->getInstanceFromDefinition(FieldLayoutBuilder::class)
       ->build($build, $display, 'view');
   }
+
+  $entity_type = $entity->getEntityType();
+  if ($entity_type->get('field_ui_base_route')) {
+    $bundle_entity_type = $entity_type->getBundleEntityType();
+    $key = $bundle_entity_type ?: $entity_type->id();
+
+    $build['#contextual_links'][$key]['route_parameters']['view_mode_name'] = $display->getMode();
+    if ($bundle_entity_type) {
+      $build['#contextual_links'][$key]['route_parameters'][$bundle_entity_type] = $entity->bundle();
+    }
+
+    // Add class and attributes to allow Javascript to target.
+    $build['#attributes']['class'][] = 'outside-in-editable';
+    $build['#attributes']['data-drupal-outsidein'] = 'editable';
+  }
 }
 
 /**
diff --git a/core/modules/field_layout/field_layout.services.yml b/core/modules/field_layout/field_layout.services.yml
new file mode 100644
index 0000000..71f5316
--- /dev/null
+++ b/core/modules/field_layout/field_layout.services.yml
@@ -0,0 +1,6 @@
+services:
+  field_layout.entity_view.route_subscriber:
+    class: Drupal\field_layout\Routing\EntityViewOffcanvasRouteSubscriber
+    arguments: ['@entity_type.manager']
+    tags:
+     - { name: event_subscriber }
diff --git a/core/modules/outside_in/src/Form/FieldLayoutEntityViewDisplayEditForm.php b/core/modules/field_layout/src/Form/EntityViewDisplayEditOffcanvasForm.php
similarity index 86%
rename from core/modules/outside_in/src/Form/FieldLayoutEntityViewDisplayEditForm.php
rename to core/modules/field_layout/src/Form/EntityViewDisplayEditOffcanvasForm.php
index 5860376..0d3183c 100644
--- a/core/modules/outside_in/src/Form/FieldLayoutEntityViewDisplayEditForm.php
+++ b/core/modules/field_layout/src/Form/EntityViewDisplayEditOffcanvasForm.php
@@ -1,14 +1,13 @@
 <?php
 
-namespace Drupal\outside_in\Form;
+namespace Drupal\field_layout\Form;
 
 use Drupal\Core\Form\FormStateInterface;
-use Drupal\field_layout\Form\FieldLayoutEntityViewDisplayEditForm as FieldLayoutEntityViewDisplayEditFormBase;
 
 /**
  * The off-canvas form handler for the EntityViewDisplay edit form.
  */
-class FieldLayoutEntityViewDisplayEditForm extends FieldLayoutEntityViewDisplayEditFormBase {
+class EntityViewDisplayEditOffcanvasForm extends FieldLayoutEntityViewDisplayEditForm {
 
   /**
    * {@inheritdoc}
diff --git a/core/modules/outside_in/src/Plugin/Derivative/OutsideInContextualLinks.php b/core/modules/field_layout/src/Plugin/Derivative/EntityViewOffcanvasContextualLinks.php
similarity index 87%
rename from core/modules/outside_in/src/Plugin/Derivative/OutsideInContextualLinks.php
rename to core/modules/field_layout/src/Plugin/Derivative/EntityViewOffcanvasContextualLinks.php
index 9b65c98..0509c94 100644
--- a/core/modules/outside_in/src/Plugin/Derivative/OutsideInContextualLinks.php
+++ b/core/modules/field_layout/src/Plugin/Derivative/EntityViewOffcanvasContextualLinks.php
@@ -1,6 +1,6 @@
 <?php
 
-namespace Drupal\outside_in\Plugin\Derivative;
+namespace Drupal\field_layout\Plugin\Derivative;
 
 use Drupal\Component\Plugin\Derivative\DeriverBase;
 use Drupal\Core\Entity\EntityTypeManagerInterface;
@@ -10,7 +10,7 @@
 /**
  * @todo.
  */
-class OutsideInContextualLinks extends DeriverBase implements ContainerDeriverInterface {
+class EntityViewOffcanvasContextualLinks extends DeriverBase implements ContainerDeriverInterface {
 
   /**
    * @var \Drupal\Core\Entity\EntityTypeManagerInterface
@@ -18,7 +18,7 @@ class OutsideInContextualLinks extends DeriverBase implements ContainerDeriverIn
   protected $entityTypeManager;
 
   /**
-   * OutsideInContextualLinks constructor.
+   * EntityViewOffcanvasContextualLinks constructor.
    *
    * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
    */
diff --git a/core/modules/outside_in/src/Routing/OutsideInRouteSubscriber.php b/core/modules/field_layout/src/Routing/EntityViewOffcanvasRouteSubscriber.php
similarity index 93%
rename from core/modules/outside_in/src/Routing/OutsideInRouteSubscriber.php
rename to core/modules/field_layout/src/Routing/EntityViewOffcanvasRouteSubscriber.php
index dd66113..3687ae3 100644
--- a/core/modules/outside_in/src/Routing/OutsideInRouteSubscriber.php
+++ b/core/modules/field_layout/src/Routing/EntityViewOffcanvasRouteSubscriber.php
@@ -1,6 +1,6 @@
 <?php
 
-namespace Drupal\outside_in\Routing;
+namespace Drupal\field_layout\Routing;
 
 use Drupal\Core\Entity\EntityTypeManagerInterface;
 use Drupal\Core\Routing\RouteSubscriberBase;
@@ -11,7 +11,7 @@
 /**
  * @todo.
  */
-class OutsideInRouteSubscriber extends RouteSubscriberBase {
+class EntityViewOffcanvasRouteSubscriber extends RouteSubscriberBase {
 
   /**
    * The entity manager service.
diff --git a/core/modules/outside_in/outside_in.links.contextual.yml b/core/modules/outside_in/outside_in.links.contextual.yml
index ad8f918..62ca999 100644
--- a/core/modules/outside_in/outside_in.links.contextual.yml
+++ b/core/modules/outside_in/outside_in.links.contextual.yml
@@ -5,10 +5,3 @@ outside_in.block_configure:
   options:
     dialog-type: dialog
     dialog-renderer: offcanvas
-
-outside_in.field_layout:
-  title: 'Edit layout'
-  deriver: \Drupal\outside_in\Plugin\Derivative\OutsideInContextualLinks
-  options:
-    dialog-type: dialog
-    dialog-renderer: offcanvas
diff --git a/core/modules/outside_in/outside_in.module b/core/modules/outside_in/outside_in.module
index a04c4e0..051f9db 100644
--- a/core/modules/outside_in/outside_in.module
+++ b/core/modules/outside_in/outside_in.module
@@ -7,11 +7,8 @@
 
 use Drupal\Component\Utility\Html;
 use Drupal\Core\Asset\AttachedAssetsInterface;
-use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
-use Drupal\Core\Entity\EntityInterface;
 use Drupal\Core\Routing\RouteMatchInterface;
 use Drupal\outside_in\Block\BlockEntityOffCanvasForm;
-use Drupal\outside_in\Form\FieldLayoutEntityViewDisplayEditForm;
 use Drupal\outside_in\Form\SystemBrandingOffCanvasForm;
 use Drupal\outside_in\Form\SystemMenuOffCanvasForm;
 
@@ -60,40 +57,6 @@ function outside_in_contextual_links_view_alter(&$element, $items) {
 }
 
 /**
- * Implements hook_contextual_links_plugins_alter().
- */
-function outside_in_contextual_links_plugins_alter(array &$contextual_links) {
-  // Remove all contextual links that depend on field_layout and field_ui.
-  if (!(\Drupal::moduleHandler()->moduleExists('field_layout') && \Drupal::moduleHandler()->moduleExists('field_ui'))) {
-    foreach (array_keys($contextual_links) as $id) {
-      if (strpos($id, 'outside_in.field_layout:') === 0) {
-        unset($contextual_links[$id]);
-      }
-    }
-  }
-}
-
-/**
- * Implements hook_entity_view_alter().
- */
-function outside_in_entity_view_alter(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display) {
-  $entity_type = $entity->getEntityType();
-  if ($entity_type->get('field_ui_base_route')) {
-    $bundle_entity_type = $entity_type->getBundleEntityType();
-    $key = $bundle_entity_type ?: $entity_type->id();
-
-    $build['#contextual_links'][$key]['route_parameters']['view_mode_name'] = $display->getMode();
-    if ($bundle_entity_type) {
-      $build['#contextual_links'][$key]['route_parameters'][$bundle_entity_type] = $entity->bundle();
-    }
-
-    // Add class and attributes to allow Javascript to target.
-    $build['#attributes']['class'][] = 'outside-in-editable';
-    $build['#attributes']['data-drupal-outsidein'] = 'editable';
-  }
-}
-
-/**
  * Implements hook_block_view_alter().
  */
 function outside_in_block_view_alter(array &$build) {
@@ -133,9 +96,6 @@ function outside_in_entity_type_build(array &$entity_types) {
   $entity_types['block']
     ->setFormClass('offcanvas', BlockEntityOffCanvasForm::class)
     ->setLinkTemplate('offcanvas-form', '/admin/structure/block/manage/{block}/offcanvas');
-  if (\Drupal::moduleHandler()->moduleExists('field_layout') && \Drupal::moduleHandler()->moduleExists('field_ui')) {
-    $entity_types['entity_view_display']->setFormClass('offcanvas', FieldLayoutEntityViewDisplayEditForm::class);
-  }
 }
 
 /**
diff --git a/core/modules/outside_in/outside_in.services.yml b/core/modules/outside_in/outside_in.services.yml
index 3add22f..48f5824 100644
--- a/core/modules/outside_in/outside_in.services.yml
+++ b/core/modules/outside_in/outside_in.services.yml
@@ -14,9 +14,3 @@ services:
     arguments: ['@outside_in.manager']
     tags:
       - { name: cache.context}
-
-  outside_in.route_subscriber:
-    class: Drupal\outside_in\Routing\OutsideInRouteSubscriber
-    arguments: ['@entity_type.manager']
-    tags:
-     - { name: event_subscriber }
tim.plunkett’s picture

Status: Needs review » Closed (won't fix)

The UX team (and I) think that this functionality is confusing and pretty useless without per-entity overrides.