override userdefinedform subject line

Hi all, how can I overwrite userdefinedform subject line, I currently have an extension for UserdefinedformController like this:

public function updateEmailData(&$emailData, $email, $recipient)
{
foreach ($emailData[‘Fields’] as $field) {
if ($field->Title == ‘Email’) {
$value = $field->Value;
$subject = ‘Email is coming from’ . $value;
}
}

    $email->setSubject($subject);
}

To override the subject line of an email sent through a UserDefinedForm, you can use the setSubject() method of the Email class.

Here’s an example of how you might use this method to set the subject of an email sent through a UserDefinedForm:

use SilverStripe\Forms\EmailField;
use SilverStripe\Forms\FormAction;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\FieldList;

class MyForm extends Form
{
    public function getFormFields()
    {
        // ... other form fields

        $subjectField = EmailField::create('Subject', 'Subject');

        return FieldList::create(
            // ... other form fields
            $subjectField
        );
    }

    public function getFormActions()
    {
        return FieldList::create(
            FormAction::create('doSubmit', 'Submit')
        );
    }

    public function doSubmit($data, $form)
    {
        // ... other form processing

        // Set the subject of the email
        $email = new Email();
        $email->setSubject($data['Subject']);

        // Send the email
        $email->send();
    }
}

This will allow the user to enter a subject for the email in the form, and the subject will be set to the value entered by the user when the email is sent.

You can read more about the Email class and its available methods in the SilverStripe documentation: https://docs.silverstripe.org/en/4/developer_guides/email/sending_emails/