From this page: Note: Not recommended since v6.0.
I don't really understand how services are supposed to be used yet, but I'm thinking about creating a custom service to share code between custom hooks and jobs. For example, I need to collect information about related entities in a hook and job for one of my entities. It's literally the same code copied from the custom hook into the custom job. There has to be a better way, right? How would I share this code between a hook and job?
I don't really understand how services are supposed to be used yet, but I'm thinking about creating a custom service to share code between custom hooks and jobs. For example, I need to collect information about related entities in a hook and job for one of my entities. It's literally the same code copied from the custom hook into the custom job. There has to be a better way, right? How would I share this code between a hook and job?
Code:
48 private function getUnits($entity) {
49 $timesheetData = $this->getTimesheetData($service);
50
51 $unitsUsed = 0;
52 foreach($timesheetData as $td) {
53 $unitsUsed += $td->get("unitsBilled");
54 }
55 return $unitsUsed;
56 }
57
58 private function getTimesheetData($service) {
59 return $this->getEntityManager()->getRepository('Service')->getRelation($service, 'timesheetData')->find();
60 }

Comment