Skip to content

Commit

Permalink
NEW Allowed link types
Browse files Browse the repository at this point in the history
  • Loading branch information
Sabina Talipova committed Dec 7, 2023
1 parent 7689bc4 commit ce90192
Show file tree
Hide file tree
Showing 23 changed files with 187 additions and 228 deletions.
8 changes: 0 additions & 8 deletions _config/graphql.yml

This file was deleted.

20 changes: 0 additions & 20 deletions _config/types.yml

This file was deleted.

3 changes: 0 additions & 3 deletions _graphql/queries.yml

This file was deleted.

5 changes: 0 additions & 5 deletions _graphql/types.yml

This file was deleted.

2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions client/src/boot/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/* global document */
/* eslint-disable */
import registerComponents from './registerComponents';
import registerQueries from './registerQueries';

document.addEventListener('DOMContentLoaded', () => {
registerComponents();
registerQueries();
});
8 changes: 0 additions & 8 deletions client/src/boot/registerQueries.js

This file was deleted.

1 change: 0 additions & 1 deletion client/src/components/LinkField/LinkField.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ const mapDispatchToProps = (dispatch) => ({
});

export default compose(
injectGraphql('readLinkTypes'),
fieldHolder,
connect(null, mapDispatchToProps)
)(LinkField);
1 change: 1 addition & 0 deletions client/src/entwine/LinkField.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jQuery.entwine('ss', ($) => {
value,
onChange: this.handleChange.bind(this),
isMulti: this.data('is-multi') ?? false,
types: this.data('types') ?? [],
};
},

Expand Down
8 changes: 4 additions & 4 deletions src/Controllers/LinkFieldController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use SilverStripe\Forms\DefaultFormFactory;
use SilverStripe\Forms\Form;
use SilverStripe\LinkField\Models\Link;
use SilverStripe\LinkField\Type\Registry;
use SilverStripe\Security\SecurityToken;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\FormAction;
Expand All @@ -19,6 +18,7 @@
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Forms\HiddenField;
use SilverStripe\LinkField\Form\LinkField;
use SilverStripe\ORM\DataList;

class LinkFieldController extends LeftAndMain
Expand Down Expand Up @@ -74,7 +74,7 @@ public function linkForm(): Form
}
} else {
$typeKey = $this->typeKeyFromRequest();
$link = Registry::create()->byKey($typeKey);
$link = LinkField::byKey($typeKey);
if (!$link) {
$this->jsonError(404, _t('LinkField.INVALID_TYPEKEY', 'Invalid typeKey'));
}
Expand Down Expand Up @@ -174,7 +174,7 @@ public function save(array $data, Form $form): HTTPResponse
// Creating a new Link
$operation = 'create';
$typeKey = $this->typeKeyFromRequest();
$className = Registry::create()->list()[$typeKey] ?? '';
$className = LinkField::byKey($typeKey) ?? '';
if (!$className) {
$this->jsonError(404, _t('LinkField.INVALID_TYPEKEY', 'Invalid typeKey'));
}
Expand Down Expand Up @@ -239,7 +239,7 @@ private function createLinkForm(Link $link, string $operation): Form
$form = $formFactory->getForm($this, $name, ['Record' => $link]);

// Set where the form is submitted to
$typeKey = Registry::create()->keyByClassName($link->ClassName);
$typeKey = LinkField::keyByClassName($link->ClassName);
$form->setFormAction($this->Link("linkForm/$id?typeKey=$typeKey"));

// Add save action button
Expand Down
3 changes: 3 additions & 0 deletions src/Form/LinkField.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DataObjectInterface;
use SilverStripe\LinkField\Models\Link;
use SilverStripe\LinkField\Traits\AllowedLinkClassesTrait;

/**
* Allows CMS users to edit a Link object.
*/
class LinkField extends FormField
{
use AllowedLinkClassesTrait;

protected $schemaComponent = 'LinkField';

protected $schemaDataType = FormField::SCHEMA_DATA_TYPE_CUSTOM;
Expand Down
3 changes: 3 additions & 0 deletions src/Form/MultiLinkField.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use LogicException;
use SilverStripe\Forms\FormField;
use SilverStripe\LinkField\Traits\AllowedLinkClassesTrait;
use SilverStripe\ORM\DataObjectInterface;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\Relation;
Expand All @@ -16,6 +17,8 @@
*/
class MultiLinkField extends FormField
{
use AllowedLinkClassesTrait;

protected $schemaComponent = 'LinkField';

protected $schemaDataType = FormField::SCHEMA_DATA_TYPE_CUSTOM;
Expand Down
30 changes: 0 additions & 30 deletions src/GraphQL/LinkTypeResolver.php

This file was deleted.

2 changes: 2 additions & 0 deletions src/Models/EmailLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class EmailLink extends Link
{
private static string $table_name = 'LinkField_EmailLink';

private static $short_code = 'email';

private static array $db = [
'Email' => 'Varchar(255)',
];
Expand Down
2 changes: 2 additions & 0 deletions src/Models/ExternalLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class ExternalLink extends Link
{
private static string $table_name = 'LinkField_ExternalLink';

private static $short_code = 'external';

private static array $db = [
'ExternalUrl' => 'Varchar',
];
Expand Down
2 changes: 2 additions & 0 deletions src/Models/FileLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class FileLink extends Link
{
private static string $table_name = 'LinkField_FileLink';

private static $short_code = 'file';

private static array $has_one = [
'File' => File::class,
];
Expand Down
8 changes: 5 additions & 3 deletions src/Models/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\LinkField\Type\Registry;
use SilverStripe\LinkField\Form\LinkField;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\FieldType\DBHTMLText;

Expand All @@ -26,6 +26,8 @@ class Link extends DataObject
{
private static $table_name = 'LinkField_Link';

private static $short_code = 'link';

private static array $db = [
'Title' => 'Varchar',
'OpenInNew' => 'Boolean',
Expand Down Expand Up @@ -188,7 +190,7 @@ function setData($data): Link
);
}

$type = Registry::singleton()->byKey($typeKey);
$type = LinkField::byKey($typeKey);

if (!$type) {
throw new InvalidArgumentException(
Expand Down Expand Up @@ -225,7 +227,7 @@ function setData($data): Link

public function jsonSerialize(): mixed
{
$typeKey = Registry::singleton()->keyByClassName(static::class);
$typeKey = LinkField::keyByClassName(static::class);

if (!$typeKey) {
return [];
Expand Down
2 changes: 2 additions & 0 deletions src/Models/PhoneLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class PhoneLink extends Link
{
private static string $table_name = 'LinkField_PhoneLink';

private static $short_code = 'phone';

private static array $db = [
'Phone' => 'Varchar(255)',
];
Expand Down
2 changes: 2 additions & 0 deletions src/Models/SiteTreeLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class SiteTreeLink extends Link
{
private static string $table_name = 'LinkField_SiteTreeLink';

private static $short_code = 'cms';

private static array $db = [
'Anchor' => 'Varchar',
'QueryString' => 'Varchar',
Expand Down
Loading

0 comments on commit ce90192

Please sign in to comment.