Problem/Motivation

Inaccurate documentation for 8.2.x

API page: https://api.drupal.org/api/drupal/core%21modules%21views%21views.api.php...

> The field module's implementation of hook_views_data() invokes this for each field storage, in the module that defines the field type. It is not invoked in other modules.

Field module no longer implements this hook in D8. Views invokes this in views_views_data().

Proposed resolution

Update documentation to reflect that Field module no longer implements this hook in D8.

Remaining tasks

Update documentation

User interface changes

-

API changes

-

Data model changes

-

Comments

joachim created an issue. See original summary.

kellyimagined’s picture

Issue summary: View changes
kellyimagined’s picture

Working on a solution for this issue.

kellyimagined’s picture

StatusFileSize
new808 bytes

Updated documentation.

kellyimagined’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 4: views-api-4.diff, failed testing.

dagmar’s picture

@kellyimagined you are creating the patch in some wrong way. Try with this:

cd your-drupal-folder
git diff > hook-field-views-data-2730227-8.patch
kellyimagined’s picture

StatusFileSize
new704 bytes

@dagmar,
Thank you for the feedback, please let me know if this works.

kellyimagined’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 8: hook-field-views-data-2730227-8.patch, failed testing.

kellyimagined’s picture

StatusFileSize
new810 bytes

@dagmar,
I must have a love for punishment. Maybe you can tell me why it is failing?

kellyimagined’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 11: hook-field-views-data-2730227-11.patch, failed testing.

kellyimagined’s picture

Status: Needs work » Needs review
StatusFileSize
new740 bytes

Updated according to docs and removed white space according to fail.

mile23’s picture

Issue tags: +Documentation
jhodgdon’s picture

Status: Needs review » Needs work
Issue tags: -Documentation

Good catch, and thanks for the patches!

However, the latest one still needs some work:

+++ b/core/modules/views/views.api.php
@@ -503,9 +503,8 @@ function hook_views_data_alter(array &$data) {
+ * The views invoke hook_views_data() in views_views_data(). The field module
+ * no longer implements this hook in D8.

The first sentence is not grammatical, and it doesn't make sense to me.

Also, we don't want to document history in the API docs. So remove the part about "no longer". Just document what is currently true.

Also, incidentally, please don't use the 'documentation' tag in Drupal Core. See https://www.drupal.org/node/1208166 .

snehi’s picture

Status: Needs work » Needs review
StatusFileSize
new657 bytes
new595 bytes

Modified.

jhodgdon’s picture

Status: Needs review » Needs work
+++ b/core/modules/views/views.api.php
@@ -503,9 +503,7 @@ function hook_views_data_alter(array &$data) {
+ * Implements the hook_views_data().

No, this is not accurate either. This is not a hook implementation at all, it's documentation for a hook.

I think what we need to do is to replace this text:

The field module's implementation of hook_views_data() invokes this for each field storage, in the module that defines the field type. It is not invoked in other modules.

If no hook implementation exists, hook_views_data() falls back to views_field_default_views_data().

with something like this:

When collecting the views data, views_views_data() invokes this hook for each field storage definition, on the module that provides the field storage definition. If the return value is empty, the result of views_field_default_views_data() is used instead. Then the result is altered by invoking hook_field_views_data_alter() on all modules.

jhodgdon’s picture

It also seems that hook_field_views_data_views_data_alter() is no longer invoked. And the documentation for hook_field_views_data_alter() needs a similar fix to this issue. I think we should combine all of that into one issue/patch?

jhodgdon’s picture

Issue tags: +VDC
kellyimagined’s picture

Status: Needs work » Needs review
StatusFileSize
new1.91 KB

@jhodgdon, is this what you are requesting?

jhodgdon’s picture

Status: Needs review » Needs work

Close, thanks!

A few things to address:

  1. +++ b/core/modules/views/views.api.php
    @@ -503,12 +503,10 @@ function hook_views_data_alter(array &$data) {
    + * When collecting the views data, views_views_data() invokes this hook for each field
    + * storage definition, on the module that provides the field storage definition. If the return
    + * value is empty, the result of views_field_default_views_data() is used instead. Then the
    + * result is altered by invoking hook_field_views_data_alter() on all modules.
    

    This section needs to be rewrapped. We want all documentation lines to be less than 80 characters.

  2. +++ b/core/modules/views/views.api.php
    @@ -587,9 +585,10 @@ function hook_field_views_data_alter(array &$data, \Drupal\field\FieldStorageCon
      * Alter the Views data on a per field basis.
      *
    - * The field module's implementation of hook_views_data_alter() invokes this for
    - * each field storage, in the module that defines the field type. It is not
    - * invoked in other modules.
    + * When collecting the views data, views_views_data() invokes this hook for each field
    + * storage definition, on the module that provides the field storage definition. If the return
    + * value is empty, the result of views_field_default_views_data() is used instead. Then the
    + * result is altered by invoking hook_field_views_data_alter() on all modules.
      *
      * Unlike hook_field_views_data_alter(), this operates on the whole of the views
      * data. This allows a field type to add data that concerns its fields in
    

    I think this is the docs header for hook_field_views_data_views_data_alter()... I had thought that this hook should be removed, but I was wrong about that. It does need an update though, but exactly not this update. What it needs to say instead is that it is invoked on the module that provides the field storage definition, and that it is invoked from views_views_data_alter().

  3. Then we also need an update to the documentation on hook_field_views_data_alter(), similar to what is in this patch.
Sonal.Sangale’s picture

Assigned: Unassigned » Sonal.Sangale
Sonal.Sangale’s picture

Hi jhodgdon,

Can you please elaborate second point of suggestion as it is little confusing ?

jhodgdon’s picture

Sure, and sorry!

OK. Ignore comment #22. Here is hopefully some clearer information.

So we have 3 hooks:

a) hook_field_views_data() -- this hook documentation header needs the fix in the #21 patch (but all documentation needs to be wrapped to 80 character lines).

b) hook_field_views_data_alter() -- needs a fix similar to hook_field_views_data() -- but not exactly, because the text says "this hook" (referring to hook_field_views_data() in that text) -- so it needs a small edit so it is relevant to hook_field_views_data_alter() instead of hook_field_views_data(). Note that the patch in #21, by mistake, put the fix in the wrong this documentation header (see (c) below).

c) hook_field_views_data_views_data_alter() -- This hook documentation was mistakenly changed in the last patch. It does need a change, but the text that was put in there was for the wrong hook. What it needs instead is some text saying that it is that it is invoked from views_views_data_alter(), and only invoked on the module that provides the field storage definition.

Thanks! Hope this is clearer.

Sonal.Sangale’s picture

Status: Needs work » Needs review
StatusFileSize
new1.92 KB
new2.15 KB

Given it a try!

Please review.

jhodgdon’s picture

Status: Needs review » Needs work

Thanks for trying, but this isn't quite right.

Looking at #25...
a) Looks good.

