Problem/Motivation

\Drupal\Core\Field\Plugin\Field\FieldFormatter\StringFormatter doesn't declare the entityManager attribute in the class

Update:
As per suggestion by @alexpott in #4 replace deprecated entity.manager with entity_type.manager service.
Also fix the same for \Drupal\Core\Field\Plugin\Field\FieldFormatter\LanguageFormatter

Proposed resolution

Replace injection of deprecated service entity.manager with entity_type.manager in following classes:
\Drupal\Core\Field\Plugin\Field\FieldFormatter\StringFormatter
\Drupal\Core\Field\Plugin\Field\FieldFormatter\LanguageFormatter

Remaining tasks

Create a patch

User interface changes

None

API changes

None

Data model changes

None

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

penyaskito created an issue. See original summary.

Stockticker’s picture

Assigned: Unassigned » Stockticker
Status: Active » Needs review
FileSize
688 bytes

Please review.

msankhala’s picture

Status: Needs review » Reviewed & tested by the community

@Stockticker Thanks for the patch. I can confirm this patch applies cleanly and declares the missing entityManager attribute of the class. Even though EntityManager is deprecated now I think that should be part of another issue.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Nice find!

There's an additional problem here. The entity manager has been deprecated. So we're fixing something but then we'll have to change it in the future. Let's inject entity_type.manager into \Drupal\Core\Field\Plugin\Field\FieldFormatter\StringFormatter instead and fix \Drupal\Core\Field\Plugin\Field\FieldFormatter\LanguageFormatter too. And then the new property can be called $entityTypeManager.

msankhala’s picture

Title: \Drupal\Core\Field\Plugin\Field\FieldFormatter\StringFormatter doesn't declare the entityManager attribute in the class » Replace injection of deprecated entity.manager service with entity_type.manager in \Drupal\Core\Field\Plugin\Field\FieldFormatter\StringFormatter and LanguageFormatter
Issue summary: View changes
msankhala’s picture

Status: Needs work » Needs review
FileSize
5.72 KB
5.78 KB

@Stockticker Thanks for reporting this issue and initial patch. Here is updated patch.

alexpott’s picture

Status: Needs review » Needs work
+++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/LanguageFormatter.php
@@ -47,13 +47,12 @@ class LanguageFormatter extends StringFormatter {
+   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager

+++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/StringFormatter.php
@@ -46,13 +53,12 @@ class StringFormatter extends FormatterBase implements ContainerFactoryPluginInt
+   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
    */

Needs a description as per coding standards

msankhala’s picture

Status: Needs work » Needs review
FileSize
5.78 KB
1.73 KB

Ahh.. silly mistake. :) Added param description.

msankhala’s picture

Assigned: Stockticker » Unassigned
barthje’s picture

Status: Needs review » Needs work

I noticed you corrected the comments in one place to "the entity type manager" but in StringFormatter you call it "The entity manager" again, it should be the entity type manager.

barthje’s picture

Status: Needs work » Needs review
FileSize
5.79 KB
Mirnaxvb’s picture

Status: Needs review » Reviewed & tested by the community

All comments are correct now.

catch’s picture

Committed 62e59a0 and pushed to 8.6.x. Thanks!

  • catch committed 62e59a0 on 8.6.x
    Issue #2981025 by msankhala, barthje, Stockticker, penyaskito, alexpott...
catch’s picture

Status: Reviewed & tested by the community » Fixed
penyaskito’s picture

Not sure how we should deal with this. But even if it wasn't declared, people may assume there is a property (dynamic) called
$entityManager. This would be a backward compatibility issue then if we "rename" it to $entityTypeManager.

Status: Fixed » Closed (fixed)

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