I want a select list in a custom form drop down field which should list down all node titles specific to a content type. For this, I have created a view block, restricted it to one content type, allowing only node titles in its fields, and I am rendering this in the custom form. Below is the code I am using to do this:

In custom module:

$customblock = \Drupal::service('plugin.manager.block')->createInstance('community_list', []);
$variables['content']['community_select_list'] = $customblock->build();

$form['community'] = array(
  '#type' => 'select',
  '#title' => $this->t('Community name'),
  '#options' => array(

Many thanks in advance!

  • try looping the values. – Prerit Mohan Jun 21 '17 at 21:07
  • or use '#type' => 'entity_autocomplete' – 4k4 Jun 22 '17 at 7:15

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.