Score:0

Can an installation profile have service.yml files?

in flag

I have a dxp_installer installation profile. I want to use the container injection for a service which I use in hook_install_tasks_alter() to verify the installation requirements. Note that I inject this service in one of my custom install forms construct, and not directly from the dxp_installer.install file.

I have defined this service in the dxp_installer.services.yml file. Now when I add container->get('dxp_installer.service'), I get an error about calling a non-existent service. Note that Drupal isn't installed yet at this stage. Are service files only usable after Drupal is installed?

Meanwhile, the actual service class is accessible with $service = new InstallerService(), which means the class is reachable by the class loader.

id flag
Can you confirm that hook name? Drupal doesn't seem to have a hook_install_alter. This is the standard reminder that Drupal 8 reached end-of-life on November 2, 2021 and has known security bugs.
ilechcod avatar
in flag
Thanks for the response, Cilefen. I meant to write ```hook_install_tasks_alter```. I have made the correction in the original question. I'm also actually running this on Drupal 10, I've also updated the tags. So then are ```service.yml``` files allowed in Installation Profiles?
id flag
It's so early in the process you may have the minimal container. What services are in the container at that stage?
ilechcod avatar
in flag
This isn't even a Drupal-defined service that I'm trying to access here. I'm trying to access a custom service which I defined in my profile's service.yml file. The question rather should be whether that service.yml file is processed at all - at that early stage?
ilechcod avatar
in flag
Seems like I have to look for another way to reach my service then. Just wished container injection was available - it's a cleaner approach.
id flag
What services are in the container at that stage?
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.