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.

Comments

dawehner’s picture

Issue tags: +Novice, +VDC

adding tags.

Thomas Brekelmans’s picture

Assigned: Unassigned » Thomas Brekelmans

I'm taking this one on :)

Thomas Brekelmans’s picture

Status: Active » Needs review
StatusFileSize
new1.98 KB

I 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?

tstoeckler’s picture

Status: Needs review » Needs work
Issue tags: -Novice, -VDC
+++ b/core/modules/file/lib/Drupal/file/Plugin/views/field/Status.php
@@ -21,7 +21,16 @@ class Status extends FieldPluginBase {
+  private function getFileStatusLabel($value) {

We 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.

dawehner’s picture

+++ b/core/modules/file/lib/Drupal/file/Plugin/views/field/Status.phpundefined
@@ -21,7 +21,16 @@ class Status extends FieldPluginBase {
+  private function getFileStatusLabel($value) {
...
+    return isset($value) && isset($valueToLabelMap[$value]) ? $valueToLabelMap[$value] : t('Unknown');

Here $value should be always set, as it is not optional

damiankloip’s picture

Issue tags: +Needs tests, +Novice, +VDC
+++ b/core/modules/file/lib/Drupal/file/Plugin/views/field/Status.phpundefined
@@ -21,7 +21,16 @@ class Status extends FieldPluginBase {
+  private function getFileStatusLabel($value) {

This should be protected, we generally don't make any methods private.

+++ b/core/modules/file/lib/Drupal/file/Plugin/views/field/Status.phpundefined
@@ -21,7 +21,16 @@ class Status extends FieldPluginBase {
+      FILE_STATUS_PERMANENT => t('Permanent'),

We need to make this a class constant instead, then we can unit test this stuff easier.

+++ b/core/modules/file/lib/Drupal/file/Plugin/views/filter/Status.phpundefined
@@ -21,8 +21,10 @@ class Status extends InOperator {
+        0 => t('Temporary'),
+        FILE_STATUS_PERMANENT => t('Permanent'),

I wonder if there is somewhere central we can get this from? If we could remove the duplication that would be great.

damiankloip’s picture

Sorry, xposted! This issue has got busy all of a sudden ;)

Thomas Brekelmans’s picture

I'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?

The last submitted patch, interdiff-2032893-3-8.patch, failed testing.

Thomas Brekelmans’s picture

Status: Needs work » Needs review

:( 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.

dawehner’s picture

If 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.

Thomas Brekelmans’s picture

I 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.

dawehner’s picture

I am sorry but I think we should move the existing usages and not just introduce a new one.

dawehner’s picture

Status: Needs review » Needs work

Update status :(

tom_ek’s picture

Issue summary: View changes
Issue tags: +Amsterdam2014

Hi,

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.

mile23’s picture

Title: Move _views_file_status() into a autoloadable place » Refactor _views_file_status() out of existence
Assigned: Thomas Brekelmans » Unassigned
Status: Needs work » Needs review
StatusFileSize
new1.4 KB

Unassigning @Thomas Brekelmans... Hop back on if you want.

The current only usage of _views_file_status() is in Drupal\file\Plugin\views\filter\Status::getValueOptions().

Unwrap some of the logic and inline it with that method, and here's the patch.

xjm’s picture

Title: Refactor _views_file_status() out of existence » Deprecate and/or remove _views_file_status()
Version: 8.0.x-dev » 8.1.x-dev
Status: Needs review » Needs work
Issue tags: -Novice

Thanks @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.

xjm’s picture

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.

longwave’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new2.27 KB

Resurrecting this after spotting it following #3021833: Move FILE_STATUS_PERMANENT to \Drupal\file\FileInterface

longwave’s picture

longwave’s picture

Title: Deprecate and/or remove _views_file_status() » Deprecate _views_file_status() for removal
daffie’s picture

Status: Needs review » Needs work

It all looks good to me. I have just 1 nitpick question. After that is it RTBC for me.

+++ b/core/modules/file/src/Plugin/views/filter/Status.php
@@ -15,7 +16,10 @@ class Status extends InOperator {
+        0 => $this->t('Temporary'),

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.

longwave’s picture

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

Added 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.

daffie’s picture

Title: Deprecate _views_file_status() for removal » Deprecate the function _views_file_status()
Issue summary: View changes

Updated the Is and the CR.

daffie’s picture

Issue tags: +Novice

The 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.

daffie’s picture

Status: Needs review » Needs work

For got the needs work.

srilakshmier’s picture

Assigned: Unassigned » srilakshmier
srilakshmier’s picture

Assigned: srilakshmier » Unassigned
Status: Needs work » Needs review
StatusFileSize
new2.54 KB
new750 bytes

Updated the patch #34 based on the comment in #36. Please review.

longwave’s picture

Status: Needs review » Needs work

Thanks, the coding standards bot found a little issue:

 1781 | ERROR | [x] Separate the @return and @deprecated sections by
      |       |     a blank line.
 1781 | ERROR | [x] Whitespace found at end of line
srilakshmier’s picture

Status: Needs work » Needs review
StatusFileSize
new2.54 KB
new576 bytes

Updated the patch #39 to fix the coding standard. Hope this works.!!

daffie’s picture

Status: Needs review » Reviewed & tested by the community

It looks good to me.
For me it is RTBC.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 9.3.x, thanks!

  • catch committed 694650f on 9.3.x
    Issue #2032893 by Thomas Brekelmans, srilakshmier, longwave, Mile23,...
catch’s picture

Push didn't make it - I've done that an also published the CR.

Status: Fixed » Closed (fixed)

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