Skip to content

Commit

Permalink
Move things around and add doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Rainville committed Jun 23, 2020
1 parent 16f48ee commit be42b5b
Show file tree
Hide file tree
Showing 18 changed files with 57 additions and 84 deletions.
8 changes: 4 additions & 4 deletions _config/types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ Name: linkfield-types
SilverStripe\Link\Type\Registry:
types:
cms:
classname: SilverStripe\Link\SiteTreeLink
classname: SilverStripe\Link\Models\SiteTreeLink
enabled: true
external:
classname: SilverStripe\Link\ExternalLink
classname: SilverStripe\Link\Models\ExternalLink
enabled: true
file:
classname: SilverStripe\Link\FileLink
classname: SilverStripe\Link\Models\FileLink
enabled: true
email:
classname: SilverStripe\Link\EmailLink
classname: SilverStripe\Link\Models\EmailLink
enabled: true
5 changes: 3 additions & 2 deletions src/Extensions/AjaxField.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

use SilverStripe\Core\Extension;
use SilverStripe\Forms\FormField;
use SilverStripe\Link;

/**
* Tweak fields that need to be serve through the DynamicLink form schema and need to be able to receive AJAX calls.
* Tweak fields that need to be served through the DynamicLink form schema and need to be able to receive AJAX calls.
*
* For example the TreeDropdownField need to be able to receive AJAX request to fetch the list of available SiteTrees.
*
* This is a bit hackish. There's probably a less dumb way of doing this.
*/
class AjaxField extends Extension
{
Expand Down
3 changes: 1 addition & 2 deletions src/Extensions/ModalController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
use SilverStripe\Control\HTTPResponse_Exception;
use SilverStripe\Core\Extension;
use SilverStripe\Forms\Form;
use SilverStripe\Link\FormFactory;
use SilverStripe\Link\Form\FormFactory;
use SilverStripe\Link\Type\Registry;
use SilverStripe\View\Requirements;

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

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

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

/**
* Create Form schema for the LinkField based on a key provided by the request.
*/
class FormFactory extends LinkFormFactory
{
protected function getFormFields($controller, $name, $context)
Expand Down
12 changes: 4 additions & 8 deletions src/JsonField.php → src/Form/JsonField.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
<?php declare(strict_types=1);

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

use InvalidArgumentException;
use SilverStripe\Assets\File;
use SilverStripe\Forms\FileUploadReceiver;
use SilverStripe\Forms\FormField;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DataObjectInterface;
use SilverStripe\ORM\RelationList;
use SilverStripe\ORM\UnsavedRelationList;

/**
* Field design to edit complex data passed as a JSON string. Other FormFields can be built on top of this one.
* Field designed to edit complex data passed as a JSON string. Other FormFields can be built on top of this one.
*
* It will output an hidden input with serialize JSON Data.
* It will output a hidden input with serialize JSON Data.
*/
abstract class JsonField extends FormField
{
Expand Down Expand Up @@ -43,7 +39,7 @@ public function saveInto(DataObjectInterface $record)
}

$dataValue = $this->dataValue();
$value = is_array($dataValue) ? $dataValue : $this->parseString($this->dataValue());
$value = is_string($dataValue) ? $this->parseString($this->dataValue()) : $dataValue;

if ($class = DataObject::getSchema()->hasOneComponent(get_class($record), $fieldname)) {
/** @var JsonData|DataObject $jsonDataObject */
Expand Down
9 changes: 4 additions & 5 deletions src/LinkField.php → src/Form/LinkField.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?php declare(strict_types=1);

namespace SilverStripe\Link;

use InvalidArgumentException;
use SilverStripe\Forms\FormField;
use SilverStripe\Link\Type\Registry;
namespace SilverStripe\Link\Form;

/**
* Allows CMS users to edit a Link object.
*/
class LinkField extends JsonField
{
protected $schemaComponent = 'LinkField';
Expand Down
1 change: 0 additions & 1 deletion src/GraphQL/LinkDescriptionQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

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

Expand Down
1 change: 0 additions & 1 deletion src/GraphQL/LinkDescriptionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use GraphQL\Type\Definition\Type as GraphqlType;
use SilverStripe\GraphQL\TypeCreator as GraphqlTypeCreator;
use GraphQL\Type\Definition\ResolveInfo;

/**
* GraphQL type for serving a Link Description.
Expand Down
1 change: 0 additions & 1 deletion src/GraphQL/LinkTypeQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

use GraphQL\Type\Definition\ResolveInfo;
use GraphQL\Type\Definition\Type as GraphqlType;
use SilverStripe\GraphQL\Pagination\Connection;
use SilverStripe\GraphQL\QueryCreator;
use SilverStripe\Link\Type\Registry;
use SilverStripe\Link\Type\Type;
Expand Down
14 changes: 6 additions & 8 deletions src/EmailLink.php → src/Models/EmailLink.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
<?php declare(strict_types=1);

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

use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Forms\EmailField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\TreeDropdownField;
use SilverStripe\i18n\i18n;
use SilverStripe\Link\Type\Type;
use SilverStripe\View\Requirements;

/**
* A link to an Email address.
*
* @property string $Email
*/
class EmailLink extends Link
{

Expand Down
15 changes: 6 additions & 9 deletions src/ExternalLink.php → src/Models/ExternalLink.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
<?php declare(strict_types=1);

namespace SilverStripe\Link;

use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\TreeDropdownField;
use SilverStripe\i18n\i18n;
use SilverStripe\Link\Type\Type;
use SilverStripe\View\Requirements;
namespace SilverStripe\Link\Models;

/**
* An link to an external URL.
*
* @property string $ExternalUrl
*/
class ExternalLink extends Link
{

Expand Down
22 changes: 4 additions & 18 deletions src/FileLink.php → src/Models/FileLink.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?php declare(strict_types=1);

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

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

/**
* Class FileLink
* @property File File
* A link to a File track in asset-admin
* @property File $File
* @property int $FileID
*/
class FileLink extends Link
{
Expand Down Expand Up @@ -37,19 +38,4 @@ public function getURL()
{
return $this->File ? $this->File->getURL() : '';
}

// public function getCMSFields()
// {
// return parent::getCMSFields()
// ->addFieldToTab(
// 'Root.Main',
// TreeDropdownField::create(
// 'SiteTreeID',
// 'Page',
// SiteTree::class,
// 'ID',
// 'TreeTitle'
// )
// );
// }
}
12 changes: 8 additions & 4 deletions src/Link.php → src/Models/Link.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
<?php declare(strict_types=1);

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

use InvalidArgumentException;
use LogicException;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Control\Middleware\HTTPCacheControlMiddleware;
use SilverStripe\Forms\FieldList;
use SilverStripe\Link\JsonData;
use SilverStripe\Link\Type\Registry;
use SilverStripe\Link\Type\Type;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\FieldType\DBHTMLText;
use SilverStripe\View\Requirements;

/**
* A Link Data Object. This class should be subclass and you should never directly interact with a plain Link instance.
*
* @property string $Title
* @property bool $OpenInNew
*/
class Link extends DataObject implements JsonData, Type
{

Expand Down
14 changes: 5 additions & 9 deletions src/SiteTreeLink.php → src/Models/SiteTreeLink.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
<?php declare(strict_types=1);

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

use SilverStripe\CMS\Forms\AnchorSelectorField;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\TreeDropdownField;
use SilverStripe\i18n\i18n;
use SilverStripe\Link\Type\Type;
use SilverStripe\View\Requirements;

/**
* Class SiteTreeLink
* @property SiteTree Page
* @property string Anchor
* A link to a Page in the CMS.
* @property SiteTree $Page
* @property int $PageID
* @property string $Anchor
*/
class SiteTreeLink extends Link
{
Expand Down
4 changes: 2 additions & 2 deletions src/DBJson.php → src/ORM/DBJson.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

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

use SilverStripe\Core\Config\Config;
use SilverStripe\ORM\DB;
use SilverStripe\ORM\FieldType\DBField;

/**
* Represents a signed 32 bit integer field.
* Represents a DBField storing a JSON string
*/
class DBJson extends DBField
{
Expand Down
14 changes: 6 additions & 8 deletions src/DBLink.php → src/ORM/DBLink.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
<?php

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

use SilverStripe\Link\Type\Registry;
use SilverStripe\ORM\DB;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\FieldType\DBHTMLText;
use SilverStripe\View\ArrayData;
use SilverStripe\Link\Form\LinkField;

/**
* Represent Link object stored as a JSON string
*/
class DBLink extends DBJson
{
/**
* Return a rendered version of this form.
*
* This is returned when you access a form as $FormObject rather
* than <% with FormObject %>
* Load the link data into a singleton Link Object
*
* @return DBHTMLText
*/
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit be42b5b

Please sign in to comment.