From c21f47093259da715c69f3aa3f496fd263e7a9da Mon Sep 17 00:00:00 2001 From: Maxime Rainville Date: Mon, 23 Nov 2020 16:42:33 +1300 Subject: [PATCH 1/2] Rename module --- composer.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 5edd02e5..1d664c06 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "silverstripe/link", + "name": "silverstripe/linkfield", "description": "Add advanced link functionality to Silverstripe.", "type": "silverstripe-vendormodule", "require": { @@ -9,7 +9,8 @@ "require-dev": { "phpunit/phpunit": "^5.7", "silverstripe/cms": "^4.5", - "silverstripe/asset-admin": "^1.5" + "silverstripe/asset-admin": "^1.5", + "silverstripe/graphql": "^4" }, "license": "BSD-3-Clause", "authors": [ From 6e84b039a1ffa282fe995e09830db459900b5bcd Mon Sep 17 00:00:00 2001 From: Mojmir Fendek Date: Fri, 22 Oct 2021 08:01:08 +1300 Subject: [PATCH 2/2] BUG: Stable branch tidy-up. --- .travis.yml | 113 ++++++++++-------------------------- README.md | 27 ++++++++- composer.json | 19 +++--- phpcs.xml.dist | 38 ++++++------ src/Form/JsonField.php | 13 ++--- src/JsonData.php | 3 +- src/Models/EmailLink.php | 1 - src/Models/ExternalLink.php | 1 - src/Models/Link.php | 8 +-- src/Models/SiteTreeLink.php | 3 +- src/ORM/DBJson.php | 3 +- src/Type/Registry.php | 7 +-- tests/php/LinkModelTest.php | 21 +++++++ tests/php/LinkModelTest.yml | 3 + 14 files changed, 130 insertions(+), 130 deletions(-) create mode 100644 tests/php/LinkModelTest.php create mode 100644 tests/php/LinkModelTest.yml diff --git a/.travis.yml b/.travis.yml index 83a16e7f..f7e083cc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,90 +1,39 @@ -language: php +version: ~> 1.0 -dist: xenial +import: + - silverstripe/silverstripe-travis-shared:config/provision/standard.yml -services: - - mysql - - postgresql - - xvfb - -cache: - directories: - - $HOME/.composer/cache/files - -addons: - apt: - packages: - - tidy - - chromium-chromedriver - - chromium-browser - -env: - global: - - DB=MYSQL - - COMPOSER_ROOT_VERSION=1.x-dev - - DISPLAY=":99" - - XVFBARGS=":99 -ac -screen 0 1024x768x16" - - SS_BASE_URL="http://localhost:8080/" - - SS_ENVIRONMENT_TYPE="dev" - -matrix: +jobs: include: - - php: 7.1 - env: PHPUNIT_TEST=1 - - php: 7.2 - env: BEHAT_TEST=1 - php: 7.3 - env: PHPUNIT_TEST=1 - - php: 7.4 - env: PHPUNIT_TEST=1 - - php: 7.1 - env: NPM_TEST=1 - - php: 7.2 - env: PHPCS_TEST=1 + env: + - DB=MYSQL + - REQUIRE_INSTALLER="$REQUIRE_RECIPE 4.x-dev" + - PHPUNIT_TEST=1 + - PHPCS_TEST=1 + - PHPSTAN_TEST=1 - php: 7.3 env: - DB=PGSQL + - REQUIRE_INSTALLER="$REQUIRE_RECIPE 4.x-dev" - PHPUNIT_TEST=1 - -before_script: -# Extra $PATH - - export PATH=/usr/lib/chromium-browser/:$PATH - -# Init PHP - - phpenv rehash - - phpenv config-rm xdebug.ini - - echo 'memory_limit = 2048M' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini - - echo 'always_populate_raw_post_data = -1' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini - -# Install composer - - composer validate - - if [[ $DB == PGSQL ]]; then composer require --no-update silverstripe/postgresql:2.x-dev --prefer-dist; fi - - composer require silverstripe/recipe-testing:^1 silverstripe/recipe-cms 4.x-dev --no-update --prefer-dist - - composer update - -# Remove preinstalled Chrome (google-chrome) -# this would conflict with our chromium-browser installation -# and its version is incompatible with chromium-chromedriver - - sudo apt-get remove -y --purge google-chrome-stable || true - -# Start behat services - - if [[ $BEHAT_TEST ]]; then mkdir artifacts; fi - - if [[ $BEHAT_TEST ]]; then cp composer.lock artifacts/; fi - - if [[ $BEHAT_TEST ]]; then sh -e /etc/init.d/xvfb start; sleep 3; fi - - if [[ $BEHAT_TEST ]]; then (chromedriver > artifacts/chromedriver.log 2>&1 &); fi - - if [[ $BEHAT_TEST ]]; then (vendor/bin/serve --bootstrap-file vendor/silverstripe/cms/tests/behat/serve-bootstrap.php &> artifacts/serve.log &); fi - -# Install NPM dependencies - - if [[ $NPM_TEST ]]; then rm -rf client/dist && nvm install && nvm use && npm install -g yarn && yarn install --network-concurrency 1 && (cd vendor/silverstripe/admin && yarn install --network-concurrency 1) && yarn run build; fi - -script: - - if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit tests/php; fi - - if [[ $NPM_TEST ]]; then git diff-files --quiet -w --relative=client; fi - - if [[ $NPM_TEST ]]; then git diff --name-status --relative=client; fi - - if [[ $NPM_TEST ]]; then yarn run test; fi - - if [[ $NPM_TEST ]]; then yarn run lint; fi - - if [[ $BEHAT_TEST ]]; then vendor/bin/behat @link; fi - - if [[ $PHPCS_TEST ]]; then composer run-script lint; fi - -after_failure: - - php ./vendor/silverstripe/framework/tests/behat/travis-upload-artifacts.php --if-env BEHAT_TEST,ARTIFACTS_BUCKET,ARTIFACTS_KEY,ARTIFACTS_SECRET --target-path $TRAVIS_REPO_SLUG/$TRAVIS_BUILD_ID/$TRAVIS_JOB_ID --artifacts-base-url https://s3.amazonaws.com/$ARTIFACTS_BUCKET/ --artifacts-path ./artifacts/ + - COW_TEST=1 + - php: 7.4 + env: + - DB=MYSQL + - PDO=1 + - REQUIRE_INSTALLER="$REQUIRE_RECIPE 4.x-dev" + - PHPUNIT_COVERAGE_TEST=1 + - php: 7.4 + env: + - DB=MYSQL + - REQUIRE_INSTALLER="$REQUIRE_RECIPE 4.x-dev" + - PHPUNIT_TEST=1 + - REQUIRE_GRAPHQL="^3@dev" + - php: 8.0 + env: + - DB=MYSQL + - REQUIRE_INSTALLER="$REQUIRE_RECIPE 4.x-dev" + - PHPUNIT_TEST=1 + - REQUIRE_GRAPHQL="^3@dev" + - COMPOSER_INSTALL_ARG=--ignore-platform-reqs diff --git a/README.md b/README.md index b1c2c1c7..5d822803 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,32 @@ Experimental module looking at how we could implement a link field and a link data object. -# Sample usage +## Installation + +Installation via composer. + +### Stable version (GraphQL v3) + +`composer require silverstripe/linkfield 1.x-dev` + +### Experimental version (GraphQL v4) + +`composer require silverstripe/linkfield 2.x-dev` + +### Known issues + +You may need to add the repository URL into your `composer.json` via the `repositories` field (example below). + +```json +"repositories": { + "silverstripe/linkfield": { + "type": "git", + "url": "https://github.com/silverstripe/silverstripe-linkfield.git" + } +}, +``` + +## Sample usage ```php - CodeSniffer ruleset for SilverStripe coding conventions. + CodeSniffer ruleset for SilverStripe coding conventions. - - - - - - - - - - - - - - - - + src + tests + + + + + + + + + + + + + + + + + */SSTemplateParser.php$ - diff --git a/src/Form/JsonField.php b/src/Form/JsonField.php index 445b39bf..0a7a36a6 100644 --- a/src/Form/JsonField.php +++ b/src/Form/JsonField.php @@ -59,7 +59,6 @@ public function saveInto(DataObjectInterface $record) $jsonDataObject->write(); $record->{"{$fieldname}ID"} = $jsonDataObject->ID; } - } elseif ((DataObject::getSchema()->databaseField(get_class($record), $fieldname))) { $record->{$fieldname} = $value; } @@ -76,11 +75,12 @@ protected function parseString(string $value): ?array $data = json_decode($value, true); if (json_last_error() !== JSON_ERROR_NONE) { - var_dump($value); - throw new InvalidArgumentException(sprintf( - '%s: Could not parse provided JSON string. Failed with "%s"', - __CLASS__, - json_last_error_msg()) + throw new InvalidArgumentException( + sprintf( + '%s: Could not parse provided JSON string. Failed with "%s"', + __CLASS__, + json_last_error_msg() + ) ); } @@ -90,5 +90,4 @@ protected function parseString(string $value): ?array return $data; } - } diff --git a/src/JsonData.php b/src/JsonData.php index 754c7c6d..bf57284d 100644 --- a/src/JsonData.php +++ b/src/JsonData.php @@ -7,7 +7,8 @@ /** * An object that can be serialize and deserialize to JSON. */ -interface JsonData extends JsonSerializable { +interface JsonData extends JsonSerializable +{ /** * @param array|JsonData $data diff --git a/src/Models/EmailLink.php b/src/Models/EmailLink.php index 615a4e41..1af1a164 100644 --- a/src/Models/EmailLink.php +++ b/src/Models/EmailLink.php @@ -20,7 +20,6 @@ class EmailLink extends Link public function generateLinkDescription(array $data): string { return isset($data['Email']) ? $data['Email'] : ''; - } public function getCMSFields() diff --git a/src/Models/ExternalLink.php b/src/Models/ExternalLink.php index aab0b7ef..8d49ae20 100644 --- a/src/Models/ExternalLink.php +++ b/src/Models/ExternalLink.php @@ -18,7 +18,6 @@ class ExternalLink extends Link public function generateLinkDescription(array $data): string { return isset($data['ExternalUrl']) ? $data['ExternalUrl'] : ''; - } public function getURL() diff --git a/src/Models/Link.php b/src/Models/Link.php index 0df7b255..0ae1fd6c 100644 --- a/src/Models/Link.php +++ b/src/Models/Link.php @@ -29,9 +29,9 @@ class Link extends DataObject implements JsonData, Type public function defineLinkTypeRequirements() { - Requirements::add_i18n_javascript('silverstripe/link:client/lang', false, true); - Requirements::javascript('silverstripe/link:client/dist/js/bundle.js'); - Requirements::css('silverstripe/link:client/dist/styles/bundle.css'); + Requirements::add_i18n_javascript('silverstripe/linkfield:client/lang', false, true); + Requirements::javascript('silverstripe/linkfield:client/dist/js/bundle.js'); + Requirements::css('silverstripe/linkfield:client/dist/styles/bundle.css'); } public function LinkTypeHandlerName(): string @@ -90,7 +90,6 @@ function setData($data): JsonData } else { $jsonData = Injector::inst()->create(get_class($type)); } - } foreach ($data as $key => $value) { @@ -141,5 +140,4 @@ public function forTemplate() { return $this->renderWith([self::class]); } - } diff --git a/src/Models/SiteTreeLink.php b/src/Models/SiteTreeLink.php index eeccb33f..a8ffb65d 100644 --- a/src/Models/SiteTreeLink.php +++ b/src/Models/SiteTreeLink.php @@ -31,8 +31,8 @@ public function generateLinkDescription(array $data): string } $page = SiteTree::get()->byID($data['PageID']); - return $page ? $page->URLSegment : ''; + return $page ? $page->URLSegment : ''; } public function getCMSFields() @@ -66,5 +66,4 @@ public function getURL() } return $url; } - } diff --git a/src/ORM/DBJson.php b/src/ORM/DBJson.php index d2ce4b0c..b9c889e0 100644 --- a/src/ORM/DBJson.php +++ b/src/ORM/DBJson.php @@ -44,7 +44,8 @@ public function nullValue() return null; } - public function setValue($value, $record = null, $markChanged = true) { + public function setValue($value, $record = null, $markChanged = true) + { if (empty($value)) { $value = null; } diff --git a/src/Type/Registry.php b/src/Type/Registry.php index 1dc1de39..964aa68d 100644 --- a/src/Type/Registry.php +++ b/src/Type/Registry.php @@ -61,7 +61,7 @@ public function list(): array */ public function keys(): array { - + return []; } /** @@ -69,13 +69,12 @@ public function keys(): array */ public function keysEnabledByDefault(): array { - + return []; } public function init() { - foreach ($this->list() as $type) - { + foreach ($this->list() as $type) { $type->defineLinkTypeRequirements(); } } diff --git a/tests/php/LinkModelTest.php b/tests/php/LinkModelTest.php new file mode 100644 index 00000000..4232a1ec --- /dev/null +++ b/tests/php/LinkModelTest.php @@ -0,0 +1,21 @@ +objFromFixture(Link::class, 'link-1'); + + $this->assertEquals('FormBuilderModal', $model->LinkTypeHandlerName()); + } +} diff --git a/tests/php/LinkModelTest.yml b/tests/php/LinkModelTest.yml new file mode 100644 index 00000000..631a5bfa --- /dev/null +++ b/tests/php/LinkModelTest.yml @@ -0,0 +1,3 @@ +SilverStripe\Link\Models\Link: + link-1: + Title: Link1