Normalize alt-text null checks across publishers

Use an explicit `!== null` guard in the Facebook, Instagram, Threads, and
Discord publishers instead of a truthy `if ($alt = ...)`, matching the
Pinterest/X/Mastodon style. The truthy form dropped a literal "0" alt; the
explicit check treats every non-null description uniformly. Also add the
missing PHPDoc to Platform::supportsAltText().
This commit is contained in:
Paulo Castellano 2026-07-11 10:02:50 -03:00
parent 8d7948cb2e
commit 0e93d7e5e3
5 changed files with 25 additions and 7 deletions

View file

@ -149,6 +149,10 @@ public function altTextMaxLength(): ?int
};
}
/**
* Whether the platform's API accepts image alt text (accessibility
* description) on published media.
*/
public function supportsAltText(): bool
{
return $this->altTextMaxLength() !== null;

View file

@ -129,7 +129,9 @@ private function sendWithMedia(string $channelId, array $payload, Collection $me
$attachment = ['id' => $index, 'filename' => $filename];
if ($alt = $item->altText()) {
$alt = $item->altText();
if ($alt !== null) {
$attachment['description'] = mb_substr($alt, 0, Platform::Discord->altTextMaxLength());
}

View file

@ -136,7 +136,9 @@ private function publishSingleImagePost(string $pageId, string $accessToken, ?st
$payload['message'] = $content;
}
if ($alt = $this->altFor($media)) {
$alt = $this->altFor($media);
if ($alt !== null) {
$payload['alt_text_custom'] = $alt;
}
@ -175,7 +177,9 @@ private function publishMultiImagePost(string $pageId, string $accessToken, ?str
'access_token' => $accessToken,
];
if ($alt = $this->altFor($media)) {
$alt = $this->altFor($media);
if ($alt !== null) {
$uploadPayload['alt_text_custom'] = $alt;
}

View file

@ -89,7 +89,9 @@ private function publishSingleImage(string $instagramId, string $accessToken, ?s
'access_token' => $accessToken,
];
if ($alt = $this->altFor($media)) {
$alt = $this->altFor($media);
if ($alt !== null) {
$params['alt_text'] = $alt;
}
@ -215,7 +217,9 @@ private function publishCarousel(string $instagramId, string $accessToken, ?stri
} else {
$params['image_url'] = $this->cropImageForAspectRatio($media->url, $aspectRatio);
if ($alt = $this->altFor($media)) {
$alt = $this->altFor($media);
if ($alt !== null) {
$params['alt_text'] = $alt;
}
}

View file

@ -109,7 +109,9 @@ private function publishImagePost(string $userId, string $accessToken, ?string $
'access_token' => $accessToken,
];
if ($alt = $this->altFor($media)) {
$alt = $this->altFor($media);
if ($alt !== null) {
$params['alt_text'] = $alt;
}
@ -193,7 +195,9 @@ private function publishCarousel(string $userId, string $accessToken, ?string $c
$params['media_type'] = 'IMAGE';
$params['image_url'] = $media->url;
if ($alt = $this->altFor($media)) {
$alt = $this->altFor($media);
if ($alt !== null) {
$params['alt_text'] = $alt;
}
}