Name Field

Scanned on Mon, 05/25/2020 - 11:50.
2 warnings found.

Check manually

Errors without Drupal source version numbers including parse errors and use of APIs from dependencies.
File name Line Error
web//Users/youri/Websites/drupal/git/d8/name/name.module 89 The module is defining "theme_name_item_list" theme function. Theme functions are deprecated. For more info, see https://www.drupal.org/node/2575445.
web/modules/wip/name/name.info.yml 0 Add core_version_requirement: ^8 || ^9 to name.info.yml to designate that the module is compatible with Drupal 9. See https://drupal.org/node/3070687.

Remaining tasks

  1. Convert theme functions to twig templates.
  2. Update functional tests, use Mink to look for fields or other page elements.
  3. Get all tests passing.
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Farnoosh created an issue. See original summary.

karishmaamin’s picture

Version: 8.x-1.0-rc2 » 8.x-1.x-dev
Status: Active » Needs review
FileSize
19.96 KB

please review

Status: Needs review » Needs work

The last submitted patch, 2: name-3128409-2.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

nkoporec’s picture

Related issues: +#3128599: Drupal 9 readiness
ruchi-94’s picture

Assigned: Unassigned » ruchi-94
Farnoosh’s picture

@karishmaamin: I cannot apply your patch. Did you create it against 8.x-1.x-dev?

drupal-check report against the dev version:

------ -------------------------------------------------------
Line src/NameFormatParser.php
------ -------------------------------------------------------
291 Call to deprecated method strtolower() of class
Drupal\Component\Utility\Unicode:
in drupal:8.6.0 and is removed from drupal:9.0.0. Use
mb_strtolower() instead.
295 Call to deprecated method strtoupper() of class
Drupal\Component\Utility\Unicode:
in drupal:8.6.0 and is removed from drupal:9.0.0. Use
mb_strtoupper() instead.
477 Call to deprecated method strlen() of class
Drupal\Component\Utility\Unicode:
in drupal:8.6.0 and is removed from drupal:9.0.0. Use
mb_strlen() instead.
483 Call to deprecated method substr() of class
Drupal\Component\Utility\Unicode:
in drupal:8.6.0 and is removed from drupal:9.0.0. Use
mb_substr() instead.
605 Call to deprecated method strtoupper() of class
Drupal\Component\Utility\Unicode:
in drupal:8.6.0 and is removed from drupal:9.0.0. Use
mb_strtoupper() instead.
611 Call to deprecated method strtoupper() of class
Drupal\Component\Utility\Unicode:
in drupal:8.6.0 and is removed from drupal:9.0.0. Use
mb_strtoupper() instead.
------ -------------------------------------------------------

------ -------------------------------------------------------------------

ruchi-94’s picture

ruchi-94’s picture

Assigned: ruchi-94 » Unassigned
Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 7: 3128409-7.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Farnoosh’s picture

Thank you @ruchi-94. Patch #7 looks good.

There are few minor changes as per drupal-check report.

------ -----------------------------------------------------------------------
Line src/NameAutocomplete.php
------ -----------------------------------------------------------------------
120 Array and string offset access syntax with curly braces is deprecated
121 Array and string offset access syntax with curly braces is deprecated
------ -----------------------------------------------------------------------

------ ------------------------------------------------------------------------
Line src/Tests/NameAutocompleteTest.php
------ ------------------------------------------------------------------------
104 Call to deprecated function entity_create():
in drupal:8.0.0 and is removed from drupal:9.0.0. Use
The method overriding Entity::create() for the entity type, e.g.
\Drupal\node\Entity\Node::create() if the entity type is known. If the
entity type is variable, use the entity storage's create() method to
construct a new entity:
------ ------------------------------------------------------------------------

------ ---------------------------------------------------------------------------
Line src/Tests/NameUserTest.php
------ ---------------------------------------------------------------------------
114 Call to deprecated function user_format_name():
in drupal:8.0.0 and is removed from drupal:9.0.0.
Use $account->label() or $account->getDisplayName() instead
115 Call to deprecated method getUsername() of class Drupal\user\Entity\User:
in drupal:8.0.0 and is removed from drupal:9.0.0.
Use \Drupal\Core\Session\AccountInterface::getAccountName() or
\Drupal\user\UserInterface::getDisplayName() instead.
------ ---------------------------------------------------------------------------

Farnoosh’s picture

This patch does not include any work from patch #7.

Status: Needs review » Needs work

The last submitted patch, 11: Drupal-9-compatibilities-report-3128409-11.patch, failed testing. View results

