Part of #2886622: Deprecate all EntityManager methods with E_USER_DEPRECATED, this covers the methods that moved to EntityRepositoryInterface, loadEntityByUuid(), loadEntityByConfigTarget() and getTranslationFromContext().

Additionally, to avoid too many conflicts and rerolls, this also completely replaces entity.manager when having to update injected dependencies and injects the necessary replacements services instead. That touches a few fairly large base classes and traits, specificalyl:

* EntityViewBuilder, including various subclasses
* DefaultSelection, including various subclasses and deprecation of SelectionTrait, which is a trait for constructor and create() method that was used in just 2 classes, which now require different services. I think it's very unlikely that someone else used this, it's pretty new, was only added ~1y ago. So I think it doesn't need a change record.
* EntityTranslationRenderTrait, used in ~6 classes, most need several injected dependency updates, one is itself not a service or plugin but just a class that is created in another plugin. And then plenty of unit tests for these classes.

CommentFileSizeAuthor
#30 entity-manager-get-translation-3023981-30-interdiff.txt924 bytesBerdir
#30 entity-manager-get-translation-3023981-30.patch173.54 KBBerdir
#23 entity-manager-get-translation-3023981-28-interdiff.txt934 bytesBerdir
#23 entity-manager-get-translation-3023981-28.patch173.31 KBBerdir
#18 entity-manager-get-translation-3023981-18-interdiff.txt24.18 KBBerdir
#18 entity-manager-get-translation-3023981-18.patch173.23 KBBerdir
#15 entity-manager-get-translation-3023981-15-interdiff.txt5.8 KBBerdir
#15 entity-manager-get-translation-3023981-15.patch169.04 KBBerdir
#13 entity-manager-get-translation-3023981-13-interdiff.txt1.53 KBBerdir
#13 entity-manager-get-translation-3023981-13.patch169.04 KBBerdir
#11 entity-manager-get-translation-3023981-11-interdiff.txt3.99 KBBerdir
#11 entity-manager-get-translation-3023981-11.patch167.52 KBBerdir
#8 entity-manager-get-translation-3023981-8-interdiff.txt39.37 KBBerdir
#8 entity-manager-get-translation-3023981-8.patch165.38 KBBerdir
#7 entity-manager-get-translation-3023981-7-interdiff.txt42.62 KBBerdir
#7 entity-manager-get-translation-3023981-7.patch126.26 KBBerdir
#4 2qlc4z.jpg44.24 KBBerdir
#4 entity-manager-get-translation-3023981-4-interdiff.txt43.63 KBBerdir
#4 entity-manager-get-translation-3023981-4.patch100.75 KBBerdir
#2 entity-manager-get-translation-3023981-2.patch63.17 KBBerdir
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Berdir created an issue. See original summary.

Berdir’s picture

Status: Active » Needs review
FileSize
63.17 KB

Hm, this might be a larger chunk than expected. I actually overlooked getTranslationFromContext() which does have quite a few usages and some tricky ones in EntityViewBuilder and DefaultSelection, I updated those to properly inject all the dependencies they need, so maybe needs should be split in dedicated issues, we'll see.

So far only covering getTranslationFromContext(), but I also remembered that there's an issue that updates all controllers, so I'm probably going to postpone this on that, as this overlaps quite a bit.

Berdir’s picture

Status: Needs review » Postponed
Berdir’s picture

EntityTranslationRenderTrait was a lovely one, to summarize:

The trait is used in ~6 implementations, all of them need to updated dependencies, and one of them is again created within another plugin, so I've had to inject the dependencies through that. And updated entity manager completely in all classes I had to touch anyway, so we only have to update the constructor once.

Still postponed on #2691675: Replace deprecated entityManager() in ControllerBase descendents and #2977107: Use more specific entity.manager services in module .services.yml files. Might not actually conflict with those, but will still have a good amount of deprecation errors now that I added the @trigger_error(). So not running tests yet, but it shouldn't conflict with those issues.

