(This is the result of a discussion we had at DrupalCon Portland.)

Views' "disable field default class" option strips all markup and hence breaks in-place editing. Apparently this is a commonly used feature, and would thus make in-place editing within views appear very broken wherever it is used.

There is a solution to that: "lifting" of data- attributes to the "cell" (depending on the style plugin (format): <td>, <li> …). Then Edit will have sufficient metadata to still allow for for in-place editing as long as fields are not merged (in that case, lifting should only happen for the first field?).

Related issues

This issue blocks #1962606: Quick Edit + "Field" Views (table, grid …).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

xjm’s picture

Issue tags: +VDC
dawehner’s picture

oh.

damiankloip’s picture

@dawehner, you sound excited...

dawehner’s picture

Well, VDC wasn't in the tag list before comment #2

xjm’s picture

Title: "Lifting" of data- attributes from a field to its containing "view cell" wherever the "disable field default class" is enabled » "Lifting" of data- attributes from a field to its containing "view cell" ([quick]edit.module integration)
Priority: Normal » Major

This is kind of a big deal.

The title said:

wherever the "disable field default class" is enabled

Shouldn't we just do it always? Having it mysteriously flip on and off would be bad DX, I think.

dawehner’s picture

When "disable field default class" is not enabled, there is a field template file used instead, and based on that quickedit has everything which is needed already.

In general we have to think about the consequences for themers, because they currently really enjoy that views is producing the markup they have configured. An additional div will cause issues, for example with the inline functionality in views.

xjm’s picture

I don't think anyone said anything about adding another div? I'm confused. It's about putting the attribute on the <td>, <li>, etc.

dawehner’s picture

I was answering your suggestion:

Shouldn't we just do it always? Having it mysteriously flip on and off would be bad DX, I think.

PS: This post was certainly not sent from the university workspace

xjm’s picture

Hehe. Sorry, I meant always add the attribute when there is a semantic container element. So this:

<li data-edit-whatever="foo">My view field content</li>

And this:

<li data-edit-whatever="foo"><div class="views-default-stuff"><div><span>My view field content</span></div></div></li>

Not:

<li><div class="views-default-stuff" data-edit-whatever="foo"><div><span>My view field content</span></div></div></li>

If someone is using an unformatted list and not adding the default markup, they're probably on their own.

dawehner’s picture

Status: Active » Needs review
FileSize
4.58 KB
17.99 KB
16.08 KB

Made some progress on working this tonight.

dawehner’s picture

Beside from general feedback it would be cool if someone could have a look at the first hunk and suggest what should be the data which is added by default ...

diff --git a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php
index fdfea10..d35bef5 100644
--- a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php
+++ b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php
@@ -849,4 +849,13 @@ function field_langcode(EntityInterface $entity) {
     }
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  public function getCellAttributes($row_index = NULL) {
+    return array(
+      'data-edit-' . $this->field_info->getFieldName() => '@TODO',
+    );
+  }
+
dawehner’s picture

Review-bump ...

Wim Leers’s picture

FileSize
4.97 KB

Sorry for the delay.

For starters, here is a reroll.

Wim Leers’s picture

General patch perspective

As the issue indicates, the ideal would be that each view cell that contains a Field API Field automatically lifted any data- attributes added by hook_preprocess_field() implementations into the view cell's attributes.
If that can't happen, then modules like Edit need some way of 1) introspecting view cells' contents, 2) depending on those contents, set view cell attributes.

The current patch reviewed

The patch in #12 doesn't implement this automatic lifting of data- attributes. But how could it? After all, hook_preprocess_field() is not called at all — because this is "the Views render pipeline", not "the Entity/Field render pipeline".

So, consequently, the only way we could get the required attributes on each view cell, is by providing the ability to introspect each view cell's contents and then set attributes on the view cell. (In the case of Edit: essentially duplicate Edit's hook_preprocess_field() implementation to work with View cells.)
I tried to do this, and surely it is possible:

  public function getCellAttributes($row_index = NULL) {
    $field_name = $this->field_info->getFieldName();
    $entity = $this->view->result[$row_index]->_entity;
    $view_mode = 'views-' . $this->view->storage->id() . '-' . $this->view->current_display . '-' . $row_index;
    return array(
      'data-edit-id' => $entity->entityType() . '/' . $entity->id() . '/' . $field_name . '/' . $entity->language()->id . '/' . $view_mode,
    );
  }

Yay!

But this of course MAY NOT be hardcoded in Drupal\field\Plugin\views\field\Field. Modules should get the opportunity to apply logic such as that above. In other words: we need a hook.

Now, this is nigh identical to what I did for Edit module in #1962606-15: Quick Edit + "Field" Views (table, grid …) over 4 months ago: implement hook_preprocess_views_view_field(), where I calculated the data-edit-id attribute and set it:

+/**
+ * Implements hook_preprocess_views_view_fields().
+ */
+function edit_preprocess_views_view_field(&$variables) {
+  if (user_access('access in-place editing')) {
+
+    // Only annotate Field API View Fields.
+    if ($views_field instanceof Field) {
+      // Entity/Field metadata.
+      $entity = $variables['row']->_entity;
+      $field_name = $views_field->field_info->id;
+      $langcode = $views_field->field_info->langcode;
+
+      // Views metadata.
+      $view_name = $variables['view']->storage->id;
+      $view_display = $variables['view']->current_display;
+      $view_row = $variables['view']->row_index;
+
+      // Build edit ID; the view mode is now a hybrid that contains the
+      // necessary metadata for Views.
+      $edit_id = $entity->entityType() . '/' . $entity->id() . '/' . $field_name . '/' . $langcode . "/views-$view_name-$view_display-$view_row";
+
+      // @todo Push the rendering of the data-edit-id attribute deeper into the
+      // Views rendering pipeline instead of wrapping content in <span> tags.
+      $variables['output'] = '<span data-edit-id="' . $edit_id . '">' . $variables['output'] . '</span>';
+    }
+  }
+}

The only difference is that I now need to be able to set this "view cell attribute". The code back then did not yet have the ability to set the attribute, the patch in this issue does not yet have the ability to let other modules run it. But is it really worthwhile to fire another hook? Wouldn't it be simpler to just use hook_preprocess_views_view_fields(), but allow $variables['attributes'] to be set?
I don't know the Views architecture well enough to answer that.

To move forward

We have two options:

  1. Allow modules to alter getCellAttributes() via a hook.
  2. Allow hook_preprocess_views_view_field() to set $variables['attributes'].

Once we have either, in-place editing of Views will become as feasible as it ever will be.

Wim Leers’s picture

A sister issue to enable in-place editing of Views in D8 contrib on the Edit side of things: #2083387: Make it possible to use in-place editing on entities rendered by a custom render pipeline (e.g. Views).

dawehner’s picture

As the issue indicates, the ideal would be that each view cell that contains a Field API Field automatically lifted any data- attributes added by hook_preprocess_field() implementations into the view cell's attributes.
If that can't happen, then modules like Edit need some way of 1) introspecting view cells' contents, 2) depending on those contents, set view cell attributes.

Well, sure, we could somehow call the preprocess functions manually to get this information out. I don't think this will be a problem in terms of performance though we might should be somehow able to disable that behavior. (A config option without any UI could work)

The patch in #12 doesn't implement this automatic lifting of data- attributes. But how could it? After all, hook_preprocess_field() is not called at all — because this is "the Views render pipeline", not "the Entity/Field render pipeline".

So yeah my idea was that a generic fieldapi field could set enough information so that edit (and other modules) can deal with it and don't need anything more. It seemed for me that entity-type entity-id field-name combination and maybe field-instance-id etc. would be enough and you don't need anything more. (no hook / other preprocess). From your comments this sadly doesn't seem to be the case. It would be great
to get some feedback whether you need a specific combination so that a generic solution can't work.

The only difference is that I now need to be able to set this "view cell attribute". The code back then did not yet have the ability to set the attribute, the patch in this issue does not yet have the ability to let other modules run it. But is it really worthwhile to fire another hook? Wouldn't it be simpler to just use hook_preprocess_views_view_fields(), but allow $variables['attributes'] to be set?

From an API point of view css classes are part of the render api of views, so bypassing that in preprocess functions feels wrong. We do already have functions for particular elements, so that I went with the concept of cell classes/attributes. As properties aren't fieldapi fields I am wondering how we can also support them with a generic data pattern.

Luckily there are just two data points available yet, so the next review-break could also last just a short time.

Wim Leers’s picture

So yeah my idea was that a generic fieldapi field could set enough information so that edit (and other modules) can deal with it and don't need anything more. It seemed for me that entity-type entity-id field-name combination and maybe field-instance-id etc. would be enough and you don't need anything more.

That should indeed be sufficient metadata, as long as you also include view mode and langcode.

(no hook / other preprocess). From your comments this sadly doesn't seem to be the case. It would be great
to get some feedback whether you need a specific combination so that a generic solution can't work.

That's not what I said. What I said was that Views' code can't hardcode setting the data-edit-id attribute for Edit module. Hence Edit module needs some way — a hook, a callback, something — to take that metadata you mentioned earlier (see the above quote) and then turn it into the attribute that is desired.

So I think you might have misinterpreted my comment? (Or my comment just might be not sufficiently clear, of course.)

dawehner’s picture

Yeah I though a generic attribute would be enough while you think that the metadata itself are needed in order to provide a specific data attribute.

I am fine with introducing a hook. Maybe we should add this hook once for each results.

Wim Leers’s picture

Issue tags: -sprint

Still tracking this, but since we can't push this forward, not really part of the Spark sprint. The edit.module-side of this problem is part of this sprint because it's not blocked (by this or any other issue), we're working on that in #2083387: Make it possible to use in-place editing on entities rendered by a custom render pipeline (e.g. Views).

Wim Leers’s picture

Booooo, d.o tag monster!

Wim Leers’s picture

Third time's a charm!

(I hope.)

Wim Leers’s picture

Issue summary: View changes

Updated issue summary.

Wim Leers’s picture

Just FYI: the necessary API changes to make in-place editing of Views possible in Edit have landed in #2083387: Make it possible to use in-place editing on entities rendered by a custom render pipeline (e.g. Views). The only remaining blocker are the necessary API changes in Views, i.e.: this issue.

xjm’s picture

13: vdc-2010946-13.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 13: vdc-2010946-13.patch, failed testing.

Renee S’s picture

Version: 8.0.x-dev » 8.1.x-dev
Issue summary: View changes

All the other related issues have been bumped to 8.1, so, moving this up also...

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs work » Closed (outdated)

Brought this up in #yes-no-queue and agreed with @larowlan this can probably be closed out with inactivity.

If still a valid feature request please reopen updating issue summary for how it pertains to D10

Thanks!