Skip to content

Commit

Permalink
Restore repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Thomson authored and Julian Thomson committed Aug 23, 2024
0 parents commit 63f61fc
Show file tree
Hide file tree
Showing 16 changed files with 347 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions .tx/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[main]
host = https://www.transifex.com

[silverstripe-elemental-list.master]
file_filter = lang/<lang>.yml
source_file = lang/en.yml
source_lang = en
type = YML
2 changes: 2 additions & 0 deletions .upgrade.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mappings:
ElementList: DNADesign\ElementalList\Model\ElementList
29 changes: 29 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
8 changes: 8 additions & 0 deletions _config/elemental.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
name: elemental-list
---
DNADesign\Elemental\Models\BaseElement:
extensions:
- DNADesign\ElementalList\Extension\BaseElementCMSEditLinkExtension
DNADesign\ElementalList\Model\ElementalList:
inline_editable: false
1 change: 1 addition & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
comment: false
35 changes: 35 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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/"
}
}
}
25 changes: 25 additions & 0 deletions contributing.md
Original file line number Diff line number Diff line change
@@ -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.

8 changes: 8 additions & 0 deletions lang/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
en:
DNADesign\ElementalList\Model\ElementList:
BlockType: List
PLURALNAME: lists
PLURALS:
one: 'A list'
other: '{count} lists'
SINGULARNAME: list
8 changes: 8 additions & 0 deletions lang/fr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fr:
DNADesign\ElementalList\Model\ElementList:
BlockType: Liste
PLURALNAME: listes
PLURALS:
one: 'Une liste'
other: '{count} listes'
SINGULARNAME: liste
16 changes: 16 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true">
<testsuites>
<testsuite name="Default">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src/</directory>
<exclude>
<directory suffix=".php">tests/</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
28 changes: 28 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -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"
```


58 changes: 58 additions & 0 deletions src/Extension/BaseElementCMSEditLinkExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace DNADesign\ElementalList\Extension;

use DNADesign\Elemental\Models\BaseElement;
use DNADesign\ElementalList\Model\ElementList;
use SilverStripe\CMS\Controllers\CMSPageEditController;
use SilverStripe\Control\Controller;
use SilverStripe\Core\Extension;

/**
* BaseElement can be nested, CMSEditLink() needs to be updated to reflect that
*
* @property BaseElementCMSEditLinkExtension|$this $owner
*/
class BaseElementCMSEditLinkExtension extends Extension
{
/**
* @param string $link
*/
public function updateCMSEditLink(?string &$link): void
{
/** @var $owner BaseElement */
$owner = $this->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'
);
}
}
86 changes: 86 additions & 0 deletions src/Model/ElementList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

namespace DNADesign\ElementalList\Model;

use DNADesign\Elemental\Models\BaseElement;
use DNADesign\Elemental\Models\ElementalArea;
use DNADesign\Elemental\Extensions\ElementalAreasExtension;
use SilverStripe\ORM\FieldType\DBField;

/**
* @property int $ElementsID
* @method ElementalArea Elements()
*/
class ElementList extends BaseElement
{
private static string $icon = 'font-icon-block-file-list';

private static array $has_one = [
'Elements' => 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;
}
}
6 changes: 6 additions & 0 deletions templates/DNADesign/ElementalList/Model/ElementList.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<% if $ShowTitle %>
<h2 class="list-element__title">$Title</h2>
<% end_if %>
<div class="list-element__container" data-listelement-count="$Elements.Elements.Count">
$Elements
</div>

0 comments on commit 63f61fc

Please sign in to comment.