0

I'm trying to pass a stdclass (containing array of measurement and name details) using a new Lang_String in Moodle plugin code:

redirect(new moodle_url('/mod/healthtracker/profile_measurements.php', ['id' => $userMeasurement->userid, 'course' => $userMeasurement->courseid]), new lang_string('delete_patient_measurement_success', 'mod_healthtracker', (object)compact('user','measurement')), \core\output\notification::NOTIFY_SUCCESS);

the lang sting itself being:

'delete_patient_measurement_success' => 'The {$a->measurement->name} measurement has been removed from {$a->user->firstname} {$a->user->lastname}',

however at present the output is:

The {$a->measurement->name} measurement has been removed from {$a->user->firstname} {$a->user->lastname}

whereas I actually want the lang string to display the variable values e.g. 'Blood Pressure' in place of {$a->measurement->name} and 'Bob' in place of {$a->user->firstname}

  • I think the (object)compact('user','measurement')) is the issue here but is not sure where the syntax is incorrect - any help greatfully received!
JNGF1
  • 1

1 Answers1

0

Moodle language strings only support single depth objects for substitutions.

So, a valid language string would look like this:

$string['delete_patient_measurement_success'] = "The {$a->measurementname} measurement has been removed from {$a->firstname} {$a->lastname}";

You would then call use it like this:

$str = new lang_string('delete_patient_measurement_success', 'mod_healthtracker', (object)[
     'measurementname' => $measurement->name,
     'firstname' => $user->firstname,
     'lastname' => $user->lastname,
]);
davosmith
  • 6,037
  • 2
  • 14
  • 23