I'm trying to render taxonomy add term form inside content type ('article') add form. (node/add/article
)
In hook_form_alter
, I called this callback function on abutton.
public function _cvv_ajax_callback(VocabularyInterface $taxonomy_vocabulary) {
$taxonomy_vocabulary = 'cvv';
$term = \Drupal::entityManager()->getStorage('taxonomy_term')->create(['vid' => $taxonomy_vocabulary->id()]);
return \Drupal::entityFormBuilder()->getForm($term);
}
But this is not return form in my node/add page, rather giving me error:
error php Drupal\Core\Entity\EntityStorageException: Missing bundle for entity type taxonomy_term in Drupal\Core\Entity\ContentEntityStorageBase->doCreate()
I tried
if ($vocabulary = taxonomy_vocabulary_machine_name_load('jenis_dokumen')) {
module_load_include('inc', 'taxonomy', 'taxonomy.admin');
$edit = array();
$taxonomy_form = drupal_get_form('taxonomy_form_term', $edit ,$vocabulary);
return drupal_render($taxonomy_form);
}
but this is also not working in Drupal 8.
Also tried:
$form = \Drupal::formBuilder()->getForm('\Drupal\taxonomy\Controller\TaxonomyController::addForm','plan_features');
didn't worked :'(
Lastly I tried Inline Entity Form , the problem with module is, when a add term form get rendered inside node type form and if you do
kint($form_id);
inside hook_form_alter
, you won't get any form id for this inline form. Hence if you want to add custom validations for the term title, it won't be achievable even by hooks this module provides.
Please suggest a way to do this.