I am using the following modules provided by default from Drupal's core - Contact and Contact Storage to manage simple contact forms.

For my module, I needed to include a title and sub-title fields in my contact forms, so I decided that the approach taken in Contact Storage suits me the most and I did the following:

  • In my .module file I implemented hook_form_FORM_ID_alter() like this - module_form_contact_form_form_alter(&$form, FormStateInterface $form_state) {} in which I placed my fields $form['title'] and $form['sub_title']

  • Then I added custom form builder function so that I can store my extra data using the functionality provided by ThirdPartySettingInterface like this $form['#entity_builders'][] = 'module_contact_form_form_builder';

  • In my custom builder function I invoke only the method to store my custom data, like this: $contact_form->setThirdPartySetting(/** **/);

So far - so good. I can save and later on, edit the data, but there comes in my problem:

How am I supposed to pass these two fields to my view/template? I tried to look for some _preprocess hooks, but I don't know how to access the data stored by ThirdPartySetting outside of form scope.

I want to state that I am fairly new to Drupal development whatsoever, so any kind of advice would be highly appreciated.

  • You will have to create fields for the Contact storage entities I guess and see how Contact storage has done it, you will get a fair idea of how things are working See hook_entity_base_field_info() in contact_storage.module
    – gauravjeet
    Aug 14 '17 at 13:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.