Problem/Motivation

#3508731 added service aliases for autowiring and set _defaults: autowire: true in the Commerce *.services.yml files, but a few leftovers remain:

  • commerce_log.services.yml is the only services file without _defaults: autowire: true.
  • 25 services still declare explicit arguments even though they could be autowired.
  • 18 service classes still assign their constructor arguments to properties manually instead of using constructor property promotion.

Every non-test service that can be injected already has an alias, so no new aliases are needed. The services without one are the lazy builders, which are only called through #lazy_builder, and the logger channels, which share the same class and are injected with #[Autowire(service: ...)].

Proposed resolution

  1. Add _defaults: autowire: true to commerce_log.services.yml.
  2. Remove arguments from the services below. Where autowiring cannot resolve a parameter on its own, add an #[Autowire] attribute to that constructor parameter instead:
    • cache bins (@cache.discovery, @cache.data) and @container.namespaces: #[Autowire(service: '...')]
    • %install_profile%: #[Autowire(param: 'install_profile')]
  3. Convert the constructors of the classes below to constructor property promotion.

The three logger channel services (commerce.logger, logger.channel.commerce_order, logger.channel.commerce_payment) keep their arguments, because those are the channel names passed to the logger.factory factory.

Services with explicit arguments

  • commerce: commerce.config_updater, plugin.manager.commerce_condition, plugin.manager.commerce_entity_trait, plugin.manager.commerce_inline_form
  • commerce_log: plugin.manager.commerce_log_template, plugin.manager.commerce_log_category
  • commerce_order: plugin.manager.commerce_adjustment_type, commerce_order.adjustment_transformer, commerce_order.address_book, commerce_order.order_assignment, commerce_order.availability_order_processor, commerce_order.address_book_subscriber, commerce_order.organization_condition_subscriber, commerce_order.profile_label_subscriber, commerce_order.timestamp_event_subscriber, commerce_order.order_number_subscriber, commerce_order.order_receipt_subscriber, commerce_order.order_receipt_mail, commerce_order.order_total_summary, commerce_order.order_store_resolver, commerce_order.price_splitter, commerce_order.price_calculator
  • commerce_product: commerce_product.attribute_field_manager
  • commerce_promotion: plugin.manager.commerce_promotion_offer
  • commerce_tax: commerce_tax.tax_order_processor

Services without constructor property promotion

  • commerce: ConditionManager, EntityTraitManager
  • commerce_cart: EventSubscriber\CartEventSubscriber
  • commerce_log: LogCategoryManager, LogTemplateManager
  • commerce_order: AdjustmentTransformer, AdjustmentTypeManager, OrderAssignment, PriceCalculator, Resolver\OrderStoreResolver, EventSubscriber\AddressBookSubscriber, EventSubscriber\OrderNumberSubscriber, EventSubscriber\OrderReceiptSubscriber, EventSubscriber\TimestampEventSubscriber
  • commerce_payment: PaymentOptionsBuilder
  • commerce_product: ContextProvider\ProductVariationContext
  • commerce_promotion: PromotionOfferManager
  • commerce_store: Cache\Context\StoreCacheContext

Plugin managers only promote the arguments that the parent constructor does not take.

Remaining tasks

  • Write the MR.
  • Rebuild the container and run the test suite to confirm every service still resolves.

API changes

None. Constructor parameter order and names are unchanged, so subclasses that call parent::__construct() keep working.

Issue fork commerce-3643468

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

jsacksick created an issue. See original summary.

jsacksick’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.