Skip to content

Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.

Add MediaItem::altText() accessor for per-image alt text

Paulo Castellano603ac84b5f0e
diff --git a/app/DataTransferObjects/MediaItem.php b/app/DataTransferObjects/MediaItem.php
index 2e0abedee..a81b0ae76 100644
--- a/app/DataTransferObjects/MediaItem.php
+++ b/app/DataTransferObjects/MediaItem.php
@@ -59,6 +59,22 @@ class MediaItem
return is_numeric($height) ? (int) $height : null;
}
+ /**
+ * User-provided accessibility description for this image, when set.
+ */
+ public function altText(): ?string
+ {
+ $alt = data_get($this->meta, 'alt_text');
+
+ if (! is_string($alt)) {
+ return null;
+ }
+
+ $alt = trim($alt);
+
+ return $alt === '' ? null : $alt;
+ }
+
/**
* @param array<string, mixed> $data
*/
diff --git a/tests/Unit/MediaItemAltTextTest.php b/tests/Unit/MediaItemAltTextTest.php
new file mode 100644
index 000000000..599db8241
--- /dev/null
+++ b/tests/Unit/MediaItemAltTextTest.php
@@ -0,0 +1,16 @@
+<?php
+
+declare(strict_types=1);
+
+use App\DataTransferObjects\MediaItem;
+
+test('altText returns the trimmed meta alt_text', function () {
+ $item = MediaItem::fromArray(['id' => 'a', 'path' => 'p.jpg', 'url' => 'u', 'meta' => ['alt_text' => ' a cat ']]);
+
+ expect($item->altText())->toBe('a cat');
+});
+
+test('altText is null when meta has no alt_text or it is blank', function () {
+ expect(MediaItem::fromArray(['id' => 'a', 'path' => 'p.jpg', 'url' => 'u'])->altText())->toBeNull()
+ ->and(MediaItem::fromArray(['id' => 'a', 'path' => 'p.jpg', 'url' => 'u', 'meta' => ['alt_text' => ' ']])->altText())->toBeNull();
+});