How do I detect whether any contact forms have been created? Context: On my Drupal 8 site I'm trying to add in a new section containing a view that lists out all forms. The user can then click on one of the form and it launches a download of all the messages sent through that form. However that section should only be visible if the user has created at least 1 form.
What I've tried: So far what I've discovered is that the contact forms are stored in the config table in the database, so I could theoretically run a query like &quot;SELECT 1 FROM config WHERE name LIKE '%contact.form%'&quot; or whatever the equivalent in D8 is. However, it seems like there has to be a quicker way to return either the presence of contact forms or the contact forms themselves programmatically.
Final question: How can I return either the contact forms themselves or at least a boolean representing the presence of contact forms programmatically?
You can use the D8 config factory interface to retrieve multiple contact form config keys and their corresponding config entities:
$contact_form_keys = \Drupal::configFactory()-&gt;listAll('contact.form');
$contact_form_configs = \Drupal::configFactory()-&gt;:loadMultiple($contact_form_keys);