abhijeet.kumar2107’s picture

Assigned: Unassigned » abhijeet.kumar2107
abhijeet.kumar2107’s picture

Assigned: abhijeet.kumar2107 » Unassigned
ruchi-94’s picture

Assigned: Unassigned » ruchi-94
ruchi-94’s picture

changes made as per suggestion in #10

MegaChriz’s picture

I found some issues in the patch from #16 and I've tried to fix them.

Summary of the changes:

  • For the Form classes, I used the class method messenger() instead of using \Drupal::messenger(). This is because FormBase uses the MessengerTrait.
  • For the Views filter plugin "name_fulltext" I injected the database service (instead of using \Drupal::database()). I copied this code from Drupal\views\Plugin\views\filter\StringFilter.
  • All tests are moved from src/Tests to tests/src/Unit, tests/src/Kernel, tests/src/Functional and tests/src/Traits.

There are some additional deprecations reported by the Upgrade Status module which I have not fixed:

Name Field

Scanned on Mon, 05/25/2020 - 11:50.
2 warnings found.

Check manually

Errors without Drupal source version numbers including parse errors and use of APIs from dependencies.
File name Line Error
web//Users/youri/Websites/drupal/git/d8/name/name.module 89 The module is defining "theme_name_item_list" theme function. Theme functions are deprecated. For more info, see https://www.drupal.org/node/2575445.
web/modules/wip/name/name.info.yml 0 Add core_version_requirement: ^8 || ^9 to name.info.yml to designate that the module is compatible with Drupal 9. See https://drupal.org/node/3070687.

I put this in the issue summary.

I haven't tested the module manually after making the changes. Let's first see if the tests will pass.

Alan D.’s picture

Let me know if anyone is keen to co-maintain, I'm time short atm.

MegaChriz’s picture

I looked at the test failures and started working on fixing them.

A good replacement for $element->asXML() could be $element->getHtml(). It happens that in WebTestBase a call to the method xpath() returned a \SimpleXMLElement, but in BrowserTestBase a \Behat\Mink\Element\NodeElement is returned. I did this at all locations, but locally the tests failed on an other thing after that.

Convert code to use Mink

I see that xpath is used a lot for checking if certain fields or other elements exist in the HTML output. In Drupal browser tests that are based on PHPUnit, Mink is used to do these checks. I therefore think that all code that is using xpath should be converted to use Mink. I added several @todo's in the code.

Also added $defaultTheme to NameTestBase.

@Alan D.
I'm not sure I'll have the time to help maintaining this module. I was just looking into this to see if I already could update a relatively small site to Drupal 9.

MegaChriz’s picture

This should fix NameAdminTest.

Contains also a single coding standards fix: properties $web_user and $admin_user have been renamed to $webUser and $adminUser.

Still needs work because of failing NameWidgetTest.

MegaChriz’s picture

Status: Needs work » Needs review
FileSize
64.19 KB
26.33 KB

This should fix NameWidgetTest.

Additionally, I also fixed the following issues:

  • Support for asserting against non-boolean values in ::assertTrue is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use a different assert method, for example, ::assertNotEmpty(). See https://www.drupal.org/node/3082086
  • Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was name_element_pre_render. Support for this callback implementation is deprecated in 8.8.0 and will be removed in Drupal 9.0.0. See https://www.drupal.org/node/2966725
  • Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was Drupal\name\Plugin\Field\FieldType\NameItem::fieldSettingsFormPreRender. Support for this callback implementation is deprecated in 8.8.0 and will be removed in Drupal 9.0.0. See https://www.drupal.org/node/2966725
  • Replaced some assertTrue() calls with better alternatives, for example with assertInstanceOf().
  • And some coding standards and spelling.

I realize this patch is becoming quite big - which makes it harder to review. If you want me to divide it into multiple chunks, I can do that.
I could do for example the following divisions:

  • Deprecation fixes in /src (thus excluding tests).
  • Text/spelling corrections.
  • Coding standard fixes (some).
  • #pre_render callbacks fixes
  • Test conversions.

The patch for converting the tests would remain big, I'm afraid.

Still left to do: convert theme functions to twig templates. That could be big patch by itself, so I would say that this should be postponed to a follow-up.

wrd’s picture

Patch applies to 2.x-dev, and in conjunction with https://www.drupal.org/files/issues/2020-04-17/name-3128599-2.patch (which simply adds the core_version_requirement), I can successfully add and configure a name field on a content type.

Ruslan Piskarov’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.

joshua.boltz’s picture

