If we want to do #2561773: CacheableMetadata is misnamed in 8.2, then we should stop parameter typehinting on CacheableMetadata in 8.1, in order to minimize disruption. See also #2561773-47: CacheableMetadata is misnamed.

I think we only have 2 such typehints in core: within MenuParentFormSelectorInterface::getParentSelectOptions() and CachePluginBase::alterCacheMetadata(), and despite my comment in #2561773-51: CacheableMetadata is misnamed, @Wim Leers convinced me that those would be fine to change to RefineableCacheableDependencyInterface.

Tagging for "rc target triage", since changing those two typehints in a patch release of 8.1 would violate semver.

CommentFileSizeAuthor
#7 2705819-7.patch5.32 KBwim leers

Comments

effulgentsia created an issue. See original summary.

dawehner’s picture

Mh, so \Drupal\Core\Menu\MenuParentFormSelector::parentSelectOptionsTreeWalk calls out to

$cacheability
          ->merge

which is not on the interface, is this really what we want?

In generla having a BC layer aka. an old instance of the class seems totally worth it, and doesn't cause issues for people, so I don't get why breaking interfaces here is okay.

wim leers’s picture

#2: Because we should typehint to interfaces, not implementations.

dawehner’s picture

@Wim Leers
Sure, but to be honest CacheableMetadata is a value object for me, so additional implementations don't make that much sense.

wim leers’s picture

Note that callers of this code won't have to change anything. Only implementations (of which likely zero exist at this time) would have to be updated.

wim leers’s picture

Also, once those two are removed, we'll have zero typehints to CacheableMetadata left! The only remaining ones then are in test coverage/ internals.

This is again shows that typehinting to those concrete classes was simply a mistake, an oversight, a bug. This fixes that. Everything else typehints to (Refinable)CacheableDependencyInterface. For a very similar example, see \Drupal\Core\Menu\LocalTaskManagerInterface::getTasksBuild().

wim leers’s picture

Status: Active » Needs review
StatusFileSize
new5.32 KB
dawehner’s picture

I still don't see why we freak out ..., for the static method and other reasons we need to BC when we rename anyway.

Only implementations (of which likely zero exist at this time) would have to be updated.

You know, we promised the BC. I think we should break if just if there is an actual benefit.

dawehner’s picture

This is again shows that typehinting to those concrete classes was simply a mistake, an oversight, a bug

I don't disagree with that, but that is simply not my point here.

effulgentsia’s picture

Priority: Major » Normal

You know, we promised the BC.

Not really. From https://www.drupal.org/core/d8-bc-policy:
Interfaces follow a similar pattern as above with respect to @api, @internal, or neither. However, in case of neither tag, the interface is treated as an API for callers but not for implementors.

I think we should break if just if there is an actual benefit.

Well, how do we rename a concrete class per #2561773: CacheableMetadata is misnamed? Should NewClassName extends OldClassName or OldClassName extends NewClassName? If the former, then contrib module 1 cannot change its typehints to NewClassName because contrib module 2 might still be passing in objects of type OldClassName. If the latter, then neither core nor contrib modules can retain typehints to OldClassName, because most likely NewClassName objects are being passed. So essentially, any typehint to a concrete class name (as opposed to an interface) prevents the renaming of that class name.

effulgentsia’s picture

I downgraded priority in #10, because the Major priority was an artifact of me cloning from the parent issue. If we end up not doing this issue, we might be able to solve the parent issue via #2561773-52: CacheableMetadata is misnamed, which is less ideal, but possible, so therefore, this issue should be prioritized on its own merits, not as a hard blocker.

dawehner’s picture

Oh yeah both directions are just horrible. What about using https://secure.php.net/manual/en/function.class-alias.php ? (see https://3v4l.org/Ntu7n it runs perfectly)

<?php

class A {}

class_alias('A', 'B');

function f1(A $a) {
    
}

function f2(B $b) {
    
}

$a = new A();
f1($a);
f2($a);

$b = new B();
f1($b);
f2($b);

In general renaming classes feels really painfull.

wim leers’s picture

Woah! Mind=blown.

@dawehner++
@dawehner++

So, then would you agree with NOT doing this issue, and doing this in the parent issue (#2561773: CacheableMetadata is misnamed)?

  1. Rename CacheableMetadata to Cacheability
  2. Create an alias for BC.
  3. Mark merge() as deprecated, to be removed in 8.2 (edited)
dawehner’s picture

SO yeah for the alias you afaik put a class_alias() call into the file which would have contained the former class.

@Wim Leers
I'm confused about your point 3, there are like a gazillion amount of calls to merge()

wim leers’s picture

Version: 8.1.x-dev » 8.2.x-dev
Issue tags: -rc target triage

Too late now. Moving to 8.2, removing RC target triage tag.

However, I still think the patch in #7 makes sense, even independently of #2561773: CacheableMetadata is misnamed. Per the first paragraph of #10 that is okay.

Comments #10-paragraph-2, #11, #12, #13 and #14 actually belong on #2561773: CacheableMetadata is misnamed.

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.

smustgrave’s picture

Status: Needs review » Postponed (maintainer needs more info)
Issue tags: +Needs Review Queue Initiative

This issue is being reviewed by the kind folks in Slack, #need-reveiw-queue. We are working to keep the size of Needs Review queue [2700+ issues] to around 200, following Review a patch or merge require as a guide.

Wondering after 7 years for Drupal10.1 if this is still relevant?

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.

catch’s picture

Status: Postponed (maintainer needs more info) » Needs work

I think between changing the type hints to the interface and using class_alias() that would allow us to do the other issue without breaking bc, so still seems valid.

Comments on the patch:

  1. +++ b/core/lib/Drupal/Core/Menu/MenuParentFormSelectorInterface.php
    @@ -26,7 +26,7 @@
        *   the values are a menu name or link title indented by depth.
        */
    -  public function getParentSelectOptions($id = '', array $menus = NULL, CacheableMetadata &$cacheability = NULL);
    +  public function getParentSelectOptions($id = '', array $menus = NULL, RefinableCacheableDependencyInterface $cacheability = NULL);
     
       /**
    

    I doubt anyone is subclassing this, but I think we should probably remove the entire parameter from the interface in Drupal 10, add a commented out one to indicate it's going to be added back with the new type hint, then change the type hint in Drupal 12. Pretty sure this allows an implementation to update their own type hint in Drupal 10, see example 3 on #3050720: [Meta] Implement strict typing in existing code.

  2. +++ b/core/modules/views/src/Plugin/views/cache/CachePluginBase.php
    @@ -283,10 +284,10 @@ protected function prepareViewResult(array $result) {
        */
    -  public function alterCacheMetadata(CacheableMetadata $cache_metadata) {
    +  public function alterCacheMetadata(RefinableCacheableDependencyInterface $cache_metadata) {
       }
    

    And the same here.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.