-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created an intermediary dataobject for the link. This allows us to set fields like Content and SortOrder on the dataobject, but reference the field values of the Link.
- Loading branch information
Showing
5 changed files
with
138 additions
and
60 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
--- | ||
name: silverstripe-elemental-links-config | ||
--- | ||
gorriecoe\Link\Models\Link: | ||
extensions: | ||
- Dynamic\Elements\Links\Extensions\LinkDataExtension |
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 was deleted.
Oops, something went wrong.
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,116 @@ | ||
<?php | ||
|
||
namespace Dynamic\Elements\Links\Model; | ||
|
||
use gorriecoe\Link\Models\Link; | ||
use SilverStripe\ORM\DataObject; | ||
use SilverStripe\Forms\FieldList; | ||
use gorriecoe\LinkField\LinkField; | ||
use Dynamic\Elements\Links\Elements\LinksElement; | ||
|
||
/** | ||
* Class \Dynamic\Elements\Links\Model\LinkListObject | ||
* | ||
* @property string $Content | ||
* @property int $SortOrder | ||
* @property int $LinkListID | ||
* @property int $LinkID | ||
* @method LinksElement LinkList() | ||
* @method Link Link() | ||
*/ | ||
class LinkListObject extends DataObject | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private static $singular_name = 'Link'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private static $plural_name = 'Links'; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private static $db = [ | ||
'Content' => 'HTMLText', | ||
'SortOrder' => "Int", | ||
]; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private static $has_one = [ | ||
'LinkList' => LinksElement::class, | ||
'Link' => Link::class, | ||
]; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private static $summary_fields = [ | ||
'Link.Title', | ||
'Link.LinkURL', | ||
]; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private static $table_name = 'LinkListObject'; | ||
|
||
/** | ||
* @param bool $includerelations | ||
* @return array | ||
*/ | ||
public function fieldLabels($includerelations = true) | ||
{ | ||
$labels = parent::fieldLabels($includerelations); | ||
|
||
$labels['Description'] = _t(__CLASS__ . '.DescriptionLabel', 'Description'); | ||
$labels['Link.Title'] = _t(__CLASS__ . '.LinkTitleLabel', 'Link'); | ||
$labels['Link.LinkURL'] = _t(__CLASS__ . '.LinkURLLabel', 'Link URL'); | ||
$labels['Link'] = _t(__CLASS__ . '.LinkLabel', 'Link'); | ||
|
||
return $labels; | ||
} | ||
|
||
/** | ||
* @return \SilverStripe\Forms\FieldList | ||
*/ | ||
public function getCMSFields() | ||
{ | ||
$this->beforeUpdateCMSFields(function (FieldList $fields) { | ||
$fields->replaceField( | ||
'LinkID', | ||
LinkField::create('Link', $this->fieldLabel('Link'), $this) | ||
); | ||
|
||
$fields->insertBefore( | ||
'Content', | ||
$fields->dataFieldByName('Link') | ||
); | ||
|
||
$fields->dataFieldByName('Content') | ||
->setTitle($this->fieldLabel('Description')) | ||
->setRows(5); | ||
|
||
$fields->removeByName([ | ||
'LinkListID', | ||
'SortOrder', | ||
]); | ||
}); | ||
|
||
return parent::getCMSFields(); | ||
} | ||
|
||
/** | ||
* return Title of Link for LinkListObject Title | ||
* | ||
* @return void | ||
*/ | ||
public function getTitle() | ||
{ | ||
return $this->Link()->Title; | ||
} | ||
} |
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