Problem/Motivation

When I upgraded to the version 2.2 i've got this error (even on drush cr)

Fatal error: Uncaught Error: Class "Drupal\serialization\Normalizer\NormalizerBase" not found in /var/www/html/modules/contrib/duration_field/src/Normalizer/DateIntervalDataNormalizer.php:13
Stack trace:
#0 /var/www/html/vendor/composer/ClassLoader.php(576): include()
#1 /var/www/html/vendor/composer/ClassLoader.php(427): Composer\Autoload\{closure}('/var/www/html/m...')
#2 [internal function]: Composer\Autoload\ClassLoader->loadClass('Drupal\\duration...')
#3 /var/www/html/modules/contrib/symfony_mailer/src/MailerPass.php(22): class_exists('Drupal\\duration...')
#4 /var/www/html/vendor/symfony/dependency-injection/Compiler/Compiler.php(73): Drupal\symfony_mailer\MailerPass->process(Object(Drupal\Core\DependencyInjection\ContainerBuilder))
#5 /var/www/html/vendor/symfony/dependency-injection/ContainerBuilder.php(825): Symfony\Component\DependencyInjection\Compiler\Compiler->compile(Object(Drupal\Core\DependencyInjection\ContainerBuilder))

To avoid this error, I needed to enable the core module serialization.

Steps to reproduce

Use symfony mailer last version (I added it to the description because i saw it in my stack trace)
Use duration field last version

Proposed resolution

Add dependency to the module serialization

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

tichris59 created an issue. See original summary.

dkmishra’s picture

I tested this on Drupal 11 and was unable to reproduce the error. The module works without requiring the Serialization module to be enabled. Based on the stack trace, this issue may be related to the Symfony Mailer module rather than Duration Field itself. It would be helpful to know whether the problem can be reproduced on a clean Drupal 11 installation with only Duration Field enabled, without Symfony Mailer.

tichris59’s picture

Title: Fatal error on upgrade » Fatal error with symfony mailer
tichris59’s picture

Hello @dkmishra, I just tested on a fresh install:

here my composer.json

{
    "name": "drupal/recommended-project",
    "description": "Project template for Drupal projects with a relocated document root",
    "type": "project",
    "license": "GPL-2.0-or-later",
    "homepage": "https://www.drupal.org/project/drupal",
    "support": {
        "docs": "https://www.drupal.org/docs/user_guide/en/index.html",
        "chat": "https://www.drupal.org/node/314178"
    },
    "repositories": [
        {
            "type": "composer",
            "url": "https://packages.drupal.org/8"
        }
    ],
    "require": {
        "composer/installers": "^2.3",
        "drupal/admin_toolbar": "^3.5",
        "drupal/core-composer-scaffold": "11.3.10",
        "drupal/core-project-message": "11.3.10",
        "drupal/core-recommended": "11.3.10",
        "drupal/duration_field": "^2.2",
        "drupal/symfony_mailer": "^2.0",
        "drush/drush": "^13.4"
    },
    "conflict": {
        "drupal/drupal": "*"
    },
    "minimum-stability": "stable",
    "prefer-stable": true,
    "config": {
        "allow-plugins": {
            "composer/installers": true,
            "drupal/core-composer-scaffold": true,
            "drupal/core-project-message": true,
            "phpstan/extension-installer": true,
            "dealerdirect/phpcodesniffer-composer-installer": true,
            "php-http/discovery": true
        },
        "sort-packages": true
    },
    "extra": {
        "drupal-scaffold": {
            "locations": {
                "web-root": "web/"
            }
        },
        "installer-paths": {
            "web/core": [
                "type:drupal-core"
            ],
            "web/libraries/{$name}": [
                "type:drupal-library"
            ],
            "web/modules/contrib/{$name}": [
                "type:drupal-module"
            ],
            "web/profiles/contrib/{$name}": [
                "type:drupal-profile"
            ],
            "web/themes/contrib/{$name}": [
                "type:drupal-theme"
            ],
            "drush/Commands/contrib/{$name}": [
                "type:drupal-drush"
            ],
            "web/modules/custom/{$name}": [
                "type:drupal-custom-module"
            ],
            "web/profiles/custom/{$name}": [
                "type:drupal-custom-profile"
            ],
            "web/themes/custom/{$name}": [
                "type:drupal-custom-theme"
            ],
            "recipes/{$name}": [
                "type:drupal-recipe"
            ]
        },
        "drupal-core-project-message": {
            "include-keys": [
                "homepage",
                "support"
            ],
            "post-create-project-cmd-message": [
                "<bg=blue;fg=white>                                                         </>",
                "<bg=blue;fg=white>  Congratulations, you’ve installed the Drupal codebase  </>",
                "<bg=blue;fg=white>  from the drupal/recommended-project template!          </>",
                "<bg=blue;fg=white>                                                         </>",
                "",
                "<bg=yellow;fg=black>Next steps</>:",
                "  * Install the site: https://www.drupal.org/docs/installing-drupal",
                "  * Read the user guide: https://www.drupal.org/docs/user_guide/en/index.html",
                "  * Get support: https://www.drupal.org/support",
                "  * Get involved with the Drupal community:",
                "      https://www.drupal.org/getting-involved",
                "  * Remove the plugin that prints this message:",
                "      composer remove drupal/core-project-message"
            ]
        }
    }
}

duration field on drupal 13.3.10 is ok
just after enable symfony_mailer : KO

https://ibb.co/ks2GYHkJ

And the same bug if I enabled symfony_mailer and after duration_field.

dkmishra’s picture

@tichris59, thanks for sharing above details. I was able to reproduce the issue.

The error appears to originate from `web/modules/contrib/duration_field/src/Normalizer/DateIntervalDataNormalizer.php`. Around line 13, the file contains:

use Drupal\serialization\Normalizer\NormalizerBase;

class DateIntervalDataNormalizer extends NormalizerBase {

During container compilation (for example, while enabling Symfony Mailer), Drupal scans enabled modules and attempts to load this normalizer. It then fails with:
Class "Drupal\serialization\Normalizer\NormalizerBase" not found

It looks like the module relies on the serialization module but does not explicitly declare it as a dependency. It would make sense to add the following to duration_field.info.yml.

dependencies:
  - drupal:serialization
tichris59’s picture

Yes ! I made the change in this commit if you want: https://git.drupalcode.org/issue/duration_field-3593006/-/tree/8.x-2.x

dkmishra’s picture

Thanks for making the change. If you could also create an MR, that would be great.

tichris59’s picture

Sure, it's done :) thanks for your time

dkmishra’s picture

Version: 8.x-2.2 » 8.x-2.x-dev
Status: Active » Needs review

Thanks!

akashkumar07’s picture

Status: Needs review » Needs work

@tichris59 sorry for this nitpicking.
Can you please add \n newline at the end of file duration_field.info.yml
Thanks!

tichris59’s picture

@akashkumar07 seems good

akashkumar07’s picture

Status: Needs work » Needs review
akashkumar07’s picture

Status: Needs review » Reviewed & tested by the community

Thanks @tichris59
I have verified the changes and looking good.