Skip to content

Commit

Permalink
MNT Remove old code (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
sabina-talipova authored Nov 12, 2023
1 parent 24882c6 commit 369b619
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 82 deletions.
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ use SilverStripe\LinkField\Form\LinkField;

class Page extends SiteTree
{
private static array $db = [
'DbLink' => DBLink::class
];

private static array $has_one = [
'HasOneLink' => Link::class,
];
Expand All @@ -63,8 +59,8 @@ class Page extends SiteTree
[
LinkField::create('HasOneLink'),
LinkField::create('DbLink'),
]
)
],
);

return $fields;
}
Expand Down
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/src/bundles/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
// require('expose-loader?InsertMediaModal!containers/InsertMediaModal/InsertMediaModal');

import 'boot';
import 'entwine/JsonField';
import 'entwine/LinkField';
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ReactDOM from 'react-dom/client';
import { loadComponent } from 'lib/Injector';

jQuery.entwine('ss', ($) => {
$('.js-injector-boot .entwine-jsonfield').entwine({
$('.js-injector-boot .entwine-linkfield').entwine({

Component: null,
Root: null,
Expand Down
49 changes: 0 additions & 49 deletions src/Form/JsonField.php

This file was deleted.

39 changes: 38 additions & 1 deletion src/Form/LinkField.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,47 @@

namespace SilverStripe\LinkField\Form;

use SilverStripe\Forms\FormField;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DataObjectInterface;
use SilverStripe\LinkField\Models\Link;

/**
* Allows CMS users to edit a Link object.
*/
class LinkField extends JsonField
class LinkField extends FormField
{
protected $schemaComponent = 'LinkField';

protected $schemaDataType = FormField::SCHEMA_DATA_TYPE_CUSTOM;
protected $inputType = 'hidden';

public function setValue($value, $data = null)
{
if (is_a($value, Link::class)) {
$id = $value->ID;
} else {
$id = $value;
}
return parent::setValue($id, $data);
}

/**
* @param DataObject|DataObjectInterface $record - A DataObject such as a Page
* @return $this
*/
public function saveInto(DataObjectInterface $record)
{
// Check required relation details are available
$fieldname = $this->getName();
if (!$fieldname) {
return $this;
}

$linkID = $this->dataValue();
$dbColumn = $fieldname . 'ID';
$record->$dbColumn = $linkID;

return $this;
}
}
17 changes: 0 additions & 17 deletions src/JsonData.php

This file was deleted.

9 changes: 4 additions & 5 deletions src/Models/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\LinkField\JsonData;
use SilverStripe\LinkField\Type\Registry;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\FieldType\DBHTMLText;
Expand All @@ -22,7 +21,7 @@
* @property string $Title
* @property bool $OpenInNew
*/
class Link extends DataObject implements JsonData
class Link extends DataObject
{
private static $table_name = 'LinkField_Link';

Expand Down Expand Up @@ -124,7 +123,7 @@ public function onBeforeWrite(): void
parent::onBeforeWrite();
}

function setData($data): JsonData
function setData($data): Link
{
if (is_string($data)) {
$data = json_decode($data, true);
Expand All @@ -136,7 +135,7 @@ function setData($data): JsonData
json_last_error_msg()
));
}
} elseif ($data instanceof JsonData) {
} elseif ($data instanceof Link) {
$data = $data->jsonSerialize();
}

Expand Down Expand Up @@ -193,7 +192,7 @@ public function jsonSerialize(): mixed
return $data;
}

public function loadLinkData(array $data): JsonData
public function loadLinkData(array $data): Link
{
$link = new static();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<input $AttributesHTML />
<div data-field-id="$ID" data-schema-component="$SchemaComponent" class="entwine-jsonfield"></div>
<div data-field-id="$ID" data-schema-component="$SchemaComponent" class="entwine-linkfield"></div>

0 comments on commit 369b619

Please sign in to comment.