Problem/Motivation

This is a followup to #2898947: Change "writeable" to "writable" in documentation. Where that ticket covers the documentation, a follow-up was requested to cover changes to the method names. This is that follow-up.

Drupal core defines three functions with the less-used spelling 'writeable'...

The PHP standard library has a function named is_writable(), which Core uses 36 times; and an alias of that function named is_writeable(), which core does not use (as of commit 3834d60f1a).

Given that 'writable' already occurs more often than 'writeable', it makes sense for us change to 'writable' in this patch.

Proposed resolution

  1. Create new versions of the methods spelled "writable".
  2. Update the old versions to be wrappers of the new ones.
  3. Deprecate the old ones.

Remaining tasks

  1. Write a patch.
  2. Review by searching latest code with grep -r 'writeable' /path/to/core.

API changes

  1. \Drupal\Component\PhpStorage\PhpStorageInterface::writeable() is deprecated with no replacement
  2. \Drupal\Component\PhpStorage\FileStorage::writeable() is deprecated with no replacement
  3. \Drupal\Component\PhpStorage\FileReadOnlyStorage::writeable() is deprecated with no replacement

Data model changes

N/A

Release notes snippet

N/A

CommentFileSizeAuthor
#82 interdiff-71-82.txt5.04 KBjungle
#82 3138595-82.patch4.5 KBjungle
#71 interdiff-70-71.txt727 bytesjungle
#71 3138595-71.patch5.17 KBjungle
#70 interdiff-65-70.txt4.53 KBjungle
#70 3138595-70.patch5.12 KBjungle
#65 interdiff-64-65.txt1.59 KBjungle
#65 3138595-65.patch4.36 KBjungle
#64 interdiff-60-64.txt1.82 KBjungle
#64 3138595-64.patch3.43 KBjungle
#62 3138595-after-patch(2).png378.64 KBnayana_mvr
#62 3138595-after-patch(1).png495.57 KBnayana_mvr
#60 3138595-60.patch3.41 KB_utsavsharma
#60 interdiff_58-60.txt3.89 KB_utsavsharma
#58 interdiff-51-58.txt3.9 KBmarkdorison
#58 3138595-58.patch3.41 KBmarkdorison
#51 interdiff-49-51.txt667 bytesjungle
#51 3138595-51.patch3.41 KBjungle
#49 interdiff-46-49.txt3.84 KBjungle
#49 3138595-49.patch3.4 KBjungle
#46 3138595-46.patch3.4 KBjungle
#37 3138595-37.patch11.15 KBhimanshu_sindhwani
#33 3138595-33.patch11.16 KBankitsingh0188
#33 interdiff_30-33.txt603 bytesankitsingh0188
#30 interdiff-3138595-26-30.txt500 bytesmrinalini9
#30 3138595-30.patch11.17 KBmrinalini9
#28 writable-3138595-26.png68.41 KBatul4drupal
#26 interdiff_21-26.txt1.01 KBKumar Kundan
#26 3138595-26.patch11.18 KBKumar Kundan
#21 interdiff_17-21.txt2.71 KBKumar Kundan
#21 3138595-21.patch11.24 KBKumar Kundan
#17 interdiff_9-17.txt8.38 KBKumar Kundan
#17 3138595-17.patch11.41 KBKumar Kundan
#16 intediff.txt8.38 KBKumar Kundan
#16 3138595-16.patch11.23 KBKumar Kundan
#10 Screenshot 2020-05-26 at 4.47.22 PM.png159.78 KBkunalgautam
#9 interdiff_5-9.txt2.09 KBkunalgautam
#9 replace_method_writeable_to_writable-3138595-9.patch3.41 KBkunalgautam
#5 interdiff_2_5.txt544 byteswalangitan
#5 3138595-5.patch3.17 KBwalangitan
#2 3138595-1.patch3.17 KBmarkdorison

Comments

markdorison created an issue. See original summary.

markdorison’s picture

Status: Active » Needs review
StatusFileSize
new3.17 KB
codersukanta’s picture

Successfully applied patch #1. it looks good to me.

This seems to be a good idea.

public function writeable() {
return $this->writable();
}

For me it's RTBC +1.

walangitan’s picture

Status: Needs review » Needs work

There's a typo in 3138595-1.patch on the deprecation notice in PhpStorageInterface.php on comment #2. Patch to follow.

walangitan’s picture

Status: Needs work » Needs review
StatusFileSize
new3.17 KB
new544 bytes
ankitsingh0188’s picture

Hi,

Patch applied successfully #5

Looks good to me. Good to move it to RTBC.

