-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sabina Talipova
committed
Dec 7, 2023
1 parent
5d41b85
commit 737a662
Showing
28 changed files
with
425 additions
and
351 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
|
||
namespace SilverStripe\LinkField\Services; | ||
|
||
use LogicException; | ||
use SilverStripe\Core\ClassInfo; | ||
use SilverStripe\Core\Injector\Injectable; | ||
use SilverStripe\Core\Injector\Injector; | ||
use SilverStripe\LinkField\Models\Link; | ||
|
||
class LinkTypeService | ||
{ | ||
|
||
use Injectable; | ||
|
||
public static function generateAllLinkTypes(): array | ||
{ | ||
$typeDefinitions = ClassInfo::subclassesFor(Link::class); | ||
|
||
$result = array(); | ||
foreach ($typeDefinitions as $class) { | ||
if (is_subclass_of($class, Link::class)) { | ||
$type = Injector::inst()->get($class)->config()->get('short_code'); | ||
$result[$type] = $class; | ||
} | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
public static function byKey(string $key): ?Link | ||
{ | ||
/** @var array $types */ | ||
$typeDefinitions = static::generateAllLinkTypes(); | ||
$definition = $typeDefinitions[$key] ?? null; | ||
|
||
if (!$definition) { | ||
return null; | ||
} | ||
|
||
return static::definitionToType($definition); | ||
} | ||
|
||
public static function keyByClassName(string $classname): ?string | ||
{ | ||
$typeDefinitions = static::generateAllLinkTypes(); | ||
|
||
foreach ($typeDefinitions as $key => $class) { | ||
if ($class === $classname) { | ||
return $key; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public static function definitionToType(string $className): Link | ||
{ | ||
if (!$className && !($className instanceof Link)) { | ||
throw new LogicException( | ||
_t( | ||
'LinkField.NO_CLASSNAME', | ||
'"{class}": All types should reference a valid classname', | ||
['class' => static::class], | ||
sprintf('%s: All types should reference a valid classname', static::class), | ||
), | ||
); | ||
} | ||
|
||
/** @var Link $type */ | ||
$type = Injector::inst()->get($className); | ||
|
||
if (!$type instanceof Link) { | ||
throw new LogicException( | ||
_t( | ||
'LinkField.INVALID_TYPENAME', | ||
'"{class}": {typename} is not a valid link type', | ||
[ | ||
'class' => static::class, | ||
'typename' => $className, | ||
], | ||
sprintf('%s: %s is not a valid link type', static::class, $className), | ||
), | ||
); | ||
} | ||
|
||
return $type; | ||
} | ||
} |
Oops, something went wrong.