From c8453af4a2dd979e42acaf1947e2be26f1484618 Mon Sep 17 00:00:00 2001 From: Christian Einvik Date: Wed, 29 Oct 2025 13:13:54 +0100 Subject: [PATCH] Edlib GH #3162: Add fields for ContentType and ContentTypeName --- .../DeepLinking/EdlibContentItemMapper.php | 2 ++ .../Edlib/DeepLinking/EdlibLtiLinkItem.php | 30 +++++++++++++++++++ .../EdlibLtiLinkItemSerializer.php | 8 +++++ .../Lti/Edlib/EdlibContentItemMapperTest.php | 4 +++ .../Edlib/EdlibContentItemsSerializerTest.php | 8 +++++ 5 files changed, 52 insertions(+) diff --git a/src/Lti/Edlib/DeepLinking/EdlibContentItemMapper.php b/src/Lti/Edlib/DeepLinking/EdlibContentItemMapper.php index 7d4e2bb..3acdd37 100644 --- a/src/Lti/Edlib/DeepLinking/EdlibContentItemMapper.php +++ b/src/Lti/Edlib/DeepLinking/EdlibContentItemMapper.php @@ -40,6 +40,8 @@ public function map(array $data): ContentItem ->withShared(Prop::getOfType($data, 'shared', Prop::TYPE_BOOLEAN)) ->withTags(Prop::getArrayOfType($data, 'tag', Prop::TYPE_NORMALIZED_STRING)) ->withOwnerEmail(Prop::getOfType($data, 'ownerEmail', Prop::TYPE_NORMALIZED_STRING)) + ->withContentType(Prop::getOfType($data, 'contentType', Prop::TYPE_NORMALIZED_STRING)) + ->withContentTypeName(Prop::getOfType($data, 'contentTypeName', Prop::TYPE_NORMALIZED_STRING)) ; } diff --git a/src/Lti/Edlib/DeepLinking/EdlibLtiLinkItem.php b/src/Lti/Edlib/DeepLinking/EdlibLtiLinkItem.php index ccc92ec..440808f 100644 --- a/src/Lti/Edlib/DeepLinking/EdlibLtiLinkItem.php +++ b/src/Lti/Edlib/DeepLinking/EdlibLtiLinkItem.php @@ -22,6 +22,10 @@ class EdlibLtiLinkItem extends LtiLinkItem private string|null $ownerEmail = null; + private string|null $contentType = null; + + private string|null $contentTypeName = null; + /** * @var list */ @@ -123,4 +127,30 @@ public function withOwnerEmail(string|null $email): static return $self; } + + public function getContentType(): string|null + { + return $this->contentType; + } + + public function withContentType(string|null $type): static + { + $self = clone $this; + $self->contentType = $type; + + return $self; + } + + public function getContentTypeName(): string|null + { + return $this->contentTypeName; + } + + public function withContentTypeName(string|null $name): static + { + $self = clone $this; + $self->contentTypeName = $name; + + return $self; + } } diff --git a/src/Lti/Edlib/DeepLinking/EdlibLtiLinkItemSerializer.php b/src/Lti/Edlib/DeepLinking/EdlibLtiLinkItemSerializer.php index 93a11fc..de6cad9 100644 --- a/src/Lti/Edlib/DeepLinking/EdlibLtiLinkItemSerializer.php +++ b/src/Lti/Edlib/DeepLinking/EdlibLtiLinkItemSerializer.php @@ -49,6 +49,14 @@ public function serialize(LtiLinkItem $item): array if ($item->getOwnerEmail() !== null) { $serialized['ownerEmail'] = $item->getOwnerEmail(); } + + if ($item->getContentType() !== null) { + $serialized['contentType'] = $item->getContentType(); + } + + if ($item->getContentTypeName() !== null) { + $serialized['contentTypeName'] = $item->getContentTypeName(); + } } return $serialized; diff --git a/tests/Lti/Edlib/EdlibContentItemMapperTest.php b/tests/Lti/Edlib/EdlibContentItemMapperTest.php index 24aee1e..270d2e5 100644 --- a/tests/Lti/Edlib/EdlibContentItemMapperTest.php +++ b/tests/Lti/Edlib/EdlibContentItemMapperTest.php @@ -35,6 +35,8 @@ public function testMapsEdlibExtensions(): void 'shared' => false, 'tag' => 'foo', 'ownerEmail' => 'owner@example.com', + 'contentType' => 'fake.fancy_content', + 'contentTypeName' => 'FancyContent', ], ], ]); @@ -50,6 +52,8 @@ public function testMapsEdlibExtensions(): void $this->assertTrue($items[0]->isPublished()); $this->assertSame(['foo'], $items[0]->getTags()); $this->assertSame('owner@example.com', $items[0]->getOwnerEmail()); + $this->assertSame('fake.fancy_content', $items[0]->getContentType()); + $this->assertSame('FancyContent', $items[0]->getContentTypeName()); } public function testMapsMultipleTags(): void diff --git a/tests/Lti/Edlib/EdlibContentItemsSerializerTest.php b/tests/Lti/Edlib/EdlibContentItemsSerializerTest.php index 18e6663..efcc360 100644 --- a/tests/Lti/Edlib/EdlibContentItemsSerializerTest.php +++ b/tests/Lti/Edlib/EdlibContentItemsSerializerTest.php @@ -28,6 +28,8 @@ public function testAddsJsonldContextAndSerializesEdlibExtensions(): void ->withShared(true) ->withTags(['foo']) ->withOwnerEmail('owner@example.com') + ->withContentType('fake.fancy_content') + ->withContentTypeName('FancyContent') ]); $this->assertArrayHasKey('@context', $data); @@ -65,6 +67,12 @@ public function testAddsJsonldContextAndSerializesEdlibExtensions(): void $this->assertArrayHasKey('ownerEmail', $data['@graph'][0]); $this->assertSame('owner@example.com', $data['@graph'][0]['ownerEmail']); + + $this->assertArrayHasKey('contentType', $data['@graph'][0]); + $this->assertSame('fake.fancy_content', $data['@graph'][0]['contentType']); + + $this->assertArrayHasKey('contentTypeName', $data['@graph'][0]); + $this->assertSame('FancyContent', $data['@graph'][0]['contentTypeName']); } public function testSerializesMultipleTags(): void