From 63f61fc46086c7f7c30c94a790a1901cde5cf45f Mon Sep 17 00:00:00 2001 From: Julian Thomson Date: Fri, 23 Aug 2024 14:44:15 +1200 Subject: [PATCH] Restore repo --- .editorconfig | 17 ++++ .github/workflows/main.yml | 12 +++ .tx/config | 8 ++ .upgrade.yml | 2 + LICENSE | 29 +++++++ _config/elemental.yml | 8 ++ codecov.yml | 1 + composer.json | 35 ++++++++ contributing.md | 25 ++++++ lang/en.yml | 8 ++ lang/fr.yml | 8 ++ phpunit.xml.dist | 16 ++++ readme.md | 28 ++++++ .../BaseElementCMSEditLinkExtension.php | 58 +++++++++++++ src/Model/ElementList.php | 86 +++++++++++++++++++ .../ElementalList/Model/ElementList.ss | 6 ++ 16 files changed, 347 insertions(+) create mode 100644 .editorconfig create mode 100644 .github/workflows/main.yml create mode 100644 .tx/config create mode 100644 .upgrade.yml create mode 100644 LICENSE create mode 100644 _config/elemental.yml create mode 100644 codecov.yml create mode 100644 composer.json create mode 100644 contributing.md create mode 100644 lang/en.yml create mode 100644 lang/fr.yml create mode 100644 phpunit.xml.dist create mode 100644 readme.md create mode 100644 src/Extension/BaseElementCMSEditLinkExtension.php create mode 100644 src/Model/ElementList.php create mode 100644 templates/DNADesign/ElementalList/Model/ElementList.ss diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..47ae637 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,17 @@ +# For more information about the properties used in this file, +# please see the EditorConfig documentation: +# http://editorconfig.org + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[{*.yml,package.json}] +indent_size = 2 + +# The indent size used in the package.json file cannot be changed: +# https://github.com/npm/npm/pull/3180#issuecomment-16336516 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..2e6906d --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,12 @@ +name: CI + +on: + push: + pull_request: + workflow_dispatch: + +jobs: + ci: + uses: silverstripe/gha-ci/.github/workflows/ci.yml@v1 + with: + js: false diff --git a/.tx/config b/.tx/config new file mode 100644 index 0000000..f5ce1d4 --- /dev/null +++ b/.tx/config @@ -0,0 +1,8 @@ +[main] +host = https://www.transifex.com + +[silverstripe-elemental-list.master] +file_filter = lang/.yml +source_file = lang/en.yml +source_lang = en +type = YML diff --git a/.upgrade.yml b/.upgrade.yml new file mode 100644 index 0000000..3884b93 --- /dev/null +++ b/.upgrade.yml @@ -0,0 +1,2 @@ +mappings: + ElementList: DNADesign\ElementalList\Model\ElementList diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..efab44a --- /dev/null +++ b/LICENSE @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2017, DNA Designed Communications Limited +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/_config/elemental.yml b/_config/elemental.yml new file mode 100644 index 0000000..cc5b466 --- /dev/null +++ b/_config/elemental.yml @@ -0,0 +1,8 @@ +--- +name: elemental-list +--- +DNADesign\Elemental\Models\BaseElement: + extensions: + - DNADesign\ElementalList\Extension\BaseElementCMSEditLinkExtension +DNADesign\ElementalList\Model\ElementalList: + inline_editable: false diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..69cb760 --- /dev/null +++ b/codecov.yml @@ -0,0 +1 @@ +comment: false diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..dcc5bf7 --- /dev/null +++ b/composer.json @@ -0,0 +1,35 @@ +{ + "name": "dnadesign/silverstripe-elemental-list", + "description": "Adds a new element for nested elements", + "type": "silverstripe-vendormodule", + "keywords": ["silverstripe", "element", "elemental", "content blocks"], + "license": "BSD-3-Clause", + "authors": [{ + "name": "John Milmine", + "email": "john.milmine@dna.co.nz" + }], + "minimum-stability": "dev", + "prefer-stable": true, + "require": { + "php": "^8.1", + "silverstripe/cms": "^5.0", + "dnadesign/silverstripe-elemental": "^5.0", + "silverstripe/vendor-plugin": "^2.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.5", + "silverstripe/recipe-testing": "^3", + "squizlabs/php_codesniffer": "^3.0" + }, + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "DNADesign\\ElementalList\\": "src/", + "DNADesign\\ElementalList\\Tests\\": "tests/php/" + } + } +} diff --git a/contributing.md b/contributing.md new file mode 100644 index 0000000..8ba55ba --- /dev/null +++ b/contributing.md @@ -0,0 +1,25 @@ +# Contributing + +Any open source product is only as good as the community behind it. You can participate by sharing code, ideas, or +simply helping others. No matter what your skill level is, every contribution counts. + +See our [high level overview](http://silverstripe.org/contributing-to-silverstripe) on silverstripe.org on how you can +help out. + +Or, for more detailed guidance, read one of the following pages: + + * [Sharing your opinion and raising issues](http://docs.silverstripe.org/en/contributing/issues_and_bugs/) + * [Providing code, whether it's creating a feature or fixing a bug](http://docs.silverstripe.org/en/contributing/code/) + * [Writing and translating documentation](http://docs.silverstripe.org/en/contributing/translations/) + * [Translating user-interface elements](http://docs.silverstripe.org/en/contributing/translation_process/) + +## Copyright + +**IMPORTANT: By supplying code in patches, tickets and pull requests, you agree to assign copyright of that code to +DNA DESIGNED COMMUNICATIONS LIMITED, on the condition that DNA DESIGNED COMMUNICATIONS LIMITED releases that code under +the BSD license.** unless otherwise noted. + +We ask for this so that the ownership in the license is clear and unambiguous, and so that community involvement doesn't +stop us from being able to continue supporting these projects. By releasing this code under a permissive license, this +copyright assignment won't prevent you from using the code in any way you see fit. + diff --git a/lang/en.yml b/lang/en.yml new file mode 100644 index 0000000..9445c71 --- /dev/null +++ b/lang/en.yml @@ -0,0 +1,8 @@ +en: + DNADesign\ElementalList\Model\ElementList: + BlockType: List + PLURALNAME: lists + PLURALS: + one: 'A list' + other: '{count} lists' + SINGULARNAME: list diff --git a/lang/fr.yml b/lang/fr.yml new file mode 100644 index 0000000..422e80d --- /dev/null +++ b/lang/fr.yml @@ -0,0 +1,8 @@ +fr: + DNADesign\ElementalList\Model\ElementList: + BlockType: Liste + PLURALNAME: listes + PLURALS: + one: 'Une liste' + other: '{count} listes' + SINGULARNAME: liste diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..2dbbe21 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,16 @@ + + + + + tests + + + + + src/ + + tests/ + + + + diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..29b4a79 --- /dev/null +++ b/readme.md @@ -0,0 +1,28 @@ +# SilverStripe Elemental List + +[![Build Status](http://img.shields.io/travis/dnadesign/silverstripe-elemental-list.svg?style=flat-square)](https://travis-ci.org/dnadesign/silverstripe-elemental-list) +[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/dnadesign/silverstripe-elemental-list/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/dnadesign/silverstripe-elemental-list/?branch=master) +[![codecov](https://codecov.io/gh/dnadesign/silverstripe-elemental-list/branch/master/graph/badge.svg)](https://codecov.io/gh/dnadesign/silverstripe-elemental-list) +[![Version](http://img.shields.io/packagist/v/dnadesign/silverstripe-elemental-list.svg?style=flat-square)](https://packagist.org/packages/dnadesign/silverstripe-elemental-list) +[![License](http://img.shields.io/packagist/l/dnadesign/silverstripe-elemental-list.svg?style=flat-square)](LICENSE.md) + +## Introduction + +Adds a new element for Elemental which allows for nested blocks. This block allows users to nest blocks within other +blocks, allowing things like columns of blocks. + +## Requirements + +* Silverstripe CMS ^5.0 +* PHP ^8.1 + +For a Silverstripe CMS ^4.2 compatible version of this module, please see the [^1.1 releases](https://github.com/dnadesign/silverstripe-elemental-list/tree/1.1.0). + + +## Installation + +``` +composer require "dnadesign/silverstripe-elemental-list" +``` + + diff --git a/src/Extension/BaseElementCMSEditLinkExtension.php b/src/Extension/BaseElementCMSEditLinkExtension.php new file mode 100644 index 0000000..4d85c64 --- /dev/null +++ b/src/Extension/BaseElementCMSEditLinkExtension.php @@ -0,0 +1,58 @@ +owner; + + $relationName = $owner->getAreaRelationName(); + $page = $owner->getPage(); + + if (!$page) { + return; + } + + if ($page instanceof ElementList) { + // nested bock - we need to get edit link of parent block + $link = Controller::join_links( + $page->CMSEditLink(), + 'ItemEditForm/field/' . $page->getOwnedAreaRelationName() . '/item/', + $owner->ID + ); + + // remove edit link from parent CMS link + $link = preg_replace('/\/item\/([\d]+)\/edit/', '/item/$1', $link); + } else { + // block is directly under a non-block object - we have reached the top of nesting chain + $link = Controller::join_links( + singleton(CMSPageEditController::class)->Link('EditForm'), + $page->ID, + 'field/' . $relationName . '/item/', + $owner->ID + ); + } + + $link = Controller::join_links( + $link, + 'edit' + ); + } +} diff --git a/src/Model/ElementList.php b/src/Model/ElementList.php new file mode 100644 index 0000000..af14b88 --- /dev/null +++ b/src/Model/ElementList.php @@ -0,0 +1,86 @@ + ElementalArea::class + ]; + + private static array $owns = [ + 'Elements' + ]; + + private static array $cascade_deletes = [ + 'Elements' + ]; + + private static array $cascade_duplicates = [ + 'Elements' + ]; + + private static array $extensions = [ + ElementalAreasExtension::class + ]; + + private static string $table_name = 'ElementList'; + + private static string $title = 'Group'; + + private static string $description = 'Orderable list of elements'; + + private static string $singular_name = 'list'; + + private static string $plural_name = 'lists'; + + public function getType(): string + { + return _t(__CLASS__ . '.BlockType', 'List'); + } + + /** + * @return DBField + */ + public function getSummary(): string + { + $count = $this->Elements()->Elements()->Count(); + $suffix = $count === 1 ? 'element': 'elements'; + + return 'Contains ' . $count . ' ' . $suffix; + } + + /** + * Retrieve a elemental area relation name which this element owns + * + * @return string + */ + public function getOwnedAreaRelationName(): string + { + $has_one = $this->config()->get('has_one'); + + foreach ($has_one as $relationName => $relationClass) { + if ($relationClass === ElementalArea::class && $relationName !== 'Parent') { + return $relationName; + } + } + + return 'Elements'; + } + + public function inlineEditable(): bool + { + return false; + } +} diff --git a/templates/DNADesign/ElementalList/Model/ElementList.ss b/templates/DNADesign/ElementalList/Model/ElementList.ss new file mode 100644 index 0000000..e959465 --- /dev/null +++ b/templates/DNADesign/ElementalList/Model/ElementList.ss @@ -0,0 +1,6 @@ +<% if $ShowTitle %> +

$Title

+<% end_if %> +
+ $Elements +