Open laceysanderson opened 1 year ago
We need to add documentation for how to use the Tripal core cvterm autocomplete. This was added via https://github.com/tripal/tripal/pull/1486
Here is @reynoldtan documentation from the PR:
An example form element would look this:
$form['my_autocomplete'] = [ '#type' => 'textfield', '#autocomplete_route_name' => 'tripal_chado.cvterm_autocomplete', '#autocomplete_route_parameters' => ['count' => 5] ];
Since the autocomplete returns human-readable output and not the cvterm id, there is an additional method that will fetch the ID from the user input.
namespace Drupal\my_autocomplete\Form; use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\tripal_chado\Controller\ChadoCVTermAutocompleteController; class MyAutoCompleteForm extends ConfigFormBase { /** * {@inheritdoc} */ public function getFormId() { return 'my_autocomplete_form'; } /** * {@inheritdoc} */ protected function getEditableConfigNames() { } /** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { $form['my_autocomplete'] = [ '#type' => 'textfield', '#autocomplete_route_name' => 'tripal_chado.cvterm_autocomplete', '#autocomplete_route_parameters' => ['count' => 5] ]; return parent::buildForm($form, $form_state); } /** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $term = $form_state->getValue('my_autocomplete'); // THIS IS THE CVTERM ID BASED ON THE USER SELECTIONS. $cvterm_id = ChadoCVTermAutocompleteController::getCVtermId($term); $this->messenger()->addWarning('Id is: ' . $cvterm_id, $repeat = FALSE); return parent::submitForm($form, $form_state); } }
And this is what it looks like in use:
We need to add documentation for how to use the Tripal core cvterm autocomplete. This was added via https://github.com/tripal/tripal/pull/1486
Here is @reynoldtan documentation from the PR:
An example form element would look this:
Since the autocomplete returns human-readable output and not the cvterm id, there is an additional method that will fetch the ID from the user input.
And this is what it looks like in use: