Skip to content

Commit

Permalink
ENH Remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Feb 12, 2024
1 parent 48e36da commit 447be6c
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 143 deletions.
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/registerComponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ import Injector from 'lib/Injector';
import LinkPicker from 'components/LinkPicker/LinkPicker';
import LinkField from 'components/LinkField/LinkField';
import LinkModal from 'components/LinkModal/LinkModal';
import FileLinkModal from 'components/LinkModal/FileLinkModal';

const registerComponents = () => {
Injector.component.registerMany({
LinkPicker,
LinkField,
'LinkModal.FormBuilderModal': LinkModal,
'LinkModal.InsertMediaModal': FileLinkModal
});
};

Expand Down
76 changes: 0 additions & 76 deletions client/src/components/LinkModal/FileLinkModal.js

This file was deleted.

64 changes: 0 additions & 64 deletions src/Models/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
use ReflectionException;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Forms\CompositeValidator;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\LinkField\Services\LinkTypeService;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DataObjectSchema;
Expand Down Expand Up @@ -54,13 +51,6 @@ class Link extends DataObject
Versioned::class,
];

/**
* In-memory only property used to change link type
* This case is relevant for CMS edit form which doesn't use React driven UI
* This is a workaround as changing the ClassName directly is not fully supported in the GridField admin
*/
private ?string $linkType = null;

/**
* Set the priority of this link type in the link picker.
* A link with a higher priority value will be displayed lower in the list.
Expand Down Expand Up @@ -94,8 +84,6 @@ public function LinkTypeHandlerName(): string
public function getCMSFields(): FieldList
{
$this->beforeUpdateCMSFields(function (FieldList $fields) {
$linkTypes = $this->getLinkTypes();

$linkTextField = $fields->dataFieldByName('LinkText');
$linkTextField->setTitle(_t(__CLASS__ . '.LINK_TEXT_TITLE', 'Link text'));
$linkTextField->setTitleTip(new Tip(_t(
Expand All @@ -107,23 +95,6 @@ public function getCMSFields(): FieldList

$openInNewField = $fields->dataFieldByName('OpenInNew');
$openInNewField->setTitle(_t(__CLASS__ . '.OPEN_IN_NEW_TITLE', 'Open in new window?'));

if (static::class === self::class) {
// Add a link type selection field for generic links
$fields->addFieldsToTab(
'Root.Main',
[
$linkTypeField = DropdownField::create(
'LinkType',
_t(__CLASS__ . '.LINK_TYPE_TITLE', 'Link Type'),
$linkTypes
),
],
'LinkText'
);

$linkTypeField->setEmptyString('-- select type --');
}
});
$this->afterUpdateCMSFields(function (FieldList $fields) {
// Move the LinkText and OpenInNew fields to the bottom of the form if it hasn't been removed in
Expand All @@ -140,43 +111,8 @@ public function getCMSFields(): FieldList
return parent::getCMSFields();
}

/**
* @return CompositeValidator
*/
public function getCMSCompositeValidator(): CompositeValidator
{
$validator = parent::getCMSCompositeValidator();

if (static::class === self::class) {
// Make Link type mandatory for generic links
$validator->addValidator(RequiredFields::create([
'LinkType',
]));
}

return $validator;
}

/**
* Form hook defined in @see Form::saveInto()
* We use this to work with an in-memory only field
*
* @param $value
*/
public function saveLinkType($value)
{
$this->linkType = $value;
}

public function onBeforeWrite(): void
{
// Detect link type change and update the class accordingly
if ($this->linkType && DataObject::singleton($this->linkType) instanceof Link) {
$this->setClassName($this->linkType);
$this->populateDefaults();
$this->forceChange();
}

// Ensure a Sort value is set and that it's one larger than any other Sort value for
// this owner relation so that newly created Links on MultiLinkField's are properly sorted
if (!$this->Sort) {
Expand Down

0 comments on commit 447be6c

Please sign in to comment.