Nice catch @walangitan

xjm’s picture

Status: Needs review » Needs work

Thanks for working on this. More consistent spelling in APIs will mean fewer accidental bugs.

  1. +++ b/core/lib/Drupal/Component/PhpStorage/FileReadOnlyStorage.php
    @@ -69,6 +69,13 @@ public function getFullPath($name) {
       public function writeable() {
    +    return $this->writable();
    +  }
    
    +++ b/core/lib/Drupal/Component/PhpStorage/FileStorage.php
    @@ -148,6 +148,13 @@ public function getFullPath($name) {
       public function writeable() {
    +    return $this->writable();
    +  }
    

    The old implementations should also @trigger_error() the deprecation, and have a legacy test of the expected deprecation.

  2. +++ b/core/lib/Drupal/Component/PhpStorage/PhpStorageInterface.php
    @@ -55,9 +55,19 @@ public function save($name, $code);
    +   * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0.
    

    This should have an @see to a change record. It's also listing the wrong thing -- it should say PhpStorageInterface. Edit: But actually, see the next point.

  3. +++ b/core/lib/Drupal/Component/PhpStorage/PhpStorageInterface.php
    @@ -55,9 +55,19 @@ public function save($name, $code);
    +  /**
    +   * Whether this is a writable storage.
    +   *
    +   * @return bool
    +   */
    +  public function writable();
    

    Adding a new method to an interface is a BC break, because it changes the interface contract. We can add new methods to an interface if there's a 1:1 relationship with an abstract base class that implements the methods; then, the base class can provide the new method implementation. Reference: https://www.drupal.org/core/d8-bc-policy#interfaces

    Unfortunately, we don't seem to have that here.

    So, I think we need to probably drop the new method from the interface. We might be able to create an additional interface as a BC layer that gets merged into the current interface in D10. Edit: The deprecation messages / documentation would need to explain all that; otherwise we might not complete it correctly in D10.

kunalgautam’s picture

Assigned: Unassigned » kunalgautam
kunalgautam’s picture

Updated patch.

kunalgautam’s picture

StatusFileSize
new159.78 KB

There are some "writeable" text and "is_writeable" function in the vendor folder.

kunalgautam’s picture

Assigned: kunalgautam » Unassigned
Status: Needs work » Needs review
atul4drupal’s picture

Status: Needs review » Needs work

Regarding #9:
Thanks for taking this forward, however the patch at #9 does not addresses the concerns pointed at #7.
Resetting for needs work.

ramya balasubramanian’s picture

Assigned: Unassigned » ramya balasubramanian
ramya balasubramanian’s picture

Assigned: ramya balasubramanian » Unassigned

I am unassigning this ticket as I have another ticket on my plate.

Kumar Kundan’s picture

Assigned: Unassigned » Kumar Kundan
Kumar Kundan’s picture

StatusFileSize
new11.23 KB
new8.38 KB
Kumar Kundan’s picture

StatusFileSize
new11.41 KB
new8.38 KB
Kumar Kundan’s picture

Assigned: Kumar Kundan » Unassigned
Status: Needs work » Needs review
atul4drupal’s picture

Status: Needs review » Needs work

Thanks Kumar Kundan, #17 is a good start to address the BC concern, just few improvements over what is in #17:

1) Its better to implement the 'PhpStorageInterface' interface in the abstract class itself and have the abstract class only been implemented in the class actually defining the functions body.

2) deprecation message needs improvement for @trigger_error:
some thing like -
%thing% is deprecated in %in-version% and will be VERB ADVERB %removal-version%. %extra-info%. See %cr-link%
(make this consistent where ever used)

3) +++ b/core/lib/Drupal/Component/PhpStorage/PhpStorageInterface.php

+ * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0.
change with : + @deprecated in Drupal:9.0.0 and will be removed "from / before" Drupal:10.0.0.
(make this consistent where ever used)

4) +++ b/core/lib/Drupal/Component/PhpStorage/PhpStorageInterface.php
"public function writeable();" is removed from the interface
and added the new function + public function writable();

writable function I see is placed in abstract class which is good however the original writeable() function must remain in the interface else it will break the BC.

The interface must not change at all.

Looks like a long patch to review... will share more findings if found :)

Kumar Kundan’s picture

Assigned: Unassigned » Kumar Kundan
Kumar Kundan’s picture

StatusFileSize
new11.24 KB
new2.71 KB
Kumar Kundan’s picture

Assigned: Kumar Kundan » Unassigned
Kumar Kundan’s picture

Status: Needs work » Needs review
ankitsingh0188’s picture

