I'm trying to load a form inside a block plugin. However when I try to load it I get an error
The form argument information_request is not a valid form
'information_request' is the machine name of the form I'm attempting to load. This is an EForm I created, not a built in core form such as the user login form, or search form.
Here is the method I'm using that fails
$fb = \Drupal::formBuilder();
$inforequest = $fb->getForm('information_request');
$render['form'] = $inforequest;
return $render;
I've seen other examples for loading core forms like so
$form = \Drupal::formBuilder()->getForm('Drupal\search\Form\SearchBlockForm');
and I do see that a full address is being given in this example instead of just the machine id, but I don't know what address you could give for a custom eform. I've tried the following with no luck.
$inforequest = $fb->getForm('\Drupal\eform\information_request');
$inforequest = $fb->getForm('\Drupal\eform\Form\information_request');
How do you load an EForm programmatically to render inside a block plugin?
UPDATE: I made some more attempts to try to render it in another way. I attempted to load all entities like so
$content_entity_types = [];
foreach (\Drupal::entityManager()->getDefinitions() as $entity_type_id => $entity_type_definition) {
if ($entity_type_definition->getGroup() == 'content') {
$content_entity_types[$entity_type_id] = $entity_type_definition;
}
}
$entities = array();
foreach ($content_entity_types as $type_key => $entity_type) {
// Entities that do not declare a form class.
// Exclude Comment entities as they have to be attached to another entity.
// Get all bundles for current entity type.
$entity_type_bundles = \Drupal::entityManager()->getBundleInfo($type_key);
foreach ($entity_type_bundles as $bundle_key => $bundle_info) {
// Personal contact form requires a user recipient to be specified.
$entities[(string) $entity_type->getLabel()][$type_key.'.'.$bundle_key] = $bundle_info['label'];
}
}
die('<pre>'.print_r($entities).'</pre>');
Doing so did actually show that $entities did contain the form I was looking for
Array
(
[Custom block] => Array
(
[block_content.basic] => Basic block
)
[EForm Submission] => Array
(
[eform_submission.donate] => Donate
[eform_submission.information_request] => Information Request
)
[File] => Array
(
[file.file] => Drupal\Core\StringTranslation\TranslatableMarkup Object
(
[string:protected] => File
[translatedMarkup:protected] =>
[options:protected] => Array
(
)
[stringTranslation:protected] =>
[arguments:protected] => Array
(
)
)
)
[Content] => Array
(
[node.book] => Book page
[node.landing_page] => Landing Page
[node.news] => News
[node.newsletter] => Newsletter
[node.page] => Basic page
)
[Shortcut link] => Array
(
[shortcut.default] => Default
)
[User] => Array
(
[user.user] => Drupal\Core\StringTranslation\TranslatableMarkup Object
(
[string:protected] => User
[translatedMarkup:protected] =>
[options:protected] => Array
(
)
[stringTranslation:protected] =>
[arguments:protected] => Array
(
)
)
)
[Custom menu link] => Array
(
[menu_link_content.menu_link_content] => Drupal\Core\StringTranslation\TranslatableMarkup Object
(
[string:protected] => Custom menu link
[translatedMarkup:protected] =>
[options:protected] => Array
(
)
[stringTranslation:protected] =>
[arguments:protected] => Array
(
)
)
)
)
I see my form in $entities['EForm Submission']['eform_submission.information_request']; But I'm still not sure how to access or render it.