This looks good in combination with the patch that adds the core_version_requirement to the module's info.yml file.
It would be great to get these committed, so that folks don't need to include the patches via composer, because, in my experience, and possibly others, even though a patch adds the `core_version_requirement` value, composer still complains that it's not D9 supported.

In my understanding, there is a process that happens on the packagist repo when composer pulls down a module, where based on the `core_version_requirement`, it sets the values for the module in the composer.lock file, such as

"require": {
    "drupal/core": "^8 | ^9"
},

But, when adding patches, even though the info.yml is right, the .lock file still contains the old values

"require": {
    "drupal/core": "^8.8"
},

Which will be an issue during the D9 upgrade process.

  • Alan D. committed 32c6ddb on 8.x-1.x authored by MegaChriz
    Issue #3128409 by MegaChriz, ruchi-94, Farnoosh, karishmaamin, abhijeet....
Alan D.’s picture

Status: Reviewed & tested by the community » Fixed

Thanks everyone!

I didn't review but with no critical issues for the 8.x branch I've pushed these through directly.

As an aside, being out of the loop for a year or more, should I be creating a new branch for D9+ now? My lazy search didn't show much info and the project patch guide seems outdated.

nkoporec’s picture

Alen D. no need for a new branch, you can just tag a new release candidate, eq: 8.x-1.0-rc3

nkoporec’s picture

nkoporec’s picture

Alan D.’s picture

Cool thanks, albeit I may branch to 1.x once D8 is depreciated :)

I'll leave dev as is for a while before tagging up a new release.

MegaChriz’s picture

@Alan D.
If you want to switch to semantic versioning, you would need to increase the major version. But for D9 support you don’t necessarily have to switch.

From https://www.drupal.org/node/1015226#semver-transition:

When your project switches to using semantic versioning, you must increment your major version. For example, if the latest release is 8.x-3.5, your next stable release will be 4.0.0

8.x-* projects can be compatible with Drupal 9, so you don’t need to switch right away if you aren’t ready to start a new major version release series.

Alan D.’s picture

Thanks :)

Status: Fixed » Closed (fixed)

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

mrshowerman’s picture

I still get this warning after cache rebuild:

User deprecated function: Theme functions are deprecated in drupal:8.0.0 and are removed from drupal:10.0.0. Use Twig templates instead of theme_name_item_list(). See https://www.drupal.org/node/1831138 in Drupal\Core\Theme\Registry->processExtension() (line 498 of core/lib/Drupal/Core/Theme/Registry.php).

I guess this is due to the functions defined in name.theme.inc.

MegaChriz’s picture

@mrshowerman
Correct, we need to open a follow-up issue for that. I noted this in comment #21:

Still left to do: convert theme functions to twig templates. That could be big patch by itself, so I would say that this should be postponed to a follow-up.

Do you want to create a new issue for that?

Note that theme functions will keep working during the D9 release cycle, so there is less urgency to change it right now. But the sooner it is done, the better, I guess.

MegaChriz’s picture

Ah, I see someone already opened a follow-up: #3168948: Remove theme functions deprecated in Drupal 9

mrshowerman’s picture

Thanks @MegaChriz for pointing this out. Added the follow-up as a related issue.

JasonLuttrell’s picture

For anyone else wondering, the theme-related error message can be silenced with a quick/temporary patch:

diff --git a/core/lib/Drupal/Core/Theme/Registry.php b/core/lib/Drupal/Core/Theme/Registry.php
index 094780a10..15c88b029 100644
--- a/core/lib/Drupal/Core/Theme/Registry.php
+++ b/core/lib/Drupal/Core/Theme/Registry.php
@@ -495,7 +495,7 @@ protected function processExtension(array &$cache, $name, $type, $theme, $path)
         // if the theme hook specifies a function callback instead, check to
         // ensure the function actually exists.
         if (isset($info['function'])) {
-          trigger_error(sprintf('Theme functions are deprecated in drupal:8.0.0 and are removed from drupal:10.0.0. Use Twig templates instead of %s(). See https://www.drupal.org/node/1831138', $info['function']), E_USER_DEPRECATED);
+          @trigger_error(sprintf('Theme functions are deprecated in drupal:8.0.0 and are removed from drupal:10.0.0. Use Twig templates instead of %s(). See https://www.drupal.org/node/1831138', $info['function']), E_USER_DEPRECATED);
           if (!function_exists($info['function'])) {
             throw new \BadFunctionCallException(sprintf(
               'Theme hook "%s" refers to a theme function callback that does not exist: "%s"',

Hopefully, someone will fix this soon?