Skip to content

Commit

Permalink
House keeping
Browse files Browse the repository at this point in the history
  • Loading branch information
gorriecoe committed Apr 11, 2018
1 parent cb8e16f commit 750035c
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 40 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ composer require gorriecoe/silverstripe-link
- silverstripe/framework ^4.0
- unclecheese/display-logic ^2.0

## Suggestion

- [silverstripe/silverstripe-linkfield](https://github.com/gorriecoe/silverstripe-linkfield)

## Maintainers

- [Gorrie Coe](https://github.com/gorriecoe)
Expand Down Expand Up @@ -74,7 +78,7 @@ gorriecoe\Link\Models\Link:

### Limit allowed Link types

Globally limit link types. To limit types define them in your site config.yml file as below.
To limit types define them in your site config.yml file as below.

```yaml
gorriecoe\Link\Models\Link:
Expand All @@ -94,7 +98,7 @@ gorriecoe\Link\Models\Link:
- gorriecoe\Link\Extensions\AutomaticMarkupID
```

To apply automatic id's add the following to your config
To apply input defineable id's add the following to your config
```yaml
gorriecoe\Link\Models\Link:
extensions:
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gorriecoe/silverstripe-link",
"description": "",
"description": "Adds a Link Object that can be link to a URL, Email, Phone number, an internal Page or File.",
"type": "silverstripe-vendormodule",
"license": "BSD-3-Clause",
"authors": [
Expand All @@ -11,7 +11,6 @@
],
"keywords": [
"silverstripe",
"cms",
"link"
],
"homepage": "http://github.com/gorriecoe/silverstripe-link",
Expand Down
3 changes: 1 addition & 2 deletions src/extensions/AutomaticMarkupID.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
/**
* Add sitetree type to link field
*
* @package silverstripe
* @subpackage silverstripe-link
* @package silverstripe-link
*/
class AutomaticMarkupID extends DataExtension
{
Expand Down
3 changes: 1 addition & 2 deletions src/extensions/DBStringLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
/**
* Adds methods to DBString to help manipulate the output suitable for links
*
* @package silverstripe
* @subpackage silverstripe-link
* @package silverstripe-link
*/
class DBStringLink extends DataExtension
{
Expand Down
3 changes: 1 addition & 2 deletions src/extensions/DefineableMarkupID.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
/**
* Add sitetree type to link field
*
* @package silverstripe
* @subpackage silverstripe-link
* @package silverstripe-link
*/
class DefineableMarkupID extends DataExtension
{
Expand Down
3 changes: 1 addition & 2 deletions src/extensions/LinkSiteTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
/**
* Add sitetree type to link field
*
* @package silverstripe
* @subpackage silverstripe-link
* @package silverstripe-link
*/
class LinkSiteTree extends DataExtension
{
Expand Down
6 changes: 2 additions & 4 deletions src/extensions/SiteTreeLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
namespace gorriecoe\Link\Extensions;

use gorriecoe\Link\Models\Link;
use SilverStripe\Core\Config\Config;
use SilverStripe\ORM\DataExtension;

/**
* Fixes duplicate link in SiteTree
*
* @package silverstripe
* @subpackage silverstripe-link
* @package silverstripe-link
*/
class SiteTreeLink extends DataExtension
{
Expand All @@ -21,7 +19,7 @@ public function onBeforeDuplicate()
{
$owner = $this->owner;
//loop through has_one relationships and reset any Link fields
if($hasOne = Config::inst()->get($owner->ClassName, 'has_one')){
if($hasOne = $owner->Config()->get('has_one')){
foreach ($hasOne as $field => $fieldType) {
if ($fieldType === Link::class) {
$owner->{$field.'ID'} = 0;
Expand Down
3 changes: 1 addition & 2 deletions src/graphql/LinkQueryCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
/**
* LinkQueryCreator
*
* @package silverstripe
* @subpackage silverstripe-menu
* @package silverstripe-link
*/
class LinkQueryCreator extends QueryCreator implements OperationResolver
{
Expand Down
3 changes: 1 addition & 2 deletions src/graphql/LinkTypeCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
/**
* LinkTypeCreator
*
* @package silverstripe
* @subpackage silverstripe-menu
* @package silverstripe-link
*/
class LinkTypeCreator extends TypeCreator
{
Expand Down
3 changes: 1 addition & 2 deletions src/graphql/LinksQueryCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
/**
* LinksQueryCreator
*
* @package silverstripe
* @subpackage silverstripe-menu
* @package silverstripe-link
*/
class LinksQueryCreator extends QueryCreator implements OperationResolver
{
Expand Down
36 changes: 18 additions & 18 deletions src/models/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ class Link extends DataObject
*/
private static $db = [
'Title' => 'Varchar(255)',
'Type' => 'Varchar',
'Type' => 'Varchar(50)',
'URL' => 'Varchar(255)',
'Email' => 'Varchar(255)',
'Phone' => 'Varchar(255)',
'Phone' => 'Varchar(30)',
'OpenInNewWindow' => 'Boolean',
'Template' => 'Varchar(255)'
];
Expand All @@ -50,7 +50,7 @@ class Link extends DataObject
* @var array
*/
private static $has_one = [
'File' => File::class,
'File' => File::class
];

/**
Expand All @@ -60,7 +60,7 @@ class Link extends DataObject
*/
private static $summary_fields = [
'Title' => 'Title',
'LinkType' => 'Type',
'TypeLabel' => 'Type',
'LinkURL' => 'Link'
];

Expand Down Expand Up @@ -120,10 +120,10 @@ public function getCMSFields()
{
$fields = FieldList::create(
TabSet::create(
"Root",
Tab::create("Main")
'Root',
Tab::create('Main')
)
->setTitle(_t('SiteTree.TABMAIN', "Main"))
->setTitle(_t('SiteTree.TABMAIN', 'Main'))
);

if ($styles = $this->i18nStyles) {
Expand Down Expand Up @@ -161,33 +161,33 @@ public function getCMSFields()
'Title'
)
)
->displayIf("Type")->isEqualTo('File')->end(),
->displayIf('Type')->isEqualTo('File')->end(),
Wrapper::create(
TextField::create(
'URL',
_t(__CLASS__ . '.URL', 'URL')
)
)
->displayIf("Type")->isEqualTo('URL')->end(),
->displayIf('Type')->isEqualTo('URL')->end(),
Wrapper::create(
TextField::create(
'Email',
_t(__CLASS__ . '.EMAILADDRESS', 'Email Address')
)
)
->displayIf("Type")->isEqualTo('Email')->end(),
->displayIf('Type')->isEqualTo('Email')->end(),
Wrapper::create(
TextField::create(
'Phone',
_t(__CLASS__ . '.PHONENUMBER', 'Phone Number')
)
)
->displayIf("Type")->isEqualTo('Phone')->end(),
->displayIf('Type')->isEqualTo('Phone')->end(),
CheckboxField::create(
'OpenInNewWindow',
_t(__CLASS__ . '.OPENINNEWWINDOW','Open link in a new window')
)
->displayIf('Type')->isEqualTo("URL")
->displayIf('Type')->isEqualTo('URL')
->orIf()->isEqualTo('File')
->orIf()->isEqualTo('SiteTree')->end()
]
Expand Down Expand Up @@ -444,10 +444,10 @@ public function getIDAttr()
* Returns the description label of this links type
* @return string
*/
public function getLinkType()
public function getTypeLabel()
{
$types = $this->config()->get('types');
return isset($types[$this->Type]) ? _t(__CLASS__ . '.TYPE'.strtoupper($this->Type), $types[$this->Type]) : null;
return isset($types[$this->Type]) ? _t(__CLASS__ . '.TYPE' . strtoupper($this->Type), $types[$this->Type]) : null;
}

/**
Expand Down Expand Up @@ -533,9 +533,9 @@ public function validate()
$valid = false;
$message = _t(
__CLASS__ . '.VALIDATIONERROR_EMPTY'.strtoupper($type),
'You must enter a {LinkType}',
'You must enter a {TypeLabel}',
[
'LinkType' => $this->LinkType
'TypeLabel' => $this->TypeLabel
]
);
}
Expand All @@ -546,9 +546,9 @@ public function validate()
$valid = false;
$message = _t(
__CLASS__ . '.VALIDATIONERROR_OBJECT',
'Please select a {LinkType}',
'Please select a {TypeLabel}',
[
'LinkType' => $this->LinkType
'TypeLabel' => $this->TypeLabel
]
);
}
Expand Down

0 comments on commit 750035c

Please sign in to comment.