Change SVG source code in blueprint

I use a lot of svg files in my project, which are uploaded via the regular upload dialog. The blueprint for svg files is predefined by me. Since I use these svg files inline in my project (because of less server requests), I don’t have an <alt> tag and I have to check (and change!) the <title> tag in the svg source. (see screenshot)

How can I read the source code of my svg file into the blueprint and update it directly in the svg-file in the filesystem. I’ve never worked with hooks before and need a little help getting started.

Thanks in advance for any help

You can update the file on create like this:

  'hooks' => [
    'file.create:after' => function($file) {
        $sourceCode = F::read($file->root());
        $file->update([
          'source' => $sourceCode,
        ]);
      }
  ],

Maybe add a condition to make sure this only works for svg files/files with a given template.

The you can use a second hook on file update that writes the content of this field to file again.

Thank you for your answer. I’ll give it a try.