I want to create a new content type, e.g. company. This company needs an additional field which is a multiple file upload field. When the full node of the content type is displayed, I want to run some code in a controller which reads the uploaded files, executes logic and sends information to the twig template. However I'm unsure how to proceed. As far as I can see there are three options (of which the first isn't really an option):
I can create an entity type through the admin interface, and create a new node.html.twig template file, however this lacks the ability to execute custom PHP logic and send the information to twig, as i only have the twig template.
I can create a content type in a module and define the fields through the admin. If i understand correctly, this can be done through
drupal generate:entity:contentwith the Drupal Console.
I can create a module in which I define the content type, and hard-code all the fields. This is less flexible but maybe a stronger option: if something happens with the database I don't have to recreate the structure.
Both option 2 and option 3 can be viable. I've used Symfony2 before and using that I would take option 3, however it seems this option is over-complex in D8. If I understand correct in D8 fields should be defined through the admin interface. And a custom template can be created in the module eventually.
How should i tackle this issue? Which option is best? What is the best way to create a controller, which is used in displaying an entity/content type which is created via the D8 admin interface?