Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving form selections #38

Open
Natkeeran opened this issue Sep 1, 2017 · 6 comments
Open

Saving form selections #38

Natkeeran opened this issue Sep 1, 2017 · 6 comments

Comments

@Natkeeran
Copy link
Contributor

Natkeeran commented Sep 1, 2017

One UI improvement suggested is to save the selections for "CMODEL Mapping", "Object Properties Mapping" forms.

For instance, in the import.form.inc islandora_multi_importer_form_submit function, the "sequence and ordering" field selection can be saved as below:

$sequencemap = $form_state['values']['objectmap']['objectmapping']['rows']['sequencemap_row']['sequencemap'];
variable_set("multiimporter_objectmapping", $sequencemap);

And then in the islandora_multi_importer_objectmapping_form the saved variable info can be retried and set below:

$sequencemap = variable_get("multiimporter_objectmapping");
---
    'sequencemap' => array(
        '#type' => 'select',
        '#attributes' => '',
        '#description' => t('Select the source field to use as Sequence order index in multi child objects'),
        '#options' => $file_data['headers'],
        '#default_value' => $sequencemap,
      ),
---

I've tested this and this seems to work. If a stored value is not found as one of the options, it would default to the first option as it currently does.

Questions:

  • Is this approach ok?
  • We should avoid creating too many drupal variables, thus we can put all values belonging to objectmapping into a comma separated string.
  • The selected values are only available after submit/ingest. I am not sure if there is any other point to get the form values to save it to a variable.
  • cmodeldsmapping bit more challenging as is dynamically generated. But, similar approach should work there as well.

@DiegoPino

@DiegoPino
Copy link
Contributor

@Natkeeran the approach is right. Instead of system variables, we can set a new table as I do for the templates.

@DiegoPino
Copy link
Contributor

And we can serialize (json) all the form_state, the complete settings, which are basically what is inside cmodelmap and objectmap

@Natkeeran
Copy link
Contributor Author

@DiegoPino Ok, I see. Will review how you are storing the info in a table. Thanks.

@DiegoPino
Copy link
Contributor

@Natkeeran some help:

this class stores the templates
https://github.com/mnylc/islandora_multi_importer/blob/master/includes/TwigTemplateDatabase.inc

This here stores and retrieves the templates

https://github.com/mnylc/islandora_multi_importer/blob/master/includes/utilities.inc#L141-L164

You would only need to add a json_encode before saving and json_decode when retrieving.

@McFateM
Copy link
Contributor

McFateM commented Nov 6, 2017

I've approached this a little differently by coding an implementation of hook_form_alter which is documented in a new islandora_multi_importer.api.php like so...

/**
 * hook_form_alter.
 *
 * Note that this hook is implicitly, not explicitly, engaged by the
 *   islandora_multi_importer_form.  Intended use is to allow users of IMI to
 *   set custom default values for most input fields.
 *
 * Example values are from Digital Grinnell and the column order inherent in
 *   the Digital_Grinnell_MODS_Master Google Sheet, and its derivatives.
 *
 * @param $form
 * @param $form_state
 * @param $form_id
 *
 */
function hook_form_alter(&$form, &$form_state, $form_id) {

  // The big switch...
  switch($form_id) {

    // islandora_multi_importer_form
    case 'islandora_multi_importer_form':
      $form['cmodelmap']['basemapping']['rows']['cmodelmap_row']['cmodelmap']['#default_value'] = 4;        // cmodel - 4th column
      $form['objectmap']['objectmapping']['rows']['pidmap_row']['pidmap']['#default_value'] = 6;            // obj - 6th column
      $form['objectmap']['objectmapping']['rows']['parentmap_row']['parentmap']['#default_value'] = 3;      // parent - 3rd column
      $form['objectmap']['objectmapping']['rows']['labelmap_row']['labelmap']['#default_value'] = 7;        // title - 7th column
      $form['objectmap']['objectmapping']['rows']['sequencemap_row']['sequencemap']['#default_value'] = 5;  // sequence - 5th column
      $form['objectmap']['objectmapping']['rows']['dsmap_row']['dsremote']['#default_value'] = 'LOCAL';     // *local
      break;

  }

  return;
}

@McFateM
Copy link
Contributor

McFateM commented Oct 4, 2019

Just updating this to announce that I have a new implementation of hook_islandora_multi_importer_form_alter that populates my consistent defaults for ALL of the form fields including all CModels. I'm planning to share it at the Batch Ingest workshop I'm co-hosting next week at IslandoraCon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants