Skip to content

Commit

Permalink
FIX Defaul link type title and icon for disabled link types
Browse files Browse the repository at this point in the history
  • Loading branch information
Sabina Talipova committed Jan 19, 2024
1 parent 4bc4883 commit 8b31884
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion client/src/components/LinkPicker/LinkPickerMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ const LinkPickerMenu = ({ types, onSelect }) => {
{i18n._t('LinkField.ADD_LINK', 'Add Link')}
</DropdownToggle>
<DropdownMenu>
{types.map(({key, title, icon}) =>
{types.map(({key, title, icon, allowed}) => {
return allowed &&
<DropdownItem key={key} onClick={() => onSelect(key)}>
<span className={`link-picker__menu-icon ${icon}`}></span>
{title}
</DropdownItem>
}
)}
</DropdownMenu>
</Dropdown>
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/LinkPicker/tests/LinkPicker-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import LinkPicker from '../LinkPicker';

function makeProps(obj = {}) {
return {
types: { phone: { key: 'phone', title: 'Phone', icon: 'font-icon-phone' } },
types: { phone: { key: 'phone', title: 'Phone', icon: 'font-icon-phone', allowed: true } },
canCreate: true,
onModalSuccess: () => {},
onModalClosed: () => {},
Expand Down
4 changes: 3 additions & 1 deletion src/Form/Traits/AllowedLinkClassesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ public function getTypesProps(): string
{
$typesList = [];
$typeDefinitions = $this->genarateAllowedTypes();
foreach ($typeDefinitions as $key => $class) {
$allTypes = LinkTypeService::create()->generateAllLinkTypes();
foreach ($allTypes as $key => $class) {
$type = Injector::inst()->get($class);
if (!$type->canCreate()) {
continue;
Expand All @@ -97,6 +98,7 @@ public function getTypesProps(): string
'handlerName' => $type->LinkTypeHandlerName(),
'priority' => $class::config()->get('menu_priority'),
'icon' => $class::config()->get('icon'),
'allowed' => array_key_exists($key, $typeDefinitions),
];
}
uasort($typesList, function ($a, $b) {
Expand Down
3 changes: 3 additions & 0 deletions tests/php/Traits/AllowedLinkClassesTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ public function sortedTypesDataProvider() : array
'expected' => [
'sitetree',
'testphone',
'file',
'external',
'email',
'phone',
],
'reorder' => true,
],
Expand Down

0 comments on commit 8b31884

Please sign in to comment.