fix: lit/divi-dynamic-sources offers no {{link:<ID>}} for attachments (M-9)

Also none for internal post types (post_link_url__et_pb_speculation).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-27 04:20:44 +02:00
co-authored by Claude Opus 5.5
parent 1c2acdfbbe
commit ae994ad7bd
2 changed files with 24 additions and 1 deletions
@@ -205,7 +205,14 @@ final class DiviDynamicSourcesAbility implements Ability
return '{{post:' . $post . '}}';
}
return str_starts_with($name, 'post_link_url_') ? '{{link:<ID>}}' : null;
if (! str_starts_with($name, 'post_link_url_')) {
return null;
}
// Review M-9: {{link:}} refuses attachments (status inherit); internal types ("_…") are no link targets.
$type = substr($name, strlen('post_link_url_'));
return $type === 'attachment' || str_starts_with($type, '_') ? null : '{{link:<ID>}}';
}
/**
@@ -80,6 +80,22 @@ final class DiviDynamicSourcesAbilityTest extends TestCase
self::assertSame('lit/divi-dynamic-sources', $this->ability()->name());
}
/** Review M-9: {{link:}} refuses attachments (status inherit), so their link sources get no hint. */
public function testNoLinkHintForAttachmentsOrInternalTypes(): void
{
$registry = DiviFixtures::dynamicContentRegistry();
foreach (['post_link_url_attachment', 'post_link_url__et_pb_speculation'] as $name) {
$registry[$name] = $registry['post_link_url_page'];
$registry[$name]['id'] = $name;
}
$sources = array_column($this->ability([], 'meta', $registry)->execute(['post_type' => 'page'])['sources'], null, 'name');
self::assertSame('{{link:<ID>}}', $sources['post_link_url_page']['placeholder']);
self::assertNull($sources['post_link_url_attachment']['placeholder']);
self::assertNull($sources['post_link_url__et_pb_speculation']['placeholder']);
}
public function testOffersTextLikeFieldsAndNamesTheOthers(): void
{
$result = $this->ability()->execute(['post_type' => 'page']);