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( $variables['content']['community_select_list'], ), );
Many thanks in advance!