diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6debf9ce..1bb5a546 100644 --- a/CONTRIBUTING.md +++ b/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 diff --git a/composer.json b/composer.json index f1e49024..1cf2d7ee 100644 --- a/composer.json +++ b/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", diff --git a/islandora.module b/islandora.module index 98762248..88db562d 100644 --- a/islandora.module +++ b/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(). */ diff --git a/modules/islandora_breadcrumbs/src/IslandoraBreadcrumbBuilder.php b/modules/islandora_breadcrumbs/src/IslandoraBreadcrumbBuilder.php index 86090ff1..99ff4894 100644 --- a/modules/islandora_breadcrumbs/src/IslandoraBreadcrumbBuilder.php +++ b/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'))); } } diff --git a/modules/islandora_breadcrumbs/tests/src/Functional/BreadcrumbsTest.php b/modules/islandora_breadcrumbs/tests/src/Functional/BreadcrumbsTest.php index 18fa030e..80f5dbee 100644 --- a/modules/islandora_breadcrumbs/tests/src/Functional/BreadcrumbsTest.php +++ b/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('')->toString() => 'Home', + $this->nodeB->toUrl()->toString() => $this->nodeB->label(), + $this->nodeC->toUrl()->toString() => $this->nodeC->label(), + ]; + + $this->assertBreadcrumb($this->nodeD->toUrl()->toString(), $breadcrumbs); } } diff --git a/src/Flysystem/Adapter/FedoraAdapter.php b/src/Flysystem/Adapter/FedoraAdapter.php index 4aebde6e..783a9ed0 100644 --- a/src/Flysystem/Adapter/FedoraAdapter.php +++ b/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, diff --git a/src/Plugin/ContextReaction/JsonldTypeAlterReaction.php b/src/Plugin/ContextReaction/JsonldTypeAlterReaction.php index b2e757ff..0314e4cd 100644 --- a/src/Plugin/ContextReaction/JsonldTypeAlterReaction.php +++ b/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.

+ 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; diff --git a/tests/src/Functional/JsonldTypeAlterReactionTest.php b/tests/src/Functional/JsonldTypeAlterReactionTest.php index ce5aa081..d983e36d 100644 --- a/tests/src/Functional/JsonldTypeAlterReactionTest.php +++ b/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"); diff --git a/tests/src/Kernel/FedoraAdapterTest.php b/tests/src/Kernel/FedoraAdapterTest.php index abff8eea..5d17814d 100644 --- a/tests/src/Kernel/FedoraAdapterTest.php +++ b/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);