-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NEW Default link title for each link type
- Loading branch information
Sabina Talipova
committed
Nov 30, 2023
1 parent
64f5829
commit 6bd80b6
Showing
12 changed files
with
248 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
<a href="$URL" <% if $OpenInNew %>target="_blank" rel="noopener noreferrer"<% end_if %>>$Title</a> | ||
<a href="$URL" <% if $OpenInNew %>target="_blank" rel="noopener noreferrer"<% end_if %>> | ||
$Title | ||
<% if $DefaultTitle %> $DefaultTitle <% end_if %> | ||
</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace SilverStripe\LinkField\Tests\Models\Extensions; | ||
|
||
use SilverStripe\Dev\TestOnly; | ||
use SilverStripe\ORM\DataExtension; | ||
|
||
class ExternalLinkExtension extends DataExtension implements TestOnly | ||
{ | ||
public function updateDefaultLinkTitle(&$defaultLinkTitle): void | ||
{ | ||
$defaultLinkTitle = sprintf('External Link: %s', $this->owner->getURL()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
use SilverStripe\ORM\DataObject; | ||
use SilverStripe\ORM\ValidationException; | ||
use SilverStripe\Versioned\Versioned; | ||
use SilverStripe\LinkField\Tests\Models\Extensions\ExternalLinkExtension; | ||
|
||
class LinkTest extends SapphireTest | ||
{ | ||
|
@@ -28,6 +29,12 @@ class LinkTest extends SapphireTest | |
*/ | ||
protected static $fixture_file = 'LinkTest.yml'; | ||
|
||
protected static $required_extensions = [ | ||
ExternalLink::class => [ | ||
ExternalLinkExtension::class, | ||
], | ||
]; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
@@ -329,4 +336,112 @@ public function linkUrlCasesDataProvider(): array | |
], | ||
]; | ||
} | ||
|
||
function linkDefaultTitleDataProvider(): array | ||
{ | ||
return [ | ||
'page link' => [ | ||
'page-link-1', | ||
SiteTreeLink::class, | ||
true, | ||
'' | ||
], | ||
'email link' => [ | ||
'email-link-with-email', | ||
EmailLink::class, | ||
true, | ||
'' | ||
], | ||
'external link' => [ | ||
'external-link-with-url', | ||
ExternalLink::class, | ||
true, | ||
'' | ||
], | ||
'phone link' => [ | ||
'phone-link-with-phone', | ||
PhoneLink::class, | ||
true, | ||
'' | ||
], | ||
'file link' => [ | ||
'file-link-no-image', | ||
FileLink::class, | ||
true, | ||
'' | ||
], | ||
'page link with default title' => [ | ||
'page-link-with-default-title', | ||
SiteTreeLink::class, | ||
true, | ||
'' | ||
], | ||
'email link with default title' => [ | ||
'email-link-with-default-title', | ||
EmailLink::class, | ||
true, | ||
'[email protected]' | ||
], | ||
'external link with default title' => [ | ||
'external-link-with-default-title', | ||
ExternalLink::class, | ||
true, | ||
'External Link: https://google.com' | ||
], | ||
'phone link with default title' => [ | ||
'phone-link-with-default-title', | ||
PhoneLink::class, | ||
true, | ||
'+64 4 978 7330' | ||
], | ||
'file link with default title' => [ | ||
'file-link-with-default-title', | ||
FileLink::class, | ||
true, | ||
'600x400.png' | ||
], | ||
'page link default title not allowed' => [ | ||
'page-link-with-default-title', | ||
SiteTreeLink::class, | ||
false, | ||
'' | ||
], | ||
'email link without default title not allowed' => [ | ||
'email-link-with-default-title', | ||
EmailLink::class, | ||
false, | ||
'' | ||
], | ||
'external link without default title not allowed' => [ | ||
'external-link-with-default-title', | ||
ExternalLink::class, | ||
false, | ||
'' | ||
], | ||
'phone link without default title not allowed' => [ | ||
'phone-link-with-default-title', | ||
PhoneLink::class, | ||
false, | ||
'' | ||
], | ||
'file link without default title not allowed' => [ | ||
'file-link-with-default-title', | ||
FileLink::class, | ||
false, | ||
'' | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider linkDefaultTitleDataProvider | ||
*/ | ||
public function testDefaultLinkTitle(string $identifier, string $class, bool $useDefaultTitle, string $expected): void | ||
{ | ||
/** @var Link $link */ | ||
$link = $this->objFromFixture($class, $identifier); | ||
$link->config()->set('use_default_title', $useDefaultTitle); | ||
|
||
$this->assertEquals($expected, $link->getDefaultTitle()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,31 +36,41 @@ SilverStripe\LinkField\Models\SiteTreeLink: | |
QueryString: 'param1=value1¶m2=option2' | ||
Anchor: 'my-anchor' | ||
Page: =>SilverStripe\CMS\Model\SiteTree.page-1 | ||
page-link-with-default-title: | ||
Page: =>SilverStripe\CMS\Model\SiteTree.page-1 | ||
|
||
SilverStripe\LinkField\Models\EmailLink: | ||
email-link-with-email: | ||
Title: 'EmailLinkWithEmail' | ||
Email: '[email protected]' | ||
email-link-no-email: | ||
Title: 'EmailLinkNoEmail' | ||
email-link-with-default-title: | ||
Email: '[email protected]' | ||
|
||
SilverStripe\LinkField\Models\ExternalLink: | ||
external-link-with-url: | ||
Title: 'ExternalLinkWithUrl' | ||
ExternalUrl: 'https://google.com' | ||
external-link-no-url: | ||
Title: 'ExternalLinkNoUrl' | ||
external-link-with-default-title: | ||
ExternalUrl: 'https://google.com' | ||
|
||
SilverStripe\LinkField\Models\PhoneLink: | ||
phone-link-with-phone: | ||
Title: 'PhoneLinkWithPhone' | ||
Phone: '+64 4 978 7330' | ||
phone-link-no-phone: | ||
Title: 'PhoneLinkNoPhone' | ||
phone-link-with-default-title: | ||
Phone: '+64 4 978 7330' | ||
|
||
SilverStripe\LinkField\Models\FileLink: | ||
file-link-with-image: | ||
Title: 'FileLinkWithImage' | ||
File: =>SilverStripe\Assets\Image.image-1 | ||
file-link-no-image: | ||
Title: 'FileLinkNoImage' | ||
file-link-with-default-title: | ||
File: =>SilverStripe\Assets\Image.image-1 |