diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c6ea26d --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/vendor/ +composer.lock +/resources/ diff --git a/.phpunit.result.cache b/.phpunit.result.cache new file mode 100644 index 0000000..593bcf6 --- /dev/null +++ b/.phpunit.result.cache @@ -0,0 +1 @@ +{"version":1,"defects":{"DNADesign\\ElementalVirtual\\Tests\\BaseElementExtensionTest::testVirtualElementAnchor":4,"DNADesign\\ElementalVirtual\\Tests\\BaseElementExtensionTest::testUpdateCmsFields":1},"times":{"DNADesign\\ElementalVirtual\\Tests\\BaseElementExtensionTest::testVirtualElementAnchor":0,"DNADesign\\ElementalVirtual\\Tests\\BaseElementExtensionTest::testUpdateCmsFields":0}} \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 6981446..0000000 --- a/.travis.yml +++ /dev/null @@ -1,41 +0,0 @@ -language: php - -dist: xenial - -services: - - mysql - - postgresql - -env: - global: - - COMPOSER_ROOT_VERSION=1.x-dev - -matrix: - include: - - php: 7.1 - env: DB=MYSQL PHPCS_TEST=1 PHPUNIT_TEST=1 - - php: 7.2 - env: DB=PGSQL PHPUNIT_TEST=1 - - php: 7.3 - env: DB=MYSQL PHPUNIT_TEST=1 - - php: 7.4 - env: DB=MYSQL PHPUNIT_COVERAGE_TEST=1 - -before_script: - # Init PHP - - phpenv rehash - - phpenv config-rm xdebug.ini - - # Install composer dependencies - - composer validate - - composer require silverstripe/recipe-cms:4.x-dev --no-update - - if [[ $DB == PGSQL ]]; then composer require silverstripe/postgresql:2.x-dev --no-update; fi - - composer install --prefer-source --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile - -script: - - if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit tests/; fi - - if [[ $PHPUNIT_COVERAGE_TEST ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml; fi - - if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs --standard=vendor/silverstripe/framework/phpcs.xml.dist src/ tests/ ; fi - -after_success: - - if [[ $PHPUNIT_COVERAGE_TEST ]]; then bash <(curl -s https://codecov.io/bash) -f coverage.xml; fi diff --git a/behat.yml b/behat.yml new file mode 100644 index 0000000..f092b55 --- /dev/null +++ b/behat.yml @@ -0,0 +1,21 @@ +# Note: Currently chrome latest is recommended +# Behat test setup requires an `.env` with `SS_BASE_URL` defined, as well +# as each of the following commands to initiate a test run: +# ========================================================================= # +# composer require silverstripe/recipe-testing ^1 +# vendor/bin/behat-ss @ +# ========================================================================= # +default: + suites: [] + extensions: + SilverStripe\BehatExtension\MinkExtension: + default_session: facebook_web_driver + javascript_session: facebook_web_driver + facebook_web_driver: + browser: chrome + wd_host: "http://127.0.0.1:9515" #chromedriver port + browser_name: chrome + SilverStripe\BehatExtension\Extension: + bootstrap_file: vendor/silverstripe/cms/tests/behat/serve-bootstrap.php + screenshot_path: %paths.base%/artifacts/screenshots + retry_seconds: 4 # default is 2 diff --git a/codecov.yml b/codecov.yml deleted file mode 100644 index 69cb760..0000000 --- a/codecov.yml +++ /dev/null @@ -1 +0,0 @@ -comment: false diff --git a/composer.json b/composer.json index c626677..53f16eb 100644 --- a/composer.json +++ b/composer.json @@ -13,32 +13,37 @@ "prefer-stable": true, "require": { "dnadesign/silverstripe-elemental": "^3 || ^4", - "tractorcow/silverstripe-autocomplete": "^4", + "silverstripe/tagfield": "^2.0", "silverstripe/vendor-plugin": "^1.0", "silverstripe/admin": "^1.5" }, "require-dev": { - "phpunit/phpunit": "^5.7", - "squizlabs/php_codesniffer": "^3.0" + "silverstripe/recipe-testing": "^2" }, "extra": { "branch-alias": { - "dev-master": "1.x-dev" + "dev-main": "1.x-dev" }, "expose": [ "css" + ], + "project-files-installed": [ + "behat.yml", + "phpcs.xml.dist", + "phpunit.xml.dist" ] }, - "scripts": { - "lint": "phpcs --extensions=php src/ tests/", - "syntax-check": "find src/ tests/ -type f -name '*.php' -exec php -l {} \\;", - "lint-clean": "phpcbf src/ tests/ --extensions=php", - "remove-uses": "php-cs-fixer fix src/ tests/ --rules=no_unused_imports" - }, "autoload": { "psr-4": { "DNADesign\\ElementalVirtual\\": "src/", "DNADesign\\ElementalVirtual\\Tests\\": "tests/php/" } + }, + "config": { + "allow-plugins": { + "composer/installers": true, + "silverstripe/recipe-plugin": true, + "silverstripe/vendor-plugin": true + } } } diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 0000000..1f36b0e --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,24 @@ + + + Coding standard for SilverStripe 4.x + + + */vendor/* + */thirdparty/* + + + + + + + + + + + + + + + + + diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 49affdc..d62d325 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,14 +1,14 @@ - - - tests/php - - - - - src/ - - tests/php - - - + + + + + src/ + + + tests/php + + + + tests/php + diff --git a/src/Forms/ElementalGridFieldAddExistingAutocompleter.php b/src/Forms/ElementalGridFieldAddExistingAutocompleter.php deleted file mode 100644 index bd77704..0000000 --- a/src/Forms/ElementalGridFieldAddExistingAutocompleter.php +++ /dev/null @@ -1,71 +0,0 @@ -State->GridFieldAddRelation) { - return $dataList; - } - - $objectID = Convert::raw2sql($gridField->State->GridFieldAddRelation); - - if ($objectID) { - $object = DataObject::get_by_id($gridField->getModelClass(), $objectID); - - if ($object) { - // if the object is currently not linked to either a page or another list then we want to link to - // the original, otherwise link to a clone - if (!$object->ParentID) { - $dataList->add($object); - } else { - $virtual = ElementVirtual::create(); - $virtual->LinkedElementID = $object->ID; - $virtual->write(); - - $dataList->add($virtual); - } - } - } - - $gridField->State->GridFieldAddRelation = null; - - return $dataList; - } -} diff --git a/src/Model/ElementVirtual.php b/src/Model/ElementVirtual.php index b31b296..821c038 100644 --- a/src/Model/ElementVirtual.php +++ b/src/Model/ElementVirtual.php @@ -2,23 +2,16 @@ namespace DNADesign\ElementalVirtual\Model; -use TractorCow\AutoComplete\AutoCompleteField; -use SilverStripe\ElementalVirtual\Forms\ElementalGridFieldAddExistingAutocompleter; use DNADesign\Elemental\Models\BaseElement; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\LiteralField; -use SilverStripe\Forms\Tab; -use SilverStripe\Forms\TabSet; -use SilverStripe\ORM\FieldType\DBField; -use SilverStripe\ORM\FieldType\DBHTMLText; +use SilverStripe\TagField\TagField; /** * Virtual Linked Element. * * As elemental is based on a natural has_one relation to an object, * this allows the same element to be linked to multiple pages. - * - * {@see ElementalGridFieldAddExistingAutocompleter} */ class ElementVirtual extends BaseElement { @@ -36,8 +29,8 @@ class ElementVirtual extends BaseElement private static $table_name = 'ElementVirtual'; private static $singular_name = 'virtual block'; - - private static $inline_editable = false; + + private static $inline_editable = true; /** * @param BaseElement @@ -67,29 +60,23 @@ public function getCMSFields() $fields->addFieldToTab('Root.Main', LiteralField::create('WarningHeader', '