Status: Needs review » Needs work

Regarding #21 patch looks good, just a small suggestion/change.

Interface PhpStorageInterface already implemented by abstract class PhpStorageBase. If you are extending the abstract class PhpStorageBase, then there's no need to implement the PhpStorageInterface again.

+++ b/core/lib/Drupal/Component/PhpStorage/FileStorage.php
class FileStorage extends PhpStorageBase implements PhpStorageInterface must be class FileStorage extends PhpStorageBase

+++ b/core/lib/Drupal/Component/PhpStorage/FileReadOnlyStorage.php
class FileReadOnlyStorage extends PhpStorageBase implements PhpStorageInterface must be class FileReadOnlyStorage extends PhpStorageBase

Kumar Kundan’s picture

Assigned: Unassigned » Kumar Kundan
Kumar Kundan’s picture

StatusFileSize
new11.18 KB
new1.01 KB
Kumar Kundan’s picture

Assigned: Kumar Kundan » Unassigned
Status: Needs work » Needs review
atul4drupal’s picture

Status: Needs review » Needs work
StatusFileSize
new68.41 KB

Thanks Kumar Kundan for working on this, #26 looks almost ready just a small change:

img

mrinalini9’s picture

Assigned: Unassigned » mrinalini9
mrinalini9’s picture

Assigned: mrinalini9 » Unassigned
Status: Needs work » Needs review
StatusFileSize
new11.17 KB
new500 bytes

Done changes as mentioned in #28, please review.

atul4drupal’s picture

Status: Needs review » Needs work

Regarding #30

Thanks for the patch but seems you removed spaces against all the lines within the class, it only is to be removed (only 2 spaces) from the line containing function signature.

ankitsingh0188’s picture

Assigned: Unassigned » ankitsingh0188

I am working on it.

ankitsingh0188’s picture

StatusFileSize
new603 bytes
new11.16 KB
ankitsingh0188’s picture

Assigned: ankitsingh0188 » Unassigned
Status: Needs work » Needs review
daffie’s picture

Status: Needs review » Needs work

All the points of @xjm from comment #7 are still open.
There are still coding standard messages for the latest patch (see: https://www.drupal.org/pift-ci-job/1729166).
I think we should be using #2972224: Add .cspell.json to automate spellchecking in Drupal core, now that it has landed.

himanshu_sindhwani’s picture

Assigned: Unassigned » himanshu_sindhwani
himanshu_sindhwani’s picture

Assigned: himanshu_sindhwani » Unassigned
Status: Needs work » Needs review
StatusFileSize
new11.15 KB

Correcting the coding standard errors from drupal CI.

Interdiff:

diff -u b/core/lib/Drupal/Component/PhpStorage/PhpStorageBase.php b/core/lib/Drupal/Component/PhpStorage/PhpStorageBase.php
--- b/core/lib/Drupal/Component/PhpStorage/PhpStorageBase.php
+++ b/core/lib/Drupal/Component/PhpStorage/PhpStorageBase.php
@@ -15,2 +15,3 @@
   abstract public function writable();
+
 }
diff -u b/core/lib/Drupal/Component/PhpStorage/PhpStorageInterface.php b/core/lib/Drupal/Component/PhpStorage/PhpStorageInterface.php
--- b/core/lib/Drupal/Component/PhpStorage/PhpStorageInterface.php
+++ b/core/lib/Drupal/Component/PhpStorage/PhpStorageInterface.php
@@ -54,7 +54,11 @@
   /**
    * Whether this is a writeable storage.
    *
-   * @deprecated in Drupal:9.0.0 and will be removed from Drupal:10.0.0.
+   * @deprecated in Drupal:9.0.0 and will be removed from Drupal:10.0.0. This is
+   *   no longer used. Use \Drupal\Component\PhpStorage\PhpStorageBase::writable
+   *   instead.
+   *
+   * @see https://www.drupal.org/project/drupal/issues/3138595
    *
    * @return bool
    */
ankitsingh0188’s picture

@himanshu_sindhwani

When you post an updated patch, please also attach an interdiff file. There are instructions here: Creating an interdiff. Personally, I recommend using the interdiff utility. I think there is less room for making mistakes.

Kumar Kundan’s picture

Hi @daffie,
As per #7 comment, we covered all the possible points.
For
#7.1:- We used @trigger_error() for showing the deprecation message.
#7.2:- We used @see for referencing this issue.
#7.3:- We created a new abstract class & used for Backward compatibility.

Pls, let us know if we missed any point/cases.
Thanks

alexpott’s picture

Status: Needs review » Needs work
+++ b/core/lib/Drupal/Component/PhpStorage/PhpStorageBase.php
@@ -0,0 +1,17 @@
+/**
+ * Replace writeable with writable.
+ */
+abstract class PhpStorageBase implements PhpStorageInterface {

I'm not sure about adding this class. I guess we're adding this because we don't want to change the interface to add writable(). But then we have to support this unnecessary base class til at least Drupal 11 and have to coordinate removing it. If we're going to do this we might as when add a new interface that adds the new method. In Drupal 10 we move the writable method to PhpStorageInterface and deprecate the bridging interface. That way everything stays on interfaces and we don't end up with unnecessary class hierarchy. I think the docs for the bridging interface should tell people to not typehint on it.

Another thing that is quite amusing is that the ->writeable() method is not used in any runtime. So is it even necessary? The last runtime usage was in #2497243: Replace Symfony container with a Drupal one, stored in cache and there are no searchable contrib usages... http://grep.xnddx.ru/search?text=-%3Ewriteable%28%29&filename=

Kumar Kundan’s picture

Thanks to @alexpott, for reviewing this issue.

There are two points of view.
1. Either we follow the BC & abstract class PhpStorageBase implements PhpStorageInterface { convert the abstarct class to interface.
2. Or we directlly make changes in PhpStorageInterface interface.

Note:- I believe the 2nd point will be better.

@xjm & @alexpott please suggest the approach.

alexpott’s picture

@Kumar Kundan note that #40 points out that another option is to deprecate the writeable() method and not replace it we have no use-case in core and nothing in contrib. For me that's the preferred way forward.

jungle’s picture

Status: Needs work » Postponed

I would postpone this on #2898947: Change "writeable" to "writable" in documentation, some changes are out of scope here or in the scope of that one.

jungle’s picture

Title: Replace method names that use writeable with writable » [PP-1] Replace method names that use writeable with writable
jungle’s picture

Title: [PP-1] Replace method names that use writeable with writable » Replace method names that use writeable with writable
Status: Postponed » Needs work

Marked #3155135: Change "writeable" to "writable" ( Replace method names ) as duplicate, please credit @rajandro and @matts213 if applicable.

And the blocker is in.

jungle’s picture

Status: Needs work » Needs review
StatusFileSize
new3.4 KB

Per #42 if I understood it well. Deprecated writeable() directly, no replacement. But changing the method name in tests is fine, So changed.

jungle’s picture

+++ b/core/includes/install.core.inc
@@ -2185,7 +2185,7 @@ function install_check_requirements($install_state) {
-        $requirements["$file file writeable"] = [
+        $requirements["$file file writable"] = [

FYI, this is in the scope of #3155400: Change $requirements["$file file writeable"] to $requirements["$file file writable"], not here.

jungle’s picture

Assigned: Unassigned » jungle
Status: Needs review » Needs work
Issue tags: +Needs change record
+++ b/core/lib/Drupal/Component/PhpStorage/PhpStorageInterface.php
@@ -55,6 +55,11 @@ public function save($name, $code);
+   * @see https://www.drupal.org/node/2898947

Self-review, this should be the link of CR

jungle’s picture

Assigned: jungle » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs change record
StatusFileSize
new3.4 KB
new3.84 KB

CR added, Updating URL.

jungle’s picture

Assigned: Unassigned » jungle
Status: Needs review » Needs work
+++ b/core/lib/Drupal/Component/PhpStorage/PhpStorageInterface.php
@@ -55,6 +55,11 @@ public function save($name, $code);
+   * @deprecated in drupal:9.0.0 and is removed from drupal:10.0.0. No replacement.

Another self-review, over 80 chars.

jungle’s picture

Assigned: jungle » Unassigned
Status: Needs work » Needs review
StatusFileSize
new3.41 KB
new667 bytes

Addressing #50

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.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs tests, +Needs change record updates

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

@expectedDeprecation appears to no longer be used in Drupal core so tags for test to replace though.
Change record would have to be updated for deprecated in 10.1 and removed in 11

Thanks

markdorison’s picture

Issue tags: -Needs change record updates
StatusFileSize
new3.41 KB
new3.9 KB

Updated references to deprecation version and updated the change record.

@expectedDeprecation appears to no longer be used in Drupal core so tags for test to replace though.

Does this need to be removed or replaced with something else?

smustgrave’s picture

Probably their own tests

Use the expectDeprecation() method instead. See https://www.drupal.org/node/3176667

_utsavsharma’s picture

StatusFileSize
new3.89 KB
new3.41 KB

Updated the @expectedDeprecation with expectDeprecation().

ankitsingh0188’s picture

Status: Needs work » Needs review
nayana_mvr’s picture

StatusFileSize
new495.57 KB
new378.64 KB

Verified the patch #60 on Drupal version 10.1.x. The patch applied cleanly and I have added the after patch screenshots of both files for reference.

smustgrave’s picture

Status: Needs review » Needs work

That wasn't the correct fix. See change record

jungle’s picture

Status: Needs work » Needs review
StatusFileSize
new3.43 KB
new1.82 KB
jungle’s picture

StatusFileSize
new4.36 KB
new1.59 KB
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests

Thanks @jungle!

xjm’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/lib/Drupal/Component/PhpStorage/FileReadOnlyStorage.php
@@ -69,6 +69,7 @@ public function getFullPath($name) {
+    @trigger_error('writeable() is deprecated in drupal:10.1.0 and will be removed from drupal:11.0.0. No replacement. See https://www.drupal.org/node/3155413', E_USER_DEPRECATED);

+++ b/core/lib/Drupal/Component/PhpStorage/FileStorage.php
@@ -148,6 +148,7 @@ public function getFullPath($name) {
+    @trigger_error('writeable() is deprecated in drupal:10.1.0 and will be removed from drupal:11.0.0. No replacement. See https://www.drupal.org/node/3155413', E_USER_DEPRECATED);

These deprecation messages would appear to refer to a global procedural writeable() function. However, they are actually about Drupal\Component\PhpStorage\PhpStorageInterface::writeable().

xjm’s picture

The change record also doesn't explain what the code should do instead if for some reason some code happens to use this method.

xjm’s picture

Plus, the current scope (of entirely deprecating the method without any replacement) seems much broader than just changing the spelling to not have the silent "e", so we should update it with how we came to this solution of just entirely removing the whole interface method.

jungle’s picture

Status: Needs work » Needs review
StatusFileSize
new5.12 KB
new4.53 KB

Addressing @xjm's review. Added the new method ::writable() as the replacement of ::writeable().

jungle’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update
StatusFileSize
new5.17 KB
new727 bytes

Both IS and CR were updated.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

IS and CR look better now.

jungle’s picture

Thanks, @smustgrave

+++ b/core/lib/Drupal/Component/PhpStorage/PhpStorageInterface.php
@@ -55,6 +55,20 @@ public function save($name, $code);
+  public function writable();

Note: writable() added to the interface is a BC break. Not sure if it's allowed.

catch’s picture

Status: Reviewed & tested by the community » Fixed

The extra method is OK under the 1-1 exception for interface changes https://www.drupal.org/about/core/policies/core-change-policies/bc-policy

Committed 09a5ff9 and pushed to 10.1.x. Thanks!

  • catch committed 09a5ff9f on 10.1.x
    Issue #3138595 by jungle, Kumar Kundan, markdorison, kkalashnikov,...
catch’s picture

jungle’s picture

#74 thanks!

BTW, just published the CR.

  • xjm committed 599676af on 10.1.x
    Revert "Issue #3138595 by jungle, Kumar Kundan, markdorison,...
xjm’s picture

Status: Fixed » Needs work

I think there was a misunderstanding here. In #68 and #69 I wasn't saying that the new approach (of deprecating the methods with no replacement) was wrong; I was just indicating that the IS and CR needed to be updated accordingly.

#40 and #42 make a case for deprecating the method with no replacement because as of those comments it was not used in core or contrib. That's fine, so long as we update the issue title, issue summary, and change record to justify this and to explain to someone who might have for whatever reason used this in custom code whatever it is they should do instead.

Discussed with @catch and we agreed on a revert. Thanks!

xjm’s picture

catch’s picture

Title: Replace method names that use writeable with writable » Deprecate PhpStorage ::isWriteable() methods for removal in Drupal 11 with no replacement

Just doing the title for now.

jungle’s picture

Title: Deprecate PhpStorage ::isWriteable() methods for removal in Drupal 11 with no replacement » Deprecate PhpStorage ::writeable() methods for removal in Drupal 11 with no replacement
Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs change record updates, -Needs issue summary update
StatusFileSize
new4.5 KB
new5.04 KB

Sorry for the misunderstanding.

Corrected the title, it's ::writeable(), not ::isWriteable

IS updated, CR updated.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

I missed that too. Think it should be good now though.

  • longwave committed db3c1ec5 on 10.1.x
    Issue #3138595 by jungle, Kumar Kundan, markdorison, kkalashnikov,...
longwave’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 10.1.x, thanks!

Status: Fixed » Closed (fixed)

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