-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Labels
API: TermsTOPIC: Extending TripalDocumentation on developing custom modules, fields, themes, etc.Documentation on developing custom modules, fields, themes, etc.good first issueGood for newcomersGood for newcomers
Description
We need to add documentation for how to use the Tripal core cvterm autocomplete.
This was added via tripal/tripal#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);
}
}
Metadata
Metadata
Assignees
Labels
API: TermsTOPIC: Extending TripalDocumentation on developing custom modules, fields, themes, etc.Documentation on developing custom modules, fields, themes, etc.good first issueGood for newcomersGood for newcomers