Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add contrib hal and rdf to composer. Also fix deprecated code. #70

Merged
merged 5 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-2.x.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
strategy:
matrix:
php-versions: ["7.4", "8.0", "8.1"]
drupal-version: ["9.3.x", "9.4.x", "9.5.x-dev"]
drupal-version: ["9.4.x", "9.5.x"]

env:
DRUPAL_VERSION: ${{ matrix.drupal-version }}
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
}
],
"require" : {
"php": ">=7.4"
"php": ">=7.4",
"drupal/hal": "^1||^2",
"drupal/rdf": "^2.1"
},
"require-dev": {
"phpunit/phpunit": "^8",
Expand Down
8 changes: 4 additions & 4 deletions jsonld.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: 'JSON-LD'
type: module
description: 'Serializes entities to JSON-LD / LDP for the Islandora Project'
package: Web services
core_version_requirement: ^9
core_version_requirement: ^9.4
dependencies:
- hal
- serialization
- rdf
- drupal:serialization
- hal:hal
- rdf:rdf
7 changes: 3 additions & 4 deletions src/ContextGenerator/JsonldContextGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,8 @@ protected function getTermContextFromField($field_type) {
// yet for this instance.
if (empty($this->fieldMappings)) {
// Cribbed from rdf module's rdf_get_namespaces.
foreach (\Drupal::moduleHandler()->getImplementations(self::FIELD_MAPPPINGS_HOOK) as $module) {
$function = $module . '_' . self::FIELD_MAPPPINGS_HOOK;
foreach ($function() as $field => $mapping) {
\Drupal::moduleHandler()->invokeAllWith(self::FIELD_MAPPPINGS_HOOK, function (callable $hook, string $module) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kinda surprised that phpcs isn't complaining about the lack of DI here, but... looks like it might only be from the DrupalPractice suite (that we don't presently run, but possibly should?):

 336 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
     |         |     (DrupalPractice.Objects.GlobalDrupal.GlobalDrupal)

... s'yeah, can ignore. 👍

foreach ($hook() as $field => $mapping) {
if (array_key_exists($field, $this->fieldMappings)) {
$this->logger->warning(
t('Tried to map @field_type to @new_type, but @field_type is already mapped to @orig_type.', [
Expand All @@ -349,7 +348,7 @@ protected function getTermContextFromField($field_type) {
$this->fieldMappings[$field] = $mapping;
}
}
}
});
}
return array_key_exists($field_type, $this->fieldMappings) ? $this->fieldMappings[$field_type] : $default_mapping;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/src/Functional/JsonldContextGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function testJsonldcontextContentypeheaderResponseIsValid() {
);
$this->drupalGet($url);
$this->assertSession()->statusCodeEquals(200);
$this->assertEquals($this->drupalGetHeader('Content-Type'), 'application/ld+json', 'Correct JSON-LD mime type was returned');
$this->assertEquals($this->getSession()->getResponseHeader('Content-Type'), 'application/ld+json', 'Correct JSON-LD mime type was returned');
}

/**
Expand All @@ -121,7 +121,7 @@ public function testJsonldcontextResponseIsValid() {
$this->drupalGet($url);
$this->assertSession()->statusCodeEquals(200);
$jsonldarray = json_decode($this->getSession()->getPage()->getContent(), TRUE);
$this->verbose($jsonldarray);
dump($jsonldarray);
$this->assertEquals($expected, $jsonldarray, "Returned @context matches expected response.");
}

Expand Down
2 changes: 1 addition & 1 deletion tests/src/Kernel/JsonldContextGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class JsonldContextGeneratorTest extends JsonldKernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = [
protected static $modules = [
'entity_test',
'hal',
'jsonld',
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Kernel/JsonldHookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class JsonldHookTest extends JsonldKernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = [
protected static $modules = [
'entity_test',
'hal',
'jsonld',
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Kernel/JsonldKernelTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ abstract class JsonldKernelTestBase extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = [
protected static $modules = [
'system',
'user',
'field',
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Kernel/JsonldTestEntityGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function makeDuplicateReferenceMapping(): JsonldTestEntityGenerator {
* Error saving the entity.
*/
public function generateNewEntity(): array {
$dt = new \DateTime(NULL, new \DateTimeZone('UTC'));
$dt = new \DateTime('now', new \DateTimeZone('UTC'));
$created = $dt->format("U");
$created_iso = $dt->format(\DateTime::W3C);
// Create an entity.
Expand Down