Skip to content

Commit

Permalink
Merge branch '4.x' into tv4g1-issue1414-uo__unit
Browse files Browse the repository at this point in the history
  • Loading branch information
pdtouch authored Nov 7, 2023
2 parents 54e0061 + 36ea116 commit c6f5e2c
Show file tree
Hide file tree
Showing 29 changed files with 4,097 additions and 1,299 deletions.
32 changes: 17 additions & 15 deletions tripal/src/Form/TripalImporterForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,23 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$importer = $importer_manager->createInstance($plugin_id);
$importer_def = $importer_manager->getDefinitions()[$plugin_id];

// Now allow the loader to do its own submit if needed.
try {
$importer->formSubmit($form, $form_state);
// Ensure any modifications made by the importer are used.
$form_values = $form_state->getValues();
$run_args = $form_values;
}
catch (\Exception $e) {
\Drupal::messenger()->addMessage('Cannot submit import: ' . $e->getMessage(), 'error');
}

// If the importer wants to rebuild the form for some reason then let's
// not add a job.
if ($form_state->isRebuilding() == TRUE) {
return;
}

// Remove the file_local and file_upload args. We'll add in a new
// full file path and the fid instead.
unset($run_args['file_local']);
Expand Down Expand Up @@ -218,23 +235,8 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$file_details['file_remote'] = $file_remote;
}
try {
// Now allow the loader to do its own submit if needed.
$importer->formSubmit($form, $form_state);
// If the formSubmit made changes to the $form_state we need to update the
// $run_args info.
if ($run_args !== $form_values) {
$run_args = $form_values;
}

// If the importer wants to rebuild the form for some reason then let's
// not add a job.
if ($form_state->isRebuilding() == TRUE) {
return;
}

$importer->createImportJob($run_args, $file_details);
$importer->submitJob();

}
catch (\Exception $e) {
\Drupal::messenger()->addMessage('Cannot submit import: ' . $e->getMessage(), 'error');
Expand Down
21 changes: 21 additions & 0 deletions tripal/src/TripalImporter/TripalImporterBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,32 @@
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\ReplaceCommand;
use Drupal\Core\DependencyInjection\DependencySerializationTrait;

/**
* Defines an interface for tripal impoerter plugins.
*/
abstract class TripalImporterBase extends PluginBase implements TripalImporterInterface {

/**
* Needed to allow AJAX on TripalImporter forms once Dependency injection is used.
*
* The error message implies that the log exception this trait is needed to
* solve is caused by the form serializing an object that has an indirect
* reference to the database connection (TripalImporter) and that we should
* adjust your code so that is not necessary.
*
* That said, the TripalImporterForm does not appear to save the TripalImporter
* object in the form or form state at any point. Instead it only uses
* the importer object to get strings and arrays that are incorporated
* into the form.
*
* Anyway, using this trait solves the problem and although the error
* mentions this should be a temporary solution, there are no mentioned plans
* in the Drupal forumns or code that this trait will be removed at any point.
*/
use DependencySerializationTrait;

/**
* The number of items that this importer needs to process. A progress
* can be calculated by dividing the number of items process by this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,9 @@ vocabularies:
- id: 'NCIT:C42699'
name: 'Namespace'
description: 'In general, a namespace is an abstract container, which is or could be filled by names, or technical terms, or words, and these represent or stand for real-world things. A description logic terminology namespace is a collection of Kind, Role, Property and Concept definitions. As in computer programming, context namespaces are intended to allow multiple knowledge bases to reside in the same physical database. (from Apelon) [ NCI ]'

- id: 'NCIT:C70699'
name: 'Biospecimen'
description: 'Any material sample taken from a biological entity for testing, diagnostic, propagation, treatment or research purposes, including a sample obtained from a living organism or taken from the biological object after halting of all its life functions.'

- name: 'ncbitaxon'
label: 'NCBI organismal classification. An ontology representation of the NCBI organismal taxonomy'
Expand Down
Loading

0 comments on commit c6f5e2c

Please sign in to comment.