Commit 8bc49177 authored by João Machado's avatar João Machado

first draft for ORCID importer

parent 0bf4c503
Pipeline #1311 passed with stage
in 4 minutes and 14 seconds
......@@ -36,7 +36,6 @@
"type": "package",
"package": {
"name": "dinbror/blazy",
<<<<<<< HEAD
"version": "1.8.2",
"type": "drupal-library",
"extra": {
......@@ -46,13 +45,6 @@
"type": "git",
"url": "https://github.com/dinbror/blazy",
"reference": "1.8.2"
=======
"version": "master",
"type": "drupal-library",
"dist": {
"url": "https://github.com/dinbror/blazy/archive/master.zip",
"type": "zip"
>>>>>>> udpated core; added blazy library to composer
}
}
}
......
This diff is collapsed.
This diff is collapsed.
{
"name": "drupal/orcid_import",
"description": "This module intends to provide a basic ORCID data import feature for websites using the Bibliography & Citation (bibcite) module.",
"type": "drupal-module",
"homepage": "http://drupal.org/project/orcid_import",
"authors": [
{
"name": "joum",
"email": "joum@3462349.no-reply.drupal.org"
}
],
"require": {
"php": ">=5.6.0",
"drupal/bibcite": "1.x-dev"
},
"support": {
"issues": "http://drupal.org/project/orcid_import",
"irc": "irc://irc.freenode.org/drupal-contribute",
"source": "http://cgit.drupalcode.org/orcid_import"
},
"minimum-stability": "dev"
}
\ No newline at end of file
name: ORCID Import
description: Import Bibliography & Citations data from ORCID
core: 8.x
type: module
package: Omibee
dependencies:
- bibcite
configure: orcid_import.settings
orcid_import.admin_config_orcid_import:
title: 'ORCID Import'
parent: system.admin_config
route_name: orcid_import.admin_config_orcid_import
weight: 100
orcid_import.admin_settings:
title: 'Configuration'
parent: orcid_import.admin_config_orcid_import
route_name: orcid_import.admin_settings
orcid_import.admin_config_orcid_import:
path: '/admin/orcid_import'
defaults:
_controller: '\Drupal\system\Controller\SystemController::systemAdminMenuBlockPage'
_title: 'ORCID Import'
requirements:
_permission: 'Administer ORCID Import'
options:
_admin_route: TRUE
orcid_import.admin_settings:
path: '/admin/orcid_import/config'
defaults:
_form: '\Drupal\orcid_import\Form\ModuleConfigurationForm'
_title: 'ORCID Import configuration'
requirements:
_permission: 'Administer ORCID configuration'
services:
orcid_import.importer:
class: Drupal\orcid_import\Model\Import
arguments: ["user_orcid"]
<?php
namespace Drupal\orcid_import\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Defines orcid_import configuration form.
*/
class ModuleConfigurationForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'orcid_import_admin_settings';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'orcid_import.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('orcid_import.settings');
// HTML element with instructions
$form['orcid_instructions'] = [
"#markup" => $this->t("You need ORCID API credentials to be able to import ORCID data for your users. <br>You can register your application <a href='https://orcid.org/developer-tools' target='_blank'>here</a>."),
];
// ORCID Client ID
$form['orcid_client_id'] = [
'#type' => 'textfield',
'#title' => $this->t('ORCID Client ID'),
'#default_value' => empty($config->get('orcid_client_id')) ? 'APP-XXXXXXXXXXXXXXXX' : $config->get('orcid_client_id'),
];
// ORCID Client secret
$form['orcid_client_secret'] = [
'#type' => 'textfield',
'#title' => $this->t('ORCID Client Secret'),
'#default_value' => empty($config->get('orcid_client_secret')) ? 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX' : $config->get('orcid_client_secret'),
];
// ORCID Client password ???
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state->getValues();
$this->config('orcid_import.settings')
->set('orcid_client_id', $values['orcid_client_id'])
->set('orcid_client_secret', $values['orcid_client_secret'])
->save();
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$values = $form_state->getValues();
// test current ORCID API settings
// client id exists?
if (empty($values['orcid_client_id']) ) {
$form_state->setError($form['orcid_client_id'], $this->t("An ORCID Client ID is required. Follow instructions above to obtain one."));
}
// client secret exists?
else if (empty($values['orcid_client_secret']) ) {
$form_state->setError($form['orcid_client_secret'], $this->t("An ORCID Client Secret is required. Follow instructions above to obtain one."));
}
// do we really need API access? For what?
parent::validateForm($form, $form_state);
}
}
\ No newline at end of file
<?php
namespace Drupal\orcid_import\Services;
/**
* Class OrcidImporter.
*/
class OrcidImporter
{
/**
* Watchdog channel to be used when logging activity.
*/
const LOG_CHANNEL = 'orcid_import';
public function __construct($user_orcid)
{
$this->user_orcid = $user_orcid;
}
/**
* Fetches data from ORCID and populates Bibcite Entities
*
* @return mixed
* Number of Bibcite entities created and/or updated
*/
public function importOrcidData()
{
//Do something here to get any data.
\Drupal::logger(self::LOG_CHANNEL)->notice("Fetching ORCID data for user: " . $this->user_orcid);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment