Browse Source

Merge branch '8.x-1.x' into media_multifile

pull/756/head
Alan Stanley 5 years ago committed by GitHub
parent
commit
88dff7c19d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      CONTRIBUTING.md
  2. 1
      composer.json
  3. 45
      islandora.module
  4. 2
      modules/islandora_breadcrumbs/src/IslandoraBreadcrumbBuilder.php
  5. 12
      modules/islandora_breadcrumbs/tests/src/Functional/BreadcrumbsTest.php
  6. 27
      src/Flysystem/Adapter/FedoraAdapter.php
  7. 8
      src/Plugin/ContextReaction/JsonldTypeAlterReaction.php
  8. 2
      tests/src/Functional/JsonldTypeAlterReactionTest.php
  9. 15
      tests/src/Kernel/FedoraAdapterTest.php

2
CONTRIBUTING.md

@ -8,7 +8,7 @@ Please note that this project operates under the [Islandora Community Code of Co
## Workflows
The group meets each Wednesday at 1:00 PM Eastern. Meeting notes and announcements are posted to the [Islandora community list](https://groups.google.com/forum/#!forum/islandora) and the [Islandora developers list](https://groups.google.com/forum/#!forum/islandora-dev). You can view meeting agendas, notes, and call-in information [here](https://github.com/Islandora/documentation/wiki#islandora-8-tech-calls). Anybody is welcome to join the calls, and add items to the agenda.
The Islandora 8 Tech Call meets each Wednesday at 1:00 PM Eastern, and the Islandora 8 User Call meets every second Thursday at 1:00 PM Eastern. Meeting notes and announcements are posted to the [Islandora community list](https://groups.google.com/forum/#!forum/islandora) and the [Islandora developers list](https://groups.google.com/forum/#!forum/islandora-dev). You can view meeting agendas, notes, and call-in information [here](https://github.com/Islandora/documentation/wiki#islandora-8-tech-calls). Anybody is welcome to join the calls, and add items to the agenda.
### Use cases

1
composer.json

@ -31,6 +31,7 @@
"islandora/crayfish-commons": "dev-dev",
"drupal/hook_post_action" : "^1.0"
"drupal/file_replace": "^1.1",
},
"require-dev": {
"phpunit/phpunit": "^6",

45
islandora.module

@ -328,6 +328,51 @@ function islandora_preprocess_node(&$variables) {
}
}
/**
* Implements hook_form_alter().
*/
function islandora_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$media_add_forms = ['media_audio_add_form', 'media_document_add_form',
'media_extracted_text_add_form', 'media_file_add_form', 'media_image_add_form',
'media_fits_technical_metadata_add_form', 'media_video_add_form',
];
if (in_array($form['#form_id'], $media_add_forms)) {
$params = \Drupal::request()->query->all();
if (isset($params['edit'])) {
$media_of_nid = $params['edit']['field_media_of']['widget'][0]['target_id'];
$node = \Drupal::entityTypeManager()->getStorage('node')->load($media_of_nid);
if ($node) {
$form['name']['widget'][0]['value']['#default_value'] = $node->getTitle();
}
}
}
}
/**
* Implements hook_field_widget_WIDGET_TYPE_form_alter().
*/
function islandora_field_widget_image_image_form_alter(&$element, $form_state, $context) {
$element['#process'][] = 'islandora_add_default_image_alt_text';
}
/**
* Callback for hook_field_widget_WIDGET_TYPE_form_alter().
*/
function islandora_add_default_image_alt_text($element, $form_state, $form) {
if ($element['alt']['#access']) {
$params = \Drupal::request()->query->all();
if (isset($params['edit'])) {
$media_of_nid = $params['edit']['field_media_of']['widget'][0]['target_id'];
$node = \Drupal::entityTypeManager()->getStorage('node')->load($media_of_nid);
if ($node) {
$element['alt']['#default_value'] = $node->getTitle();
}
}
}
return $element;
}
/**
* Implements hook_entity_form_display_alter().
*/

2
modules/islandora_breadcrumbs/src/IslandoraBreadcrumbBuilder.php

@ -54,7 +54,7 @@ class IslandoraBreadcrumbBuilder implements BreadcrumbBuilderInterface {
$nid = $attributes->getRawParameters()->get('node');
if (!empty($nid)) {
$node = $this->nodeStorage->load($nid);
return (!empty($node) && $node->hasField($this->config->get('referenceField')) && !$node->get($this->config->get('referenceField'))->isEmpty());
return (!empty($node) && $node->hasField($this->config->get('referenceField')));
}
}

12
modules/islandora_breadcrumbs/tests/src/Functional/BreadcrumbsTest.php

@ -114,6 +114,18 @@ class BreadcrumbsTest extends IslandoraFunctionalTestBase {
// We should still escape it and have the same trail as before.
$this->assertBreadcrumb($this->nodeD->toUrl()->toString(), $breadcrumbs);
// Delete 'A', removing it from the chain.
$this->nodeA->delete();
// The new breadcrumb chain without 'A'.
$breadcrumbs = [
Url::fromRoute('<front>')->toString() => 'Home',
$this->nodeB->toUrl()->toString() => $this->nodeB->label(),
$this->nodeC->toUrl()->toString() => $this->nodeC->label(),
];
$this->assertBreadcrumb($this->nodeD->toUrl()->toString(), $breadcrumbs);
}
}

27
src/Flysystem/Adapter/FedoraAdapter.php

@ -11,6 +11,7 @@ use GuzzleHttp\Psr7;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Psr7\StreamWrapper;
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface;
use DateTime;
/**
* Fedora adapter for Flysystem.
@ -252,6 +253,32 @@ class FedoraAdapter implements AdapterInterface {
$headers = [
'Content-Type' => $this->mimeTypeGuesser->guess($path),
];
if ($this->has($path)) {
$fedora_url = $path;
$date = new DateTime();
$timestamp = $date->format("D, d M Y H:i:s O");
// Create version in Fedora.
try {
$response = $this->fedora->createVersion(
$fedora_url,
$timestamp,
NULL,
$headers
);
if (isset($response) && $response->getStatusCode() == 201) {
\Drupal::logger('fedora_flysystem')->info('Created a version in Fedora for ' . $fedora_url);
}
else {
\Drupal::logger('fedora_flysystem')->error(
"Client error: `Failed to create a Fedora version of $fedora_url`. Response is " . print_r($response, TRUE)
);
}
}
catch (\Exception $e) {
\Drupal::logger('fedora_flysystem')->error('Caught exception when creating version: ' . $e->getMessage() . "\n");
}
}
$response = $this->fedora->saveResource(
$path,

8
src/Plugin/ContextReaction/JsonldTypeAlterReaction.php

@ -89,9 +89,13 @@ class JsonldTypeAlterReaction extends NormalizerAlterReaction {
$config = $this->getConfiguration();
$form['source_field'] = [
'#type' => 'select',
'#title' => $this->t('Source Field'),
'#title' => $this->t('Field containing RDF type information'),
'#options' => $options,
'#description' => $this->t("Select the field containing the type predicates."),
'#description' => $this->t("Use a field to determine the rdf:type. <br/><br/>
In JSON-LD representations, the @type attribute (shorthand for rdf:type) will
be populated from the value of this field, rather than the default for the bundle
as configured in the bundle's RDF mapping. If this field is an entity reference
field, the value of the referenced entity's `field_external_uri` will be used."),
'#default_value' => isset($config['source_field']) ? $config['source_field'] : '',
];
return $form;

2
tests/src/Functional/JsonldTypeAlterReactionTest.php

@ -65,7 +65,7 @@ class JsonldTypeAlterReactionTest extends JsonldSelfReferenceReactionTest {
$this->drupalGet("admin/structure/context/$context_name");
$this->getSession()->getPage()
->fillField("Source Field", "field_type_predicate");
->fillField("Field containing RDF type information", "field_type_predicate");
$this->getSession()->getPage()->pressButton("Save and continue");
$this->assertSession()
->pageTextContains("The context $context_name has been saved");

15
tests/src/Kernel/FedoraAdapterTest.php

@ -84,6 +84,10 @@ class FedoraAdapterTest extends IslandoraKernelTestBase {
protected function createAdapterForWrite() {
$fedora_prophecy = $this->prophesize(IFedoraApi::class);
$prophecy = $this->prophesize(Response::class);
$prophecy->getStatusCode()->willReturn(201);
$fedora_prophecy->createVersion('', Argument::any(), NULL,
Argument::any())->willReturn($prophecy->reveal());
$prophecy = $this->prophesize(Response::class);
$prophecy->getStatusCode()->willReturn(201);
@ -111,6 +115,9 @@ class FedoraAdapterTest extends IslandoraKernelTestBase {
*/
protected function createAdapterForWriteFail() {
$fedora_prophecy = $this->prophesize(IFedoraApi::class);
$prophecy = $this->prophesize(Response::class);
$prophecy->getStatusCode()->willReturn(500);
$fedora_prophecy->getResourceHeaders('')->willReturn($prophecy->reveal());
$prophecy = $this->prophesize(Response::class);
$prophecy->getStatusCode()->willReturn(500);
@ -562,6 +569,14 @@ class FedoraAdapterTest extends IslandoraKernelTestBase {
$prophecy->getStatusCode()->willReturn(201);
$response = $prophecy->reveal();
$date = new \DateTime();
$timestamp = $date->format("D, d M Y H:i:s O");
$fedora_prophecy->createVersion('',
Argument::any(), NULL,
Argument::any())->willReturn($prophecy->reveal());
$prophecy = $this->prophesize(Response::class);
$prophecy->getStatusCode()->willReturn(201);
$fedora_prophecy->saveResource(Argument::any(), Argument::any(), Argument::any())->willReturn($response);
$prophecy = $this->prophesize(Response::class);

Loading…
Cancel
Save