Skip to content

Commit

Permalink
A bunch of changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Rainville committed Jul 11, 2023
1 parent 88a61fa commit 051beeb
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 23 deletions.
2 changes: 1 addition & 1 deletion _graphql/queries.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'readLinkDescription(dataStr: String!)':
type: '[LinkDescription]'
resolver: ['SilverStripe\Link\GraphQL\LinkDescriptionResolver', 'resolve']
resolver: ['SilverStripe\LinkField\GraphQL\LinkDescriptionResolver', 'resolve']
'readLinkTypes(keys: [ID])':
type: '[LinkType]'
resolver: ['SilverStripe\LinkField\GraphQL\LinkTypeResolver', 'resolve']
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion client/src/components/AbstractLinkField/linkFieldHOC.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { compose } from 'redux';
import { withApollo } from '@apollo/client';
import { withApollo } from '@apollo/client/react/hoc';
import { injectGraphql } from 'lib/Injector';
import fieldHolder from 'components/FieldHolder/FieldHolder';

Expand All @@ -16,6 +16,7 @@ const stringifyData = (Component) => (({ data, value, ...props }) => {
return <Component dataStr={JSON.stringify(dataValue)} {...props} data={dataValue} />;
});


/**
* Wires a Link field into GraphQL normalise the initial data to a proper objects
*/
Expand Down
1 change: 0 additions & 1 deletion src/Form/JsonField.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use SilverStripe\LinkField\JsonData;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DataObjectInterface;
use SilverStripe\Link\JsonData;

/**
* Field designed to edit complex data passed as a JSON string. Other FormFields can be built on top of this one.
Expand Down
4 changes: 2 additions & 2 deletions src/Form/MultiLinkField.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php declare(strict_types=1);

namespace SilverStripe\Link\Form;
namespace SilverStripe\LinkField\Form;

use SilverStripe\Core\Injector\Injector;
use SilverStripe\Link\Models\Link;
use SilverStripe\LinkField\Models\Link;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DataObjectInterface;
use SilverStripe\ORM\SS_List;
Expand Down
2 changes: 1 addition & 1 deletion src/Models/EmailLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class EmailLink extends Link
'Email' => 'Varchar(255)',
];

public function generateLinkDescription(array $data): string
public function generateLinkDescription(array $data): array
{
$description = isset($data['Email']) ? $data['Email'] : '';
$title = empty($data['Title']) ? $description : $data['Title'];
Expand Down
3 changes: 3 additions & 0 deletions src/Models/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ public function jsonSerialize(): mixed
}

$data = $this->toMap();

$data['OpenInNew'] = boolval($data['OpenInNew']);

$data['typeKey'] = $typeKey;
// Some of our models (SiteTreeLink in particular) have defined getTitle() methods. We *don't* want to override
// the 'Title' field (which represent the literal 'Title' Database field) - if we did that, then it would also
Expand Down
10 changes: 8 additions & 2 deletions src/Models/PhoneLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ class PhoneLink extends Link
'Phone' => 'Varchar(255)',
];

public function generateLinkDescription(array $data): string
public function generateLinkDescription(array $data): array
{
return isset($data['Phone']) ? $data['Phone'] : '';
if (isset($data)) {
return [
'title' => $data['Phone']
];
}

return [];
}

public function getURL(): string
Expand Down
10 changes: 5 additions & 5 deletions tests/php/Form/MultiLinkFieldTest.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

namespace SilverStripe\Link\Tests\Form;
namespace SilverStripe\LinkField\Tests\Form;

use SilverStripe\Dev\SapphireTest;
use SilverStripe\Link\Models\Link;
use SilverStripe\Link\Models\ExternalLink;
use SilverStripe\Link\Form\MultiLinkField;
use SilverStripe\Link\Tests\LinkOwner;
use SilverStripe\LinkField\Models\Link;
use SilverStripe\LinkField\Models\ExternalLink;
use SilverStripe\LinkField\Form\MultiLinkField;
use SilverStripe\LinkField\Tests\LinkOwner;

class MultiLinkFieldTest extends SapphireTest
{
Expand Down
2 changes: 1 addition & 1 deletion tests/php/GraphQL/LinkDescriptionResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace SilverStripe\Link\Tests\Form;

use SilverStripe\Dev\SapphireTest;
use SilverStripe\Link\GraphQL\LinkDescriptionResolver;
use SilverStripe\LinkField\GraphQL\LinkDescriptionResolver;

class LinkDescriptionResolverTest extends SapphireTest
{
Expand Down
6 changes: 3 additions & 3 deletions tests/php/LinkModelTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace SilverStripe\Link\Tests;
namespace SilverStripe\LinkField\Tests;

use SilverStripe\Dev\SapphireTest;
use SilverStripe\Link\Models\Link;
use SilverStripe\Link\Models\ExternalLink;
use SilverStripe\LinkField\Models\Link;
use SilverStripe\LinkField\Models\ExternalLink;

class LinkModelTest extends SapphireTest
{
Expand Down
6 changes: 3 additions & 3 deletions tests/php/LinkModelTest.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SilverStripe\Link\Models\ExternalLink:
SilverStripe\LinkField\Models\ExternalLink:
link-1:
Title: Link1
ExternalUrl: 'https://silverstripe.org/'
Expand All @@ -7,8 +7,8 @@ SilverStripe\Link\Models\ExternalLink:
ExternalUrl: 'https://google.com/'
# Owner: =>SilverStripe\Link\Tests\LinkOwner.link-owner-1

SilverStripe\Link\Tests\LinkOwner:
SilverStripe\LinkField\Tests\LinkOwner:
link-owner-1:
Title: A Link owner
Links:
- =>SilverStripe\Link\Models\ExternalLink.link-2
- =>SilverStripe\LinkField\Models\ExternalLink.link-2
4 changes: 2 additions & 2 deletions tests/php/LinkOwner.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace SilverStripe\Link\Tests;
namespace SilverStripe\LinkField\Tests;

use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\DataObject;
use SilverStripe\Link\Models\Link;
use SilverStripe\LinkField\Models\Link;

class LinkOwner extends DataObject
{
Expand Down

0 comments on commit 051beeb

Please sign in to comment.