0

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 "SELECT 1 FROM config WHERE name LIKE '%contact.form%'" 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?

1 Answer 1

1

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()->listAll('contact.form');
$contact_form_configs = \Drupal::configFactory()->:loadMultiple($contact_form_keys);
1
  • Perfect! Thanks so much Commented Aug 7, 2020 at 19:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.