Problem/Motivation
While working on #2005166: Create simple file listing under admin/content/file we had to move _views_file_status() from file.views.inc to file.module due to loading problems.
Proposed resolution
Deprecate the function _views_file_status().
Remaining tasks
TBD
User interface changes
N/A
API changes
The function _views_file_status() has been deprecated.
| Comment | File | Size | Author |
|---|---|---|---|
| #41 | interdiff_39-41.txt | 576 bytes | srilakshmier |
| #41 | 2032893-41.patch | 2.54 KB | srilakshmier |
Comments
Comment #1
dawehneradding tags.
Comment #2
Thomas Brekelmans commentedI'm taking this one on :)
Comment #3
Thomas Brekelmans commentedI did a search on where _views_file_status() was used and found it's only used in 2 places: in Drupal\file\Plugin\views\filter\Status getValueOptions() and in Drupal\file\Plugin\views\field\Status render().
Both used the function in a different way and expected different results from the function: the filter wants a value options map of possible status values and their corresponding labels, to display in the UI; the field wants to display the appropriate label for the given status value, or a default label if the value can't be matched.
I've inlined this functionality on both places and simplified/clarified the code implementation a little bit.
Inlining the code obviously solves any (auto)loading problems so if nobody is opposed to it, I think this fixes the original problem?
Comment #4
tstoecklerWe never use private in Drupal, this should be protected.
For extra credit you could also add a "public" on the function that is in the patch context above. Not strictly part of this, though.
Comment #5
dawehnerHere $value should be always set, as it is not optional
Comment #6
damiankloip commentedThis should be protected, we generally don't make any methods private.
We need to make this a class constant instead, then we can unit test this stuff easier.
I wonder if there is somewhere central we can get this from? If we could remove the duplication that would be great.
Comment #7
damiankloip commentedSorry, xposted! This issue has got busy all of a sudden ;)
Comment #8
Thomas Brekelmans commentedI've incorporated the feedback from #4, #5 and #6 and went a little further ahead to allow for more reuse: I created a very small (centralised) FileStatusMap utility class that has the functionality I inlined in the previous patch (and before that was _views_file_status()).
I've also added a UnitTestCase implementation for testing this little new class.
The trick for using/re-defining the t() function in the test comes from \Drupal\views_ui\Tests\ViewListControllerTest.
I was unsure about the FILE_STATUS_PERMANENT const from core/includes/file.inc, I opted to mirror it inside the new class (FileStatusMap) for testability/encapsulation since those include files don't really exist in the OO space anywhere.
But introducing duplicate code like this is also not ideal so ... what do you think?
Comment #10
Thomas Brekelmans commented:( I accidentally uploaded that interdiff with a .patch instead of a .txt extension ... I can't edit it anymore ... if it makes the original patch fail I'll just repost everything correctly.
Comment #11
dawehnerIf you replace something with a constant somewhere else I think all the usages should be replaced as well. Maybe skip this in that patch for now and open a new issue for just that.
Comment #12
Thomas Brekelmans commentedI fixed the missing constant reference that made the test fail (that was referencing the original constant in core/modules/file.inc, which still exists, I just mirrored it as a class const so that class is standalone and could be tested in isolation)
I've added interdiffs as well so you can see this last change just changes the constant.
Comment #13
dawehnerI am sorry but I think we should move the existing usages and not just introduce a new one.
Comment #14
dawehnerUpdate status :(
Comment #15
tom_ek commentedHi,
so what is actually happening with this issue? As far as I understand the reason it still needs work is that use of the constant? I have reviewed the code and it does not seem to have any flaws so if the problem is the constant I can rewrite that part. Otherwise - could you please let me know what exactly is to be done? I`d like to help with that.
Comment #16
mile23Unassigning @Thomas Brekelmans... Hop back on if you want.
The current only usage of
_views_file_status()is inDrupal\file\Plugin\views\filter\Status::getValueOptions().Unwrap some of the logic and inline it with that method, and here's the patch.
Comment #17
xjmThanks @Mile23!
Based on the Drupal 8 allowed changes policy we should now generally deprecate stale procedural functions in Drupal 8 rather than removing them. In this particular case, since its name begins with an underscore, that's implicitly considered an "internal" API, so we could consider removing it in a minor. We'd need to clarify that on the BC policy though since it does not mention the underscore naming pattern.
This probably needs release manager input before proceeding in one of those directions, though, so it's not currently a good novice task per https://www.drupal.org/core-mentoring/novice-tasks. Removing the novice tag.
Comment #18
xjmComment #30
longwaveResurrecting this after spotting it following #3021833: Move FILE_STATUS_PERMANENT to \Drupal\file\FileInterface
Comment #31
longwaveComment #32
longwaveComment #33
daffie commentedIt all looks good to me. I have just 1 nitpick question. After that is it RTBC for me.
Do we really need to add
0 =>or can it be removed? I can see that _views_file_status() did it. It is something we normally do not do in core.Comment #34
longwaveAdded a change record: https://www.drupal.org/node/3227228
Re #33 I think it is better to be explicit here that 0 means temporary, we usually only omit the array keys when we don't care about the number, but here the 0 has meaning.
Comment #35
daffie commentedUpdated the Is and the CR.
Comment #36
daffie commentedThe docblock of the function
_views_file_status()is missing the text: "@deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. There is no replacement."If you are a novice do a code base search for the tag "@deprecated in drupal:9.3.0" to see how it should be done.
Comment #37
daffie commentedFor got the needs work.
Comment #38
srilakshmier commentedComment #39
srilakshmier commentedUpdated the patch #34 based on the comment in #36. Please review.
Comment #40
longwaveThanks, the coding standards bot found a little issue:
Comment #41
srilakshmier commentedUpdated the patch #39 to fix the coding standard. Hope this works.!!
Comment #42
daffie commentedIt looks good to me.
For me it is RTBC.
Comment #43
catchCommitted/pushed to 9.3.x, thanks!
Comment #45
catchPush didn't make it - I've done that an also published the CR.