' . $warning . '

')); } - $autocomplete = AutoCompleteField::create( - 'LinkedElementID', - _t(__CLASS__ . '.LinkedElement', 'Linked Element'), - '', - BaseElement::class, - 'Title' - ); - - $autocomplete->setLabelField('VirtualLinkedSummary'); - $autocomplete->setDisplayField('VirtualLinkedSummary'); - $autocomplete->setSourceFilter(['AvailableGlobally' => 1]); + $availableBlocks = BaseElement::get()->filter('AvailableGlobally', 1)->exclude('ClassName', ElementVirtual::class); $fields->replaceField( 'LinkedElementID', - $autocomplete + TagField::create("LinkedElementID", $this->fieldLabel('LinkedElement'), $availableBlocks) + ->setIsMultiple(false) + ->setCanCreate(false) + ->setShouldLazyLoad(true) ); - - if($this->LinkedElementID){ + + if ($this->LinkedElementID) { $message = sprintf( '

%s

Click here to edit the original

', _t(__CLASS__ . '.VirtualDescription', 'This is a virtual copy of an element.'), $this->LinkedElement()->getEditLink() ); + $fields->addFieldToTab('Root.Main', LiteralField::create('Existing', $message)); } }); diff --git a/templates/DNADesign/Elemental/Forms/ElementalGridFieldAddExistingAutocompleter.ss b/templates/DNADesign/Elemental/Forms/ElementalGridFieldAddExistingAutocompleter.ss deleted file mode 100644 index 792c21d..0000000 --- a/templates/DNADesign/Elemental/Forms/ElementalGridFieldAddExistingAutocompleter.ss +++ /dev/null @@ -1,5 +0,0 @@ -
- <% loop $Fields %> - $Field - <% end_loop %> -
diff --git a/tests/php/BaseElementExtensionTest.php b/tests/php/BaseElementExtensionTest.php index 0e40027..18fff73 100644 --- a/tests/php/BaseElementExtensionTest.php +++ b/tests/php/BaseElementExtensionTest.php @@ -19,7 +19,7 @@ class BaseElementExtensionTest extends SapphireTest TestPage::class ]; - public function setUp() + public function setUp(): void { parent::setUp();