Berdir’s picture

Status: Postponed » Needs review

One of them is in, so if everything is correct (it most likely won't be), then this should only have deprecation messages related to the term breadcrumb builder.

Status: Needs review » Needs work

The last submitted patch, 4: entity-manager-get-translation-3023981-4.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Berdir’s picture

Fixed some constructors, updated deprecation message patterns like in #2691675: Replace deprecated entityManager() in ControllerBase descendents, updated some unit tests. This should have a lot less fails :)

Berdir’s picture

And this also covers loadEntityByUuid() and loadEnttityByConfigTarget(), these two seem to be trivial, getting large, but I think it makes sense to keep it together. Also added a @trigger_error() to SelectionTrait, @amateescu agreed with that approach.

The last submitted patch, 7: entity-manager-get-translation-3023981-7.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Status: Needs review » Needs work

The last submitted patch, 8: entity-manager-get-translation-3023981-8.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Berdir’s picture

One deprecation message was wrong, the others were all great examples of all kinds of deprecation messages, including still passing in entity manager server as an entity repository, injections, $this->entityManager properties.

If I got them all then only breadcrumb related test fails should remain, which should get fixed by #2977107: Use more specific entity.manager services in module .services.yml files

Status: Needs review » Needs work

The last submitted patch, 11: entity-manager-get-translation-3023981-11.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Berdir’s picture

That one was well hidden. Replacing using the property of the row plugin with \Drupal::entityTypeManager(), using properties of other objects has nothing to do with dependency injection :) And other places in the same class already do it like that too.

Status: Needs review » Needs work

The last submitted patch, 13: entity-manager-get-translation-3023981-13.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Berdir’s picture

Fixed some coding standard issues.

larowlan’s picture