b) This wasn't done at all.

c)

+++ b/core/modules/views/views.api.php
@@ -587,9 +586,11 @@ function hook_field_views_data_alter(array &$data, \Drupal\field\FieldStorageCon
+ * storage definition. If the return value is empty, the result of
+ * views_field_default_views_data() is used instead. Then the result is altered
+ * by invoking hook_field_views_data_alter() on all modules.

This part about the return value doesn't apply to this hook.

Sonal.Sangale’s picture

Assigned: Sonal.Sangale » Unassigned
mohit_aghera’s picture

Assigned: Unassigned » mohit_aghera
Status: Needs work » Needs review
StatusFileSize
new1.76 KB
new1.73 KB

@jhodgdon
Updated patch as per your suggestion.
Removed c point changes from patch (https://www.drupal.org/node/2730227#comment-11225311) .
Fix other comment.

mparker17’s picture

Assigned: mohit_aghera » Unassigned

Unassigned as @mohit_aghera has already uploaded a patch for review, and he can't review his own patch :) Also, I'm hoping that someone will be able to review this at the Drupal North 2016 coding sprint tomorrow.

wolffereast’s picture

Status: Needs review » Needs work
Issue tags: +DrupalNorth2016

Points a and b look alright, but we are still missing point c in it's entirety.

swarad07’s picture

Status: Needs work » Needs review
StatusFileSize
new658 bytes
new2.33 KB

As suggested by jhodgdon in #25, made changes to docs of hook_field_views_data_views_data_alter().

swarad07’s picture

Status: Needs review » Needs work
+++ b/core/modules/views/views.api.php
@@ -590,6 +588,9 @@ function hook_field_views_data_alter(array &$data, \Drupal\field\FieldStorageCon
+ * ¶
+ * Views implmentation of hook_views_data_alter() invokes this on the module ¶
+ * that provides the field storage definition.

Some empty spaces seem to have crept in.

swarad07’s picture

StatusFileSize
new2.31 KB

Removing empty spaces.

swarad07’s picture

Status: Needs work » Needs review
StatusFileSize
new2.31 KB

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.

zeip’s picture

StatusFileSize
new2.31 KB
new692 bytes

Fixed a typo.

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.

impalash’s picture

StatusFileSize
new2.91 KB

@jhodgdon fixed for 8.6.x please review.

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.

joachim’s picture

Status: Needs review » Needs work
+++ b/core/modules/views/views.api.php
@@ -587,12 +585,15 @@ function hook_field_views_data_alter(array &$data, \Drupal\field\FieldStorageCon
+ * The field module's implementation of hook_views_data_alter() invokes this

I don't think this implementation exists any more.

So it's possible this hook no longer exists either!

I would say the changes to this hook are out of scope for this issue. The rest of the patch looks fine.

So next steps:

- reroll the patch minus the changes to hook_field_views_data_views_data_alter()
- file a new issue about hook_field_views_data_views_data_alter()

izus’s picture

Status: Needs work » Needs review
StatusFileSize
new2.03 KB
new1.07 KB

Hi,

- here is a reroll minus hook_field_views_data_views_data_alter() as suggested in #43
- the new issue about hook_field_views_data_views_data_alter() : https://www.drupal.org/project/drupal/issues/2999325

Thanks

joachim’s picture

Status: Needs review » Needs work

Latest patch doesn't seem right -- we've lost the first hunk, at line 505, which is the one we mostly need.

joachim’s picture

> - file a new issue about hook_field_views_data_views_data_alter()

On second thoughts, let's keep it here.

hook_field_views_data_views_data_alter() *does* still exist. Some core modules implement it. The docs are wrong in the same way as for hook_field_views_data():

 * The field module's implementation of hook_views_data_alter() invokes this for
 * each field storage, in the module that defines the field type. It is not
 * invoked in other modules.

That paragraph is wrong. The code that invokes this is now in Views:

  foreach ($entity_manager->getStorage('field_storage_config')->loadMultiple() as $field_storage) {
    if (_views_field_get_entity_type_storage($field_storage)) {
      $function = $field_storage->getTypeProvider() . '_field_views_data_views_data_alter';
      if (function_exists($function)) {
izus’s picture

Status: Needs work » Needs review
StatusFileSize
new2.77 KB
new974 bytes

Hi,
Thanks for the review
here is another try :)

joachim’s picture

Status: Needs review » Needs work

Nearly there I think!

  1. +++ b/core/modules/views/views.api.php
    @@ -503,12 +503,11 @@ function hook_views_data_alter(array &$data) {
    + * When collecting the views data, views_views_data() invokes this hook for each
    
    @@ -587,12 +585,11 @@ function hook_field_views_data_alter(array &$data, \Drupal\field\FieldStorageCon
    + * The Views module's implementation of hook_views_data_alter() invokes this on
    

    I'd like it if we were consistent here -- either just say the name of the function, or say "The Views module's implementation of hook_NAME() invokes...".

    Or combine both for clarity:

    "The Views module's implementation of hook_NAME(), views_NAME(), invokes ... ".

  2. +++ b/core/modules/views/views.api.php
    @@ -539,10 +538,9 @@ function hook_field_views_data(\Drupal\field\FieldStorageConfigInterface $field_
      *
    - * This is called on all modules even if there is no hook_field_views_data()
    - * implementation for the field, and therefore may be used to alter the
    - * default data that views_field_default_views_data() supplies for the
    - * field storage.
    + * When collecting the views data, views_views_data() invokes
    + * hook_field_views_data_alter() for each field storage definition, on the
    + * module that provides the field storage definition.
      *
    

    This change should be removed.

    The original text is correct.

izus’s picture

Status: Needs work » Needs review
StatusFileSize
new2.04 KB
new1.43 KB

Here it is :)

joachim’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/views/views.api.php
    @@ -503,12 +503,11 @@ function hook_views_data_alter(array &$data) {
    + * field storage definition, on the module that provides the field storage
    

    We've lost the 'It is not invoked in other modules' sentence, and the paragraph break.

  2. +++ b/core/modules/views/views.api.php
    @@ -587,12 +586,11 @@ function hook_field_views_data_alter(array &$data, \Drupal\field\FieldStorageCon
    - * The field module's implementation of hook_views_data_alter() invokes this for
    - * each field storage, in the module that defines the field type. It is not
    - * invoked in other modules.
    + * views_views_data_alter() invokes this on the module that provides the field
    + * storage definition.
    

    We've lost lots of the text here.

  3. +++ b/core/modules/views/views.api.php
    @@ -587,12 +586,11 @@ function hook_field_views_data_alter(array &$data, \Drupal\field\FieldStorageCon
    - * Unlike hook_field_views_data_alter(), this operates on the whole of the views
    - * data. This allows a field type to add data that concerns its fields in
    + * Unlike hook_field_views_data_alter(), this operates on the whole of the
    + * views data. This allows a field type to add data that concerns its fields in
    

    This change is just changing wrapping.

izus’s picture

Status: Needs work » Needs review
StatusFileSize
new1.59 KB
new1.39 KB

Hi,
thanks for the review :)
Here it is

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.

quietone’s picture

Patch applies to 9.4.x. The text changes look fine to me but I'll ask in #bugsmash for a second opinion.

lendude’s picture

Status: Needs review » Reviewed & tested by the community

Gave it a detailed read and checked the logic to make sure it still matches what happens in views_views_data() and views_views_data_alter() and it does, so this looks good to me.

quietone’s picture

StatusFileSize
new1.39 KB

Re-uploading the patch so it tests with 9.4.x

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 60: inaccurate_docs_for-2730227-51.patch, failed testing. View results

longwave’s picture

Status: Needs work » Reviewed & tested by the community

Random fail.

alexpott’s picture

Version: 9.4.x-dev » 9.3.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed 9b9dc205ec to 10.0.x and be38b68647 to 9.4.x and 6e7d1e6e21 to 9.3.x. Thanks!

  • alexpott committed 9b9dc20 on 10.0.x
    Issue #2730227 by kellyimagined, izus, swarad07, Sonal.Sangale, snehi,...

  • alexpott committed be38b68 on 9.4.x
    Issue #2730227 by kellyimagined, izus, swarad07, Sonal.Sangale, snehi,...

  • alexpott committed 6e7d1e6 on 9.3.x
    Issue #2730227 by kellyimagined, izus, swarad07, Sonal.Sangale, snehi,...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.