Skip to content

Commit

Permalink
FEATURE Make LinkListObject versioned (#12)
Browse files Browse the repository at this point in the history
allows an uploaded file for a Link to be published via owns for a better CMS UX

extra config to publish an unpublished file when added to a Link

template update to only display a Link if the LinkListObject has a Link
  • Loading branch information
jsirish authored Aug 12, 2024
1 parent b366c7c commit d542472
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
4 changes: 4 additions & 0 deletions _config/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
name: silverstripe-elemental-links-config
---
# Publish file when uploaded for a Link
SilverStripe\LinkField\Models\FileLink:
owns:
- File
21 changes: 20 additions & 1 deletion src/Model/LinkListObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@

use SilverStripe\ORM\DataObject;
use SilverStripe\Forms\FieldList;
use SilverStripe\Versioned\Versioned;
use SilverStripe\LinkField\Models\Link;
use SilverStripe\LinkField\Form\LinkField;
use Dynamic\Elements\Links\Elements\LinksElement;
use SilverStripe\LinkField\Models\Link;

/**
* Class \Dynamic\Elements\Links\Model\LinkListObject
*
* @property int $Version
* @property string $Title
* @property string $Content
* @property int $SortOrder
* @property int $LinkListID
* @property int $LinkID
* @method LinksElement LinkList()
* @method Link Link()
* @mixin Versioned
*/
class LinkListObject extends DataObject
{
Expand Down Expand Up @@ -52,6 +55,22 @@ class LinkListObject extends DataObject
'Link' => Link::class,
];

/**
* @var array
* @config
*/
private static $owns = [
'Link',
];

/**
* @var array
* @config
*/
private static $extensions = [
Versioned::class,
];

/**
* @var array
* @config
Expand Down
18 changes: 9 additions & 9 deletions templates/Dynamic/Elements/Links/Elements/LinksElement.ss
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@
<div class="col-md-12">
<ul class="list-group">
<% loop $ElementLinks.Sort('SortOrder') %>
<a href="$Link.URL" class="list-group-item list-group-item-action" title="$Title"<% if $Link.OpenInNew %> target="_blank" rel="noopener noreferrer"<% end_if %>>
<div class="d-flex w-100 justify-content-between">
<h4 class="mb-1">$Title</h4>
</div>
$Content
<% if $Link %>
<% if $Link.exists %>
<a href="$Link.URL" class="list-group-item list-group-item-action" title="$Title"<% if $Link.OpenInNew %> target="_blank" rel="noopener noreferrer"<% end_if %>>
<div class="d-flex w-100 justify-content-between">
<h4 class="mb-1">$Title</h4>
</div>
$Content
<div class="d-flex gap-3">
<% with $Link %>
<i class="bi bi-link-45deg"></i>
<div class="d-flex gap-2 w-100">
<small>
<% if $Title %>$Title<br><% end_if %>{$URL}
<% if $Title %>$Title<% else %>{$URL}<% end_if %>
</small>
</div>
<% end_with %>
</div>
<% end_if %>
</a>
</a>
<% end_if %>
<% end_loop %>
</ul>
</div>
Expand Down

0 comments on commit d542472

Please sign in to comment.