Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@vidu-wil
Copy link
Contributor

@vidu-wil vidu-wil commented Sep 23, 2025

New Feature

Issue #2284

Description

This PR introduces a new controller class, ChadoOrganismFormElementController, which replaces and extends the functionality of the existing ChadoOrganismAutocompleteController. It retains all existing methods while adding methods for generating the autocomplete/select elements used in the organism widget. Additionally, it includes a method to get the select options as a direct replacement for chado_get_organism_select_options() method.

Testing

Automated testing

ChadoOrganismFormElementControllerTest class containing the following methods:

  • testChadoOrganismFormElementController() - tests if the suggestions returned by the handleAutocomplete using the url request matches the expected number of options and whether the organism_id returned by getPkeyId is valid.
  • testFormElement() along with its data provider provideDataForTestFormElement() - tests the following test case scenarios to see if the returned element contains the expected keys and values:
    1. Select element with valid default id given
    2. Autocomplete with valid default id given
    3. Autocomplete with valid default value given
    4. Select element with valid default value given
    5. Autocomplete with invalid default id given

…anismFormElementControllerTest, and the ChadoOrganismWidgetDefault is updated to use the new controller class instead of the ChadoOrganismAutocomplete controller
@dsenalik dsenalik added the Group 1 - Tripal Content Types | Terms | Fields Any issue relating to Tripal Content including types, terms, and fields. label Sep 23, 2025
@dsenalik dsenalik linked an issue Sep 23, 2025 that may be closed by this pull request
@laceysanderson
Copy link
Member

The merging of #2294 should allow your tests to pass despite deprecations. However, be aware that #2297 will bring back failing on deprecations in D11 specifically. For any tests that directly test deprecated methods, you should add the #[IgnoreDeprecations] as shown in tripal_chado/tests/src/Functional/api/ChadoDbAPITest.php. This will allow these tests to throw deprecations but not fail while still ensuring any tests that indirectly call deprecated functionality fail.

@vidu-wil vidu-wil marked this pull request as ready for review September 26, 2025 16:32
Copy link
Contributor

@dsenalik dsenalik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work!
I think we should update the organism selects in the importers.
Specifically, the FASTA and GFF importers have organism select elements that could now use this new class.

// get the list of organisms
$organisms = chado_get_organism_select_options();
$form['organism_id'] = [
'#title' => t('Organism'),
'#type' => 'select',
'#description' => t("Choose the organism to which these sequences are associated"),
'#required' => TRUE,
'#options' => $organisms,
];

// get the list of organisms
$organisms = chado_get_organism_select_options(FALSE, TRUE);
// get the sequence ontology CV id
$conditions = ['cv.name' => 'sequence'];
$cv_records = $this->cvterm_buddy->getCv($conditions, []);
$sequence_cv_id = $cv_records[0]->getValue('cv.cv_id');
$form['organism_id'] = [
'#title' => t('Existing Organism'),
'#type' => 'select',
'#description' => t("Choose an existing organism to which the entries in the GFF file will be associated."),
'#required' => TRUE,
'#options' => $organisms,
'#empty_option' => t('- Select -'),
];

Copy link
Contributor

@dsenalik dsenalik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am very very sorry to say I request one more change.
The analysis field does not convert to autocomplete
I forgot that it is in the parent class
We need to change it here

never mind not relevant to this pr that only deals with the organism controller

public function addAnalysis($form, &$form_state) {
$chado = $this->connection;
// Get the list of analyses.
$query = $chado->select('1:analysis', 'A');
$query->fields('A', ['analysis_id', 'name']);
$query->orderBy('A.name');
$analyses = [];
$results = $query->execute();
while ($analysis = $results->fetchObject()) {
$analyses[$analysis->analysis_id] = $analysis->name;
}
// Add the form element.
$element['analysis_id'] = [
'#title' => t('Analysis'),
'#type' => 'select',
'#description' => t('Choose the analysis to which the uploaded data ' .
'will be associated. Why specify an analysis for a data load? All ' .
'data comes from some place, even if downloaded from a website. By ' .
'specifying analysis details for all data imports it provides ' .
'provenance and helps end user to reproduce the data set if needed. ' .
'At a minimum it indicates the source of the data.'),
'#required' => $this->plugin_definition['require_analysis'],
'#options' => $analyses,
];
return $element;

Copy link
Member

@laceysanderson laceysanderson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some code comments --this is looking really good ❤️

@laceysanderson
Copy link
Member

Regarding the test failure: https://github.com/tripal/tripal/actions/runs/18112268169/job/51540955913?pr=2293#step:5:26

  1. Drupal\Tests\tripal_chado\Functional\GFF3ImporterTest::testGFFImporterSimpleTest
    TypeError: Drupal\tripal_chado\Controller\ChadoOrganismFormElementController::getPkeyId(): Argument Fix PHP warnings during Chado install #1 ($value) must be of type string, null given, called in /var/www/drupal/web/modules/contrib/tripal/tripal_chado/src/Plugin/TripalImporter/GFF3Importer.php on line 634

/var/www/drupal/web/modules/contrib/tripal/tripal_chado/src/Controller/ChadoOrganismFormElementController.php:133
/var/www/drupal/web/modules/contrib/tripal/tripal_chado/src/Plugin/TripalImporter/GFF3Importer.php:634
/var/www/drupal/web/modules/contrib/tripal/tripal_chado/tests/src/Functional/Plugin/GFF3ImporterTest.php:122
/var/www/drupal/vendor/phpunit/phpunit/src/Framework/TestResult.php:729

This happens when the field is optional. I say we just allow the getPkeyId() to take NULL as a param and then return it without change. This way we don't need if's in every place this is called when it's optional.

Copy link
Member

@laceysanderson laceysanderson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tldr; This is ready for merge! You addressed all the outstanding concerns, the code looks good, and the manual testing done below works perfectly. Good job and Thanks!!! ❤️ 🎉

Manual Testing

✅ Creating a germplasm variety through the UI (selecting its organism via the updated field; SELECT) works great as does editing and deleting it.
Image

✅ Creating a germplasm variety through the UI (selecting its organism via the updated field; AUTO COMPLETE) works great as does editing and deleting it.
Image

✅ Editing genes published via the GFF3 importer when either a SELECT or AUTOCOMPLETE on the organism widget is used works beautifully with no errors.

Image Image

✅ Organisms with infraspecies provided work beautifully in both SELECT and AUTOCOMPLETE.

✅ GFF3 importer with updated form element works great.
Image

✅ Fasta importer with updated form element also works great.
Image

@laceysanderson laceysanderson added the Ready to Merge 🎉 Any PR which has been approved + is just waiting on branch updates/tests. label Oct 2, 2025
@laceysanderson laceysanderson dismissed dsenalik’s stale review October 2, 2025 17:21

Changes addressed

@laceysanderson laceysanderson merged commit bee72bc into tripal:4.x Oct 2, 2025
24 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Group 1 - Tripal Content Types | Terms | Fields Any issue relating to Tripal Content including types, terms, and fields. Includes Deprecations Ready to Merge 🎉 Any PR which has been approved + is just waiting on branch updates/tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Updates needed for current tripal_chado API functions

3 participants