Browse Source

initial commit

pull/907/head
Alan Stanley 7 years ago
commit
693b0382ba
  1. 14
      composer.json
  2. 7
      islandora_fits.info.yml
  3. 24
      islandora_fits.module
  4. 58
      src/Plugin/Action/GenerateFitsDerivative.php
  5. 46
      tests/src/Functional/LoadTest.php

14
composer.json

@ -0,0 +1,14 @@
{
"name": "drupal/islandora_fits",
"type": "drupal-module",
"description": "Enables Technical Metadata derivative generation",
"keywords": ["Drupal"],
"license": "GPL-2.0+",
"homepage": "https://www.drupal.org/project/islandora_fits",
"minimum-stability": "dev",
"support": {
"issues": "https://www.drupal.org/project/issues/islandora_fits",
"source": "http://cgit.drupalcode.org/islandora_fits"
},
"require": { }
}

7
islandora_fits.info.yml

@ -0,0 +1,7 @@
name: 'Islandora Fits'
type: module
description: 'Enables Technical Metadata derivative generation'
core: 8.x
package: 'Custom'
dependencies:
- islandora

24
islandora_fits.module

@ -0,0 +1,24 @@
<?php
/**
* @file
* Contains islandora_fits.module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function islandora_fits_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the islandora_fits module.
case 'help.page.islandora_fits':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Enables Technical Metadata derivative generation') . '</p>';
return $output;
default:
}
}

58
src/Plugin/Action/GenerateFitsDerivative.php

@ -0,0 +1,58 @@
<?php
namespace Drupal\islandora_fits\Plugin\Action;
use Drupal\Core\Form\FormStateInterface;
use Drupal\islandora\Plugin\Action\AbstractGenerateDerivative;
/**
* Emits a Node for generating fits derivatives event.
*
* @Action(
* id = "generate_fits_derivative",
* label = @Translation("Generate a Technical metadata derivative"),
* type = "node"
* )
*/
class GenerateFitsDerivative extends AbstractGenerateDerivative {
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
$config = parent::defaultConfiguration();
$config['path'] = '[date:custom:Y]-[date:custom:m]/[node:nid]-[term:name].xml';
$config['mimetype'] = 'application/xml';
$config['queue'] = 'islandora-connector-fits';
$config['destination_media_type'] = 'file';
return $config;
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
$form['mimetype']['#description'] = t('Mimetype to convert to (e.g. application/xml, etc...)');
$form['mimetype']['#value'] = 'application/xml';
$form['mimetype']['#type'] = 'hidden';
unset($form['args']);
return $form;
}
/**
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
parent::validateConfigurationForm($form, $form_state);
$exploded_mime = explode('/', $form_state->getValue('mimetype'));
if ($exploded_mime[0] != 'application') {
$form_state->setErrorByName(
'mimetype',
t('Please enter file mimetype (e.g. application/xml.)')
);
}
}
}

46
tests/src/Functional/LoadTest.php

@ -0,0 +1,46 @@
<?php
namespace Drupal\Tests\islandora_fits\Functional;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
/**
* Simple test to ensure that main page loads with module enabled.
*
* @group islandora_fits
*/
class LoadTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['islandora_fits'];
/**
* A user with permission to administer site configuration.
*
* @var \Drupal\user\UserInterface
*/
protected $user;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->user = $this->drupalCreateUser(['administer site configuration']);
$this->drupalLogin($this->user);
}
/**
* Tests that the home page loads with a 200 response.
*/
public function testLoad() {
$this->drupalGet(Url::fromRoute('<front>'));
$this->assertSession()->statusCodeEquals(200);
}
}
Loading…
Cancel
Save