Use custom commerce_shipping.profile_field_copy service not working

Created on 1 September 2023, 10 months ago

Trying to overwrite the default commerce_shipping.profile_field_copy service in my own custom module.

Have created a class Drupal\MyModule\ProfileFieldCopyWithoutPickup which extends ProfileFieldCopy.

And have added it in the my_module.services.yml

  commerce_shipping.profile_field_copy:
    class: Drupal\my_module\ProfileFieldCopyWithoutPickup
    arguments: ['@current_user']

Rebuilt the caches, and it's not recognized.

But if i remove the entry from services.yml and add a MyModuleServiceProdvider class

namespace Drupal\my_module;

use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\ServiceProviderBase;

class MyModuleServiceProvider extends ServiceProviderBase {

  /**
   * {@inheritdoc}
   */
  public function alter(ContainerBuilder $container) {
    if ($container->hasDefinition('commerce_shipping.profile_field_copy')) {
      $container->getDefinition('commerce_shipping.profile_field_copy')
        ->setClass(ProfileFieldCopyWithoutPickup::class);
    }
  }

}

It works, why

💬 Support request
Status

Closed: won't fix

Version

2.0

Component

Code

Created by

🇩🇰Denmark ramlev

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024