Status: Needs review » Needs work
  1. +++ b/core/lib/Drupal/Core/Entity/EntityManager.php
    @@ -368,6 +368,7 @@ public function getEntityTypeLabels($group = FALSE) {
    +    @trigger_error('EntityManagerInterface::getTranslationFromContext() is deprecated in 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityRepository::getTranslationFromContext() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
    
    @@ -498,6 +499,7 @@ public function clearDisplayModeInfo() {
    +    @trigger_error('EntityManagerInterface::loadEntityByUuid() is deprecated in 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityRepository::loadEntityByUuid() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
    
    @@ -511,6 +513,7 @@ public function loadEntityByUuid($entity_type_id, $uuid) {
    +    @trigger_error('EntityManagerInterface::loadEntityByConfigTarget() is deprecated in 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityRepository::loadEntityByConfigTarget() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
    
    +++ b/core/modules/views/src/Plugin/views/field/EntityOperations.php
    @@ -45,16 +67,24 @@ class EntityOperations extends FieldPluginBase {
     
    

    Shouldn't we be adding new deprecation tests for these?

    And the constructor 'you need to pass blah' ones too?

  2. +++ b/core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionTrait.php
    @@ -7,6 +7,8 @@
    +@trigger_error(__NAMESPACE__ . '\SelectionTrait is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0.', E_USER_DEPRECATED);
    

    We need a change record link in this message

  3. +++ b/core/modules/aggregator/src/FeedViewBuilder.php
    @@ -15,21 +18,42 @@
    +  public function __construct(EntityTypeInterface $entity_type, EntityRepositoryInterface $entity_repository, LanguageManagerInterface $language_manager, Config $config, Registry $theme_registry, EntityDisplayRepositoryInterface $entity_display_repository, EntityTypeManagerInterface $entity_type_manager) {
    +    parent::__construct($entity_type, $entity_repository, $language_manager, $theme_registry, $entity_display_repository);
    

    Do you think we should do a big Change record listing all the constructor changes? Feels like too much to do one for each instance.

  4. +++ b/core/modules/block/src/BlockViewBuilder.php
    @@ -6,58 +6,18 @@
    -   * The module handler.
    -   *
    -   * @var \Drupal\Core\Extension\ModuleHandlerInterface
    -   */
    -  protected $moduleHandler;
    -
    -  /**
    -   * Constructs a new BlockViewBuilder.
    -   *
    -   * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
    -   *   The entity type definition.
    -   * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
    -   *   The entity manager service.
    -   * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
    -   *   The language manager.
    -   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
    -   *   The module handler.
    -   */
    -  public function __construct(EntityTypeInterface $entity_type, EntityManagerInterface $entity_manager, LanguageManagerInterface $language_manager, ModuleHandlerInterface $module_handler) {
    -    parent::__construct($entity_type, $entity_manager, $language_manager);
    -    $this->moduleHandler = $module_handler;
    -  }
    -
    -  /**
    -   * {@inheritdoc}
    -   */
    -  public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
    -    return new static(
    -      $entity_type,
    -      $container->get('entity.manager'),
    

    note for further reviews:

    BlockViewBuilder extends from EntityHandlerBase, which has setModuleHandler method called on it from \Drupal\Core\Entity\EntityTypeManager::createHandlerInstance

    there is some technical debt there we have to pay down anyway - see #2471663: Undeprecate EntityHandlerBase

  5. +++ b/core/modules/taxonomy/src/Form/OverviewTerms.php
    @@ -79,7 +101,8 @@ public static function create(ContainerInterface $container) {
           $container->get('entity.manager'),
    

    shouldn't this update to use entity type manager now?

  6. +++ b/core/modules/user/src/Plugin/EntityReferenceSelection/UserSelection.php
    @@ -33,13 +36,6 @@ class UserSelection extends DefaultSelection {
    -  protected $userStorage;
    

    note to other reviewers: not used

  7. +++ b/core/modules/views/src/Entity/Render/EntityTranslationRendererBase.php
    @@ -31,7 +31,7 @@ public function query(QueryPluginBase $query, $relationship = NULL) {
    -    $view_builder = $this->view->rowPlugin->entityManager->getViewBuilder($this->entityType->id());
    
    +++ b/core/modules/views/src/Entity/Render/TranslationLanguageRenderer.php
    @@ -80,7 +80,7 @@ protected function getLangcodeTable(QueryPluginBase $query, $relationship) {
    -    $view_builder = $this->view->rowPlugin->entityManager->getViewBuilder($this->entityType->id());
    

    ouch, talking to your neighbour's neighbour's neighbour's neighbour

Berdir’s picture

1. Yes, this needs deprecation tests, I was waiting for #3023799: Add @trigger_error() to deprecated EntityManager::clearCachedDefinitions() method to get in, which makes EntityManagerTest a @legacy test, then I I can avoid conflicts there. We didn't do deprecation tests for the constructors so far, I think that isn't worth the trouble.

2. Wasn't sure about that, what to write there? it was only added in 8.5 or so, I very much doubt anyone uses it, it is very specific to those two classes that used it and there is no replacment.

3. The grandparent of all change records, https://www.drupal.org/node/2549139, already has a note for one constructor change that we did in 8.6. Maybe we could do it for the class constructors that basically actually *are* API's, like ContentEntityForm there, so things like EntityViewBuilder and that views trait. Can add that after it is in. Most are just about being extra nice and the deprecation message is pretty obvious.

5. That looks weird indeed, need to check :)

4.6: Yup, wasn't quite sure about the userStorage, theoretically, someone could have subclassed that storage and used it, but that seems very unlikely and not that hard to fix if really required.

7. Yup, see #4 :)

Berdir’s picture

Added deprecation tests, updated the constructor deprecation messages and fixed that left-over entity.manager

larowlan’s picture

  1. +++ b/core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionTrait.php
    @@ -7,7 +7,7 @@
    +@trigger_error(__NAMESPACE__ . '\SelectionTrait is deprecated in drupal:8.7.0 and will be removed before drupal:9.0.0.', E_USER_DEPRECATED);
    

    I think we need a CR link in this message

  2. +++ b/core/modules/menu_ui/src/Tests/MenuWebTestBase.php
    @@ -46,7 +46,7 @@ public function assertMenuLink($menu_plugin_id, array $expected_item) {
    -      $entity = \Drupal::service('entity.repository')->loadEntityByUuid('menu_link_content', $uuid);
    +      $entity = \Drupal::entityManager()->loadEntityByUuid('menu_link_content', $uuid);
    

    is this intended?

Don't we need deprecation tests for the constructor arg trigger_errors?

Berdir’s picture

1. Pointing to what? I honestly feel that it is not worth to add a CR for this? There is no existing one, it is a new deprecation of a trait that was added ~1y ago that does not contain anything useful for anoyne except the two classes that used it (it's just a constructor). The chances of anyone using that are pretty much zero, there is no after code snippet either, you just have to write your own constructor which will likely be different for everone.

2. Looks a bit weird in the interdiff but the whole class is deprecated, @alexpott and I agreed in the clearCachedDefinitions() issue to not touch those cases.

3. Haven't done that before in any of the previous issues. This is stuff that we will remove again in a year or so, and we're just being super nice, according to the current BC policy, we wouldn't have to.

larowlan’s picture

Fair enough, will chat with other committers to confirm

xjm’s picture

We discussed the CR and agreed that we should have a CR summary of the overall constructor change pattern and what it applies to, with an example, rather than listing them all.

Berdir’s picture

Created https://www.drupal.org/node/3030634, still think that's a bit pointless, not convinced that e.g. duplicating a while new constructor code makes sense?

Also updated https://www.drupal.org/node/2549139 for now and added a snippet about constructor changes there, I expect at some point we can also just reference the policy page or a specific documentation page.

larowlan’s picture

Status: Needs review » Reviewed & tested by the community

I think its time for second set of committer eyes here

catch’s picture

I agree with not testing the constructor deprecations (unless it's for a value object or similar) because we're already going over and above adding those deprecations in the first place for @internal code. tbh I'm also not sure about a change record, because the trigger_error() documents the change as well as a change record can, and this is code we don't expect people to have to change - so it can make important change records harder to find. But consolidating in one is a reasonable compromise.

Patch looks right to me.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 23: entity-manager-get-translation-3023981-28.patch, failed testing. View results

Berdir’s picture

Status: Needs work » Reviewed & tested by the community

Random fail?

1) Drupal\Tests\system\FunctionalJavascript\OffCanvasTest::testOffCanvasLinks with data set "stark" ('stark')
WebDriver\Exception\UnknownError: unknown error: Element ... is not clickable at point (70, 87). Other element would receive the click: ...
  (Session info: headless chrome=62.0.3202.94)
  (Driver info: chromedriver=2.33.506092 (733a02544d189eeb751fe0d7ddca79a0ee28cce4),platform=Linux 4.9.0-0.bpo.6-amd64 x86_64)
alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/editor/src/Plugin/Filter/EditorFileReference.php
@@ -25,11 +25,11 @@
   /**
-   * An entity manager object.
+   * The entity repository.
    *
-   * @var \Drupal\Core\Entity\EntityManagerInterface
+   * @var \Drupal\Core\Entity\EntityRepositoryInterface
    */
-  protected $entityManager;
+  protected $entityRepository;

I think this should use DeprecatedServicePropertyTrait

Couldn't spot anything else.

alexpott’s picture

Given all the PHP 5.5 trait issues triggered a test against PHP 5.5

Berdir’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
173.54 KB
924 bytes

Added the missing DeprecatedServicePropertyTrait.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed e69e249 and pushed to 8.7.x. Thanks!

jibran’s picture

Status: Fixed » Reviewed & tested by the community

This has not been pushed yet.

  • alexpott committed e69e249 on 8.7.x
    Issue #3023981 by Berdir, larowlan, alexpott, xjm, catch: Add @...
alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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