Currently content items or search selections can be deleted (of /admin/content and /admin/search-selection) when they are referenced somewhere else in the database. This should not be allowed, to keep the database consistent.
Because we don't know which bundles are loaded or which custom documents have been made the fields that contain a reference to the current class must be determined automatically. This can be done with this code: https://gist.github.com/zarathustra323/9551530. After that all found fields need to be queried to see if the document that will be deleted is in use somewhere.
When the document is still in use an error message needs to be shown: This item is still on use by <a href="">item name</a>
The "by <a href..." part will only be shown if they object is instanceof Article, otherwise you don't know the title and where to link to.
Note: please don't write this code in the controller, maybe a service or event listener.
the PR has a merge conflict in an unimportant file, but I think you will have comments, so the merge conflict will be solved with the rework
See comments in PR
Comments have been fixed
Two comments still need an answer
Sorry for not looking at the PR sooner.