Problem/Motivation

On #2900409: [Meta] Improve UI of Reference field settings form, Berdir noticed that the code for that patch was very similar to the views_entity_field_label() function.

Rather than maintaining this code in two places, it would be better if it was moved to be a method on a class accessible as a service. Berdir suggested maybe putting on the EntityFieldManager class.

Proposed resolution

Move to EntityFieldManager
Make views_entity_field_label() call that method.
Deprecate views_entity_field_label() -- meaning adding @deprecated tag to the doc block, adding trigger_error to the code, and replacing calls to that function in core.

Remaining tasks

Follow up:
Once that is done, we can also use the new function on #2900409: [Meta] Improve UI of Reference field settings form (which will be taken care of on that issue, not here).

User interface changes

None.

API changes

function views_entity_field_label() will be deprecated in favor of \Drupal::service('entity_field.manager')->getFieldLabels($entity_type_id, $field_name);

Data model changes

None.

Release notes snippet

CommentFileSizeAuthor
#3 3069442-3.patch4.94 KBjhodgdon

Issue fork drupal-3069442

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

jhodgdon created an issue. See original summary.

jhodgdon’s picture

Note: As a bonus, that function is calling deprecated code (using the deprecated EntityManager) so that will go away too. :) I looked for the issue to remove those deprecations but I didn't locate it...

jhodgdon’s picture

Status: Active » Needs review
StatusFileSize
new4.94 KB

My mistake on #2 -- the deprecated code was fixed in 8.8.x already.

In any case, here is a patch that hopefully creates this method on EntityFieldManager, and makes the views function call it. I haven't done the actual deprecation yet, so let's see if the function works first -- hopefully the original function had some kind of test that depended on it... The new method body is a direct copy/paste from the views function, except that I've replaced calls to Drupal:: with using the class itself and a service it already had injected.

I'll also go over to #2900409: [Meta] Improve UI of Reference field settings form and try to modify that patch to use this method.

jhodgdon’s picture

Actually, I went back to #2900409: [Meta] Improve UI of Reference field settings form... That code is doing more than what this function does, so I don't actually think it's useful to call this function... so maybe this issue is not so necessary?

The problem is that for the reference field sort UI (that other issue), we need to go through the field definitions in more detail, because we need to know:
- the most commonly-used label (this function does that)
- whether there was more than one label or not (this function does that)
- whether the field is considered to be Computed (this function does not do that)
- what the columns are in the storage definition (this function does not do that)

So we could call this function to get the label, but since we already need to go through the field information in loops to gather the other information, I don't think it makes a lot of sense to do that.

I'll add a note on the other issue. Anyway, it may still make sense to refactor this function... ??? not sure.

andypost’s picture

Issue tags: +@deprecated

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 » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs tests

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.

If I'm understanding the deprecation was figured out in D9 so this should be updated to do the deprecation warning.

Will need a test to show the message.

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.

nicxvan made their first commit to this issue’s fork.

nicxvan’s picture

nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Status: Needs work » Needs review
nicxvan’s picture

Addressing 13 we don't need tests showing deprecation messages per the deprecation policy.

nicxvan’s picture

Title: Deprecate views_entity_field_label() in favor of a class method outside Views » Deprecate views_entity_field_label() in favor of EntityFieldManager::getFieldLabels
nicxvan’s picture

Title: Deprecate views_entity_field_label() in favor of EntityFieldManager::getFieldLabels » Deprecate views_entity_field_label() in favor of EntityFieldManager->getFieldLabels
nicxvan’s picture

Issue tags: -Needs tests
nicxvan’s picture

berdir’s picture

Status: Needs review » Needs work

This looks good to me, the only question is about BC, I think EntityFieldManagerInterface is a 1:1 interface and we can add methods there, but it could still break of someone for example decorates that service.

Implementing the interface finds finds only one contrib, and that's a false positive, that has its own Interface, it also doesn't extend core.
https://git.drupalcode.org/search?group_id=2&scope=blobs&search=%22imple...

extends finds a few, two test stubs and one real subclass, those _should_ be fine:
https://git.drupalcode.org/search?group_id=2&scope=blobs&search=%22exten...

Who knows what kind of shenanigans people did with custom code :shrug:

Was about to RTBC, but the change record should have a before/after example even if it's trivial. It possibly should also more clearly say that this method has been added to EntityFieldManagerInterface.

nicxvan’s picture

Issue summary: View changes
Status: Needs work » Needs review

I updated the CR thanks!

berdir’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me now.

nicxvan’s picture

quietone’s picture

Status: Reviewed & tested by the community » Needs work

This needs a rebase and I left some comments in the MR.

@nicxvan, why did you tag this as 11.2.0 release priority?

berdir’s picture

> @nicxvan, why did you tag this as 11.2.0 release priority?

Because this is a blocker to deprecate hook_hook_info() usage, as it relies on those extra include files being loaded.

nicxvan’s picture

Great thanks! I applied most suggestions, I'll rebase and address the rest of your comments later today or early tomorrow.

@berdir is right this is one of two blockers to deprecate hook hook info which is the real target.

nicxvan’s picture

Ok I addressed your comments and rebased, I fixed one more typo as well.

I'll keep an eye on tests and move status after.

nicxvan’s picture

Status: Needs work » Needs review
berdir’s picture

Status: Needs review » Needs work

added more more comment that I missed before.

nicxvan’s picture

Status: Needs work » Needs review

Rebased and addressed feedback

berdir’s picture

Status: Needs review » Reviewed & tested by the community

Thanks.

dww’s picture

Status: Reviewed & tested by the community » Needs work

Added some suggestions for very minor / pedantic nits. Otherwise, seems reasonable to me.

nicxvan’s picture

Status: Needs work » Reviewed & tested by the community

Tests are green after applying nits.

dww’s picture

Thanks, looks better.

Issue title and summary look clear and accurate.

Saving credit for quietone and myself for MR reviews.

Don’t see anything else to improve. RTBC++

catch’s picture

Status: Reviewed & tested by the community » Needs work

This looks good but needs a rebase.

nicxvan’s picture

Working on this.

nicxvan’s picture

Status: Needs work » Reviewed & tested by the community

Rebased thanks!

dww’s picture

Status: Reviewed & tested by the community » Needs work

phpstan is failing in the pipeline.

dww’s picture

Related, but the rebase seems to have clobbered views.views.inc entirely. I thought we still needed a deprecated views_entity_field_label() in there.

TL;DR: Probably wise not to self-RTBC after a rebase, especially with merge conflicts, so that peer review can help spot trouble. 😅

nicxvan’s picture

Yeah I'm working on baseline, the deprecated function was moved to views.module

The whole point of this was so we could delete the views.views.inc file, but only the last of the two issues to get in could actually delete it.

nicxvan’s picture

Status: Needs work » Needs review
dww’s picture

Status: Needs review » Needs work

Sorry, I missed something in previous reviews (or this is a new bug). 1 suggestion to apply, otherwise seems RTBC to me.

dww’s picture

p.s. I did some minor edits and formatting cleanups on the CR: https://www.drupal.org/node/3489411/revisions/view/13800107/13851975

nicxvan’s picture

Status: Needs work » Needs review
dww’s picture

Status: Needs review » Reviewed & tested by the community
  • Pipeline is now green.
  • All feedback addressed.
  • All threads resolved.
  • Title and summary are accurate and clear.
  • CR is simple, accurate and clear.

I see nothing left to improve. RTBC.

Thanks!
-Derek

  • catch committed 7e5d6bfa on 11.x
    Issue #3069442 by nicxvan, jhodgdon, dww, berdir, quietone: Deprecate...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 11.x, thanks!

Status: Fixed » Closed (fixed)

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