Skip to content

Commit

Permalink
Update namespace. Add table_name config to all models (#39)
Browse files Browse the repository at this point in the history
* Add table_name config to all models

* Update namespace and table names

* Update template location
  • Loading branch information
chrispenny authored Nov 16, 2021
1 parent 3e0f699 commit 1068b78
Show file tree
Hide file tree
Showing 28 changed files with 68 additions and 60 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ You may need to add the repository URL into your `composer.json` via the `reposi
```php
<?php
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Link\DBLink;
use SilverStripe\Link\Link;
use SilverStripe\Link\LinkField;
use SilverStripe\LinkField\DBLink;
use SilverStripe\LinkField\Link;
use SilverStripe\LinkField\LinkField;

class Page extends SiteTree
{
Expand Down
8 changes: 4 additions & 4 deletions _config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ Name: linkfield

SilverStripe\Admin\LeftAndMain:
extensions:
- SilverStripe\Link\Extensions\LeftAndMain
- SilverStripe\LinkField\Extensions\LeftAndMain

SilverStripe\Admin\ModalController:
extensions:
- SilverStripe\Link\Extensions\ModalController
- SilverStripe\LinkField\Extensions\ModalController

SilverStripe\Forms\TreeDropdownField:
extensions:
- SilverStripe\Link\Extensions\AjaxField
- SilverStripe\LinkField\Extensions\AjaxField

SilverStripe\CMS\Forms\AnchorSelectorField:
extensions:
- SilverStripe\Link\Extensions\AjaxField
- SilverStripe\LinkField\Extensions\AjaxField
8 changes: 4 additions & 4 deletions _config/graphql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ SilverStripe\GraphQL\Manager:
schemas:
admin:
types:
LinkType: SilverStripe\Link\GraphQL\LinkTypeType
LinkDescription: SilverStripe\Link\GraphQL\LinkDescriptionType
LinkType: SilverStripe\LinkField\GraphQL\LinkTypeType
LinkDescription: SilverStripe\LinkField\GraphQL\LinkDescriptionType

queries:
readLinkTypes: SilverStripe\Link\GraphQL\LinkTypeQuery
readLinkDescription: SilverStripe\Link\GraphQL\LinkDescriptionQuery
readLinkTypes: SilverStripe\LinkField\GraphQL\LinkTypeQuery
readLinkDescription: SilverStripe\LinkField\GraphQL\LinkDescriptionQuery
10 changes: 5 additions & 5 deletions _config/types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
Name: linkfield-types
---

SilverStripe\Link\Type\Registry:
SilverStripe\LinkField\Type\Registry:
types:
cms:
classname: SilverStripe\Link\Models\SiteTreeLink
classname: SilverStripe\LinkField\Models\SiteTreeLink
enabled: true
external:
classname: SilverStripe\Link\Models\ExternalLink
classname: SilverStripe\LinkField\Models\ExternalLink
enabled: true
file:
classname: SilverStripe\Link\Models\FileLink
classname: SilverStripe\LinkField\Models\FileLink
enabled: true
email:
classname: SilverStripe\Link\Models\EmailLink
classname: SilverStripe\LinkField\Models\EmailLink
enabled: true
2 changes: 1 addition & 1 deletion src/Extensions/AjaxField.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace SilverStripe\Link\Extensions;
namespace SilverStripe\LinkField\Extensions;

use SilverStripe\Core\Extension;
use SilverStripe\Forms\FormField;
Expand Down
4 changes: 2 additions & 2 deletions src/Extensions/LeftAndMain.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace SilverStripe\Link\Extensions;
namespace SilverStripe\LinkField\Extensions;

use SilverStripe\Core\Extension;
use SilverStripe\Link\Type\Registry;
use SilverStripe\LinkField\Type\Registry;

/**
* Register a new Form Schema in LeftAndMain.
Expand Down
6 changes: 3 additions & 3 deletions src/Extensions/ModalController.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php

namespace SilverStripe\Link\Extensions;
namespace SilverStripe\LinkField\Extensions;

use InvalidArgumentException;
use SilverStripe\Admin\ModalController as OwnerController;
use SilverStripe\Control\HTTPResponse_Exception;
use SilverStripe\Core\Extension;
use SilverStripe\Forms\Form;
use SilverStripe\Link\Form\FormFactory;
use SilverStripe\Link\Type\Registry;
use SilverStripe\LinkField\Form\FormFactory;
use SilverStripe\LinkField\Type\Registry;

/**
* Extensions to apply to ModalController so it knows how to handle the DynamicLink action.
Expand Down
4 changes: 2 additions & 2 deletions src/Form/FormFactory.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace SilverStripe\Link\Form;
namespace SilverStripe\LinkField\Form;

use LogicException;
use SilverStripe\Admin\Forms\LinkFormFactory;
use SilverStripe\Forms\HiddenField;
use SilverStripe\Link\Type\Type;
use SilverStripe\LinkField\Type\Type;

/**
* Create Form schema for the LinkField based on a key provided by the request.
Expand Down
2 changes: 1 addition & 1 deletion src/Form/JsonField.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);

namespace SilverStripe\Link\Form;
namespace SilverStripe\LinkField\Form;

use InvalidArgumentException;
use SilverStripe\Forms\FormField;
Expand Down
2 changes: 1 addition & 1 deletion src/Form/LinkField.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);

namespace SilverStripe\Link\Form;
namespace SilverStripe\LinkField\Form;

/**
* Allows CMS users to edit a Link object.
Expand Down
4 changes: 2 additions & 2 deletions src/GraphQL/LinkDescriptionQuery.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
namespace SilverStripe\Link\GraphQL;
namespace SilverStripe\LinkField\GraphQL;

use GraphQL\Type\Definition\ResolveInfo;
use GraphQL\Type\Definition\Type as GraphqlType;
use SilverStripe\GraphQL\QueryCreator;
use SilverStripe\Link\Type\Registry;
use SilverStripe\LinkField\Type\Registry;

/**
* GraphQL Query to generate a Link Description for a provided JSON string representing the Link Data.
Expand Down
2 changes: 1 addition & 1 deletion src/GraphQL/LinkDescriptionType.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace SilverStripe\Link\GraphQL;
namespace SilverStripe\LinkField\GraphQL;

use GraphQL\Type\Definition\Type as GraphqlType;
use SilverStripe\GraphQL\TypeCreator as GraphqlTypeCreator;
Expand Down
6 changes: 3 additions & 3 deletions src/GraphQL/LinkTypeQuery.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
namespace SilverStripe\Link\GraphQL;
namespace SilverStripe\LinkField\GraphQL;

use GraphQL\Type\Definition\ResolveInfo;
use GraphQL\Type\Definition\Type as GraphqlType;
use SilverStripe\GraphQL\QueryCreator;
use SilverStripe\Link\Type\Registry;
use SilverStripe\Link\Type\Type;
use SilverStripe\LinkField\Type\Registry;
use SilverStripe\LinkField\Type\Type;

/**
* GraphQL Query to retrieve the list of possible LinkTypes.
Expand Down
2 changes: 1 addition & 1 deletion src/GraphQL/LinkTypeType.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace SilverStripe\Link\GraphQL;
namespace SilverStripe\LinkField\GraphQL;

use GraphQL\Type\Definition\Type as GraphqlType;
use SilverStripe\GraphQL\TypeCreator as GraphqlTypeCreator;
Expand Down
2 changes: 1 addition & 1 deletion src/JsonData.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);

namespace SilverStripe\Link;
namespace SilverStripe\LinkField;

use JsonSerializable;

Expand Down
4 changes: 3 additions & 1 deletion src/Models/EmailLink.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);

namespace SilverStripe\Link\Models;
namespace SilverStripe\LinkField\Models;

use SilverStripe\Forms\EmailField;

Expand All @@ -12,6 +12,8 @@
class EmailLink extends Link
{

private static $table_name = 'LinkField_EmailLink';

private static $db = [
'Email' => 'Varchar(255)'
];
Expand Down
5 changes: 3 additions & 2 deletions src/Models/ExternalLink.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);

namespace SilverStripe\Link\Models;
namespace SilverStripe\LinkField\Models;

/**
* An link to an external URL.
Expand All @@ -10,11 +10,12 @@
class ExternalLink extends Link
{

private static $table_name = 'LinkField_ExternalLink';

private static $db = [
'ExternalUrl' => 'Varchar'
];


public function generateLinkDescription(array $data): string
{
return isset($data['ExternalUrl']) ? $data['ExternalUrl'] : '';
Expand Down
8 changes: 5 additions & 3 deletions src/Models/FileLink.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
<?php declare(strict_types=1);

namespace SilverStripe\Link\Models;
namespace SilverStripe\LinkField\Models;

use SilverStripe\Assets\File;
use SilverStripe\i18n\i18n;
use SilverStripe\Link\Type\Type;
use SilverStripe\LinkField\Type\Type;

/**
* A link to a File track in asset-admin
*
* @property File $File
* @property int $FileID
*/
class FileLink extends Link
{

private static $table_name = 'LinkField_FileLink';

private static $has_one = [
'File' => File::class
];


public function generateLinkDescription(array $data): string
{
if (empty($data['FileID'])) {
Expand Down
10 changes: 6 additions & 4 deletions src/Models/Link.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php declare(strict_types=1);

namespace SilverStripe\Link\Models;
namespace SilverStripe\LinkField\Models;

use InvalidArgumentException;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Forms\FieldList;
use SilverStripe\Link\JsonData;
use SilverStripe\Link\Type\Registry;
use SilverStripe\Link\Type\Type;
use SilverStripe\LinkField\JsonData;
use SilverStripe\LinkField\Type\Registry;
use SilverStripe\LinkField\Type\Type;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\FieldType\DBHTMLText;
use SilverStripe\View\Requirements;
Expand All @@ -21,6 +21,8 @@
class Link extends DataObject implements JsonData, Type
{

private static $table_name = 'LinkField_Link';

private static $db = [
'Title' => 'Varchar',
'OpenInNew' => 'Boolean'
Expand Down
5 changes: 3 additions & 2 deletions src/Models/SiteTreeLink.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);

namespace SilverStripe\Link\Models;
namespace SilverStripe\LinkField\Models;

use SilverStripe\CMS\Forms\AnchorSelectorField;
use SilverStripe\CMS\Model\SiteTree;
Expand All @@ -16,6 +16,8 @@
class SiteTreeLink extends Link
{

private static $table_name = 'LinkField_SiteTreeLink';

private static $db = [
'Anchor' => 'Varchar'
];
Expand All @@ -24,7 +26,6 @@ class SiteTreeLink extends Link
'Page' => SiteTree::class
];


public function generateLinkDescription(array $data): string
{
if (empty($data['PageID'])) {
Expand Down
2 changes: 1 addition & 1 deletion src/ORM/DBJson.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace SilverStripe\Link\ORM;
namespace SilverStripe\LinkField\ORM;

use SilverStripe\Core\Config\Config;
use SilverStripe\ORM\DB;
Expand Down
6 changes: 3 additions & 3 deletions src/ORM/DBLink.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace SilverStripe\Link\ORM;
namespace SilverStripe\LinkField\ORM;

use SilverStripe\Link\Type\Registry;
use SilverStripe\LinkField\Type\Registry;
use SilverStripe\ORM\FieldType\DBHTMLText;
use SilverStripe\Link\Form\LinkField;
use SilverStripe\LinkField\Form\LinkField;

/**
* Represent Link object stored as a JSON string
Expand Down
2 changes: 1 addition & 1 deletion src/Type/Registry.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace SilverStripe\Link\Type;
namespace SilverStripe\LinkField\Type;

use InvalidArgumentException;
use SilverStripe\Core\Config\Configurable;
Expand Down
4 changes: 2 additions & 2 deletions src/Type/Type.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace SilverStripe\Link\Type;
namespace SilverStripe\LinkField\Type;

use SilverStripe\Forms\FieldList;
use SilverStripe\Link\JsonData;
use SilverStripe\LinkField\JsonData;

/**
* Define a link type that can be edited in Link Field
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions tests/php/LinkModelTest.php → tests/php/Models/LinkTest.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?php

namespace SilverStripe\Link\Tests;
namespace SilverStripe\LinkField\Tests\Models;

use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Link\Models\Link;
use SilverStripe\Link\Models\SiteTreeLink;
use SilverStripe\LinkField\Models\Link;
use SilverStripe\LinkField\Models\SiteTreeLink;
use SilverStripe\ORM\ValidationException;

class LinkModelTest extends SapphireTest
class LinkTest extends SapphireTest
{
/**
* @var string
*/
protected static $fixture_file = 'LinkModelTest.yml';
protected static $fixture_file = 'LinkTest.yml';

public function testLinkModel(): void
{
Expand Down
4 changes: 2 additions & 2 deletions tests/php/LinkModelTest.yml → tests/php/Models/LinkTest.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
SilverStripe\Link\Models\Link:
SilverStripe\LinkField\Models\Link:
link-1:
Title: Link1

SilverStripe\Link\Models\SiteTreeLink:
SilverStripe\LinkField\Models\SiteTreeLink:
page-link-1:
Title: PageLink1

Expand Down

0 comments on commit 1068b78

Please sign in to comment.