Loading rest_oai_pmh.install +17 −0 Original line number Diff line number Diff line Loading @@ -193,3 +193,20 @@ function rest_oai_pmh_update_8005() { $config->set('cache_technique', 'liberal_cache'); $config->save(); } /** * Update storage config to avoid potentially using dots as config keys */ function rest_oai_pmh_update_8006() { $config = \Drupal::service('config.factory')->getEditable('rest_oai_pmh.settings'); $old_map_plugin_config = $config->get('metadata_map_plugins'); $new_map_plugin_config = []; foreach ($old_map_plugin_config as $prefix => $value) { $new_map_plugin_config[] = [ 'label' => $prefix, 'value' => $value, ]; } $config->set('metadata_map_plugins', $new_map_plugin_config); $config->save(); } src/Form/RestOaiPmhSettingsForm.php +25 −3 Original line number Diff line number Diff line Loading @@ -102,6 +102,20 @@ class RestOaiPmhSettingsForm extends ConfigFormBase { return 'rest_oai_pmh_settings_form'; } private function getMappingConfig(string $metadata_prefix) { $mapping_config = $this->config('rest_oai_pmh.settings') ->get('metadata_map_plugins'); if (!is_array($mapping_config)) { return false; } foreach ($mapping_config as $map) { if ($map['label'] == $metadata_prefix) { return $map['value']; } } return false; } /** * {@inheritdoc} */ Loading Loading @@ -156,14 +170,14 @@ class RestOaiPmhSettingsForm extends ConfigFormBase { foreach (\Drupal::service('plugin.manager.oai_metadata_map')->getDefinitions() as $plugin_id => $plugin_definition) { $mapping_prefix_plugins[$plugin_definition['metadata_format']][$plugin_id] = $plugin_definition['label']->render(); } $mapping_config = $config->get('metadata_map_plugins'); foreach ($mapping_prefix_plugins as $metadata_prefix => $options) { $mapping_config = $this->getMappingConfig($metadata_prefix); $form['mapping'][$metadata_prefix] = [ '#type' => 'select', '#empty_value' => '', '#options' => $options, '#title' => $metadata_prefix, '#default_value' => empty($mapping_config[$metadata_prefix]) ? '' : $mapping_config[$metadata_prefix], '#default_value' => !$mapping_config ? '' : $mapping_config['value'], ]; } Loading Loading @@ -297,9 +311,17 @@ class RestOaiPmhSettingsForm extends ConfigFormBase { } } $mapping = []; foreach ($form_state->getValue('mapping') as $label => $value) { $mapping[] = [ 'label' => $label, 'value' => $value, ]; } $config->set('view_displays', $view_displays) ->set('support_sets', $form_state->getValue('support_sets')) ->set('metadata_map_plugins', $form_state->getValue('mapping')) ->set('metadata_map_plugins', $mapping) ->set('mods_view', $form_state->getValue('view')) ->set('repository_name', $form_state->getValue('repository_name')) ->set('repository_email', $form_state->getValue('repository_email')) Loading src/Plugin/rest/resource/OaiPmh.php +11 −0 Original line number Diff line number Diff line Loading @@ -108,8 +108,19 @@ class OaiPmh extends ResourceBase { 'metadata_map_plugins', ]; foreach ($fields as $field) { //metadata map plugins are stored in ['label' => label, 'value' => value] format if ($field == 'metadata_map_plugins') { $map_plugins = []; if (is_array($config->get($field))) { foreach($config->get($field) as $map) { $map_plugins[$map['label']] = $map['value']; } } $this->{$field} = $map_plugins; } else { $this->{$field} = $config->get($field); } } // Make sure the path is always set // if we don't have one, resort to default value. Loading Loading
rest_oai_pmh.install +17 −0 Original line number Diff line number Diff line Loading @@ -193,3 +193,20 @@ function rest_oai_pmh_update_8005() { $config->set('cache_technique', 'liberal_cache'); $config->save(); } /** * Update storage config to avoid potentially using dots as config keys */ function rest_oai_pmh_update_8006() { $config = \Drupal::service('config.factory')->getEditable('rest_oai_pmh.settings'); $old_map_plugin_config = $config->get('metadata_map_plugins'); $new_map_plugin_config = []; foreach ($old_map_plugin_config as $prefix => $value) { $new_map_plugin_config[] = [ 'label' => $prefix, 'value' => $value, ]; } $config->set('metadata_map_plugins', $new_map_plugin_config); $config->save(); }
src/Form/RestOaiPmhSettingsForm.php +25 −3 Original line number Diff line number Diff line Loading @@ -102,6 +102,20 @@ class RestOaiPmhSettingsForm extends ConfigFormBase { return 'rest_oai_pmh_settings_form'; } private function getMappingConfig(string $metadata_prefix) { $mapping_config = $this->config('rest_oai_pmh.settings') ->get('metadata_map_plugins'); if (!is_array($mapping_config)) { return false; } foreach ($mapping_config as $map) { if ($map['label'] == $metadata_prefix) { return $map['value']; } } return false; } /** * {@inheritdoc} */ Loading Loading @@ -156,14 +170,14 @@ class RestOaiPmhSettingsForm extends ConfigFormBase { foreach (\Drupal::service('plugin.manager.oai_metadata_map')->getDefinitions() as $plugin_id => $plugin_definition) { $mapping_prefix_plugins[$plugin_definition['metadata_format']][$plugin_id] = $plugin_definition['label']->render(); } $mapping_config = $config->get('metadata_map_plugins'); foreach ($mapping_prefix_plugins as $metadata_prefix => $options) { $mapping_config = $this->getMappingConfig($metadata_prefix); $form['mapping'][$metadata_prefix] = [ '#type' => 'select', '#empty_value' => '', '#options' => $options, '#title' => $metadata_prefix, '#default_value' => empty($mapping_config[$metadata_prefix]) ? '' : $mapping_config[$metadata_prefix], '#default_value' => !$mapping_config ? '' : $mapping_config['value'], ]; } Loading Loading @@ -297,9 +311,17 @@ class RestOaiPmhSettingsForm extends ConfigFormBase { } } $mapping = []; foreach ($form_state->getValue('mapping') as $label => $value) { $mapping[] = [ 'label' => $label, 'value' => $value, ]; } $config->set('view_displays', $view_displays) ->set('support_sets', $form_state->getValue('support_sets')) ->set('metadata_map_plugins', $form_state->getValue('mapping')) ->set('metadata_map_plugins', $mapping) ->set('mods_view', $form_state->getValue('view')) ->set('repository_name', $form_state->getValue('repository_name')) ->set('repository_email', $form_state->getValue('repository_email')) Loading
src/Plugin/rest/resource/OaiPmh.php +11 −0 Original line number Diff line number Diff line Loading @@ -108,8 +108,19 @@ class OaiPmh extends ResourceBase { 'metadata_map_plugins', ]; foreach ($fields as $field) { //metadata map plugins are stored in ['label' => label, 'value' => value] format if ($field == 'metadata_map_plugins') { $map_plugins = []; if (is_array($config->get($field))) { foreach($config->get($field) as $map) { $map_plugins[$map['label']] = $map['value']; } } $this->{$field} = $map_plugins; } else { $this->{$field} = $config->get($field); } } // Make sure the path is always set // if we don't have one, resort to default value. Loading