0

I am curious to know if there is a way for one to load a field e.g entity reference field that is currently being used in a node context outside of node. example in an admin settings page or in a web forms settings page.

I am able to load my custom field with the following entity_field.manager service, but how would I render this filed and add it to my $form array ?

     function hook_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
      $refrencedField = \Drupal::service('entity_field.manager')->getFieldDefinitions('node', 'my_field');
      if ($form_id === 'webform_settings_form') {
          $form['page']['custom_name'] = [
            $refrencedFiled
          ];
      }
    }
  • Do you have the tokens.module installed? It provides a UI to browse all available tokens including the [webform-submission:node:*] token. – jrockowitz Feb 13 '18 at 16:06
  • I am trying to reuse existing filed that was created initially to be used in a particular content type , but now I am trying to attach the same filed in the web-forms settings page using hook_form. Webforms currently does not provide a UI to add additional field so, using token is not a option for me. – Jay Chand Feb 13 '18 at 16:14
  • Is it possible to extend webforms settings menu to include custom fields? This field will be used by site admins to tag instance of a webforms with a unique value that will then be used on the front-end. – Jay Chand Feb 13 '18 at 16:21
  • Webforms are not using Field API and fields can't be attached to a $form render array. – jrockowitz Feb 14 '18 at 1:44

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.