mirror of
https://github.com/dnadesign/silverstripe-elemental-list.git
synced 2024-10-22 11:05:47 +02:00
Initial commit
Split out element lists from the core module. The element list provides a base class for blocks to sit inside other blocks.
This commit is contained in:
commit
a9f840641d
17
.editorconfig
Normal file
17
.editorconfig
Normal file
@ -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
|
6
.gitattributes
vendored
Normal file
6
.gitattributes
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
/tests export-ignore
|
||||
/docs export-ignore
|
||||
/.gitattributes export-ignore
|
||||
/.gitignore export-ignore
|
||||
/.travis.yml export-ignore
|
||||
/.scrutinizer.yml export-ignore
|
12
.scrutinizer.yml
Normal file
12
.scrutinizer.yml
Normal file
@ -0,0 +1,12 @@
|
||||
inherit: true
|
||||
|
||||
tools:
|
||||
external_code_coverage: false
|
||||
|
||||
checks:
|
||||
php:
|
||||
code_rating: true
|
||||
duplication: true
|
||||
|
||||
filter:
|
||||
paths: [src/*, tests/*]
|
35
.travis.yml
Normal file
35
.travis.yml
Normal file
@ -0,0 +1,35 @@
|
||||
language: php
|
||||
|
||||
env:
|
||||
global:
|
||||
- COMPOSER_ROOT_VERSION=1.x-dev
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- php: 5.6
|
||||
env: DB=MYSQL PHPCS_TEST=1 PHPUNIT_TEST=1
|
||||
- php: 7.0
|
||||
env: DB=PGSQL PHPUNIT_TEST=1
|
||||
- php: 7.0
|
||||
env: DB=MYSQL PHPUNIT_TEST=1
|
||||
- php: 7.1
|
||||
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 1.0.x-dev --no-update
|
||||
- if [[ $DB == PGSQL ]]; then composer require silverstripe/postgresql:2.0.x-dev --no-update; fi
|
||||
- composer install --prefer-dist --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
|
29
LICENSE
Normal file
29
LICENSE
Normal file
@ -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.
|
6
_config/elemental.yml
Normal file
6
_config/elemental.yml
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
name: elemental-list
|
||||
---
|
||||
DNADesign/Elemental/Models/BaseElement:
|
||||
extensions:
|
||||
- DNADesign/ElementalList/Extensions/BaseElementExtension
|
1
codecov.yml
Normal file
1
codecov.yml
Normal file
@ -0,0 +1 @@
|
||||
comment: false
|
32
composer.json
Normal file
32
composer.json
Normal file
@ -0,0 +1,32 @@
|
||||
{
|
||||
"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": {
|
||||
"dnadesign/silverstripe-elemental": "2.x-dev",
|
||||
"silverstripe/vendor-plugin": "^1.0"
|
||||
},
|
||||
"extra": {
|
||||
"installer-name": "elemental-list",
|
||||
"branch-alias": {
|
||||
"dev-master": "1.x-dev"
|
||||
},
|
||||
"expose": [
|
||||
"images"
|
||||
]
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"DNADesign\\ElementalList\\": "src/",
|
||||
"DNADesign\\ElementalList\\Tests\\": "tests/php/"
|
||||
}
|
||||
}
|
||||
}
|
25
contributing.md
Normal file
25
contributing.md
Normal file
@ -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.
|
||||
|
4
images/list.svg
Normal file
4
images/list.svg
Normal file
@ -0,0 +1,4 @@
|
||||
<svg fill="#000000" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M0 0h24v24H0z" fill="none"/>
|
||||
<path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zM8 17.5c-1.38 0-2.5-1.12-2.5-2.5s1.12-2.5 2.5-2.5 2.5 1.12 2.5 2.5-1.12 2.5-2.5 2.5zM9.5 8c0-1.38 1.12-2.5 2.5-2.5s2.5 1.12 2.5 2.5-1.12 2.5-2.5 2.5S9.5 9.38 9.5 8zm6.5 9.5c-1.38 0-2.5-1.12-2.5-2.5s1.12-2.5 2.5-2.5 2.5 1.12 2.5 2.5-1.12 2.5-2.5 2.5z"/>
|
||||
</svg>
|
After Width: | Height: | Size: 479 B |
14
phpunit.xml.dist
Normal file
14
phpunit.xml.dist
Normal file
@ -0,0 +1,14 @@
|
||||
<phpunit bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true">
|
||||
<testsuite name="Default">
|
||||
<directory>tests/php</directory>
|
||||
</testsuite>
|
||||
|
||||
<filter>
|
||||
<whitelist addUncoveredFilesFromWhitelist="true">
|
||||
<directory suffix=".php">src/</directory>
|
||||
<exclude>
|
||||
<directory suffix=".php">tests/php</directory>
|
||||
</exclude>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
20
readme.md
Normal file
20
readme.md
Normal file
@ -0,0 +1,20 @@
|
||||
# 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.
|
||||
|
||||
## Installation
|
||||
|
||||
```
|
||||
composer require "dnadesign/silverstripe-elemental-list"
|
||||
```
|
||||
|
||||
|
51
src/Model/ElementList.php
Normal file
51
src/Model/ElementList.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace DNADesign\ElementalList\Model;
|
||||
|
||||
use DNADesign\Elemental\Models\BaseElement;
|
||||
use DNADesign\Elemental\Models\ElementalArea;
|
||||
use DNADesign\Elemental\Extensions\ElementalAreasExtension;
|
||||
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\ORM\ArrayList;
|
||||
use SilverStripe\ORM\FieldType\DBField;
|
||||
|
||||
class ElementList extends BaseElement
|
||||
{
|
||||
private static $icon = 'elemental-list/images/list.svg';
|
||||
|
||||
private static $has_one = [
|
||||
'Elements' => ElementalArea::class
|
||||
];
|
||||
|
||||
private static $owns = [
|
||||
'Elements'
|
||||
];
|
||||
|
||||
private static $cascade_deletes = [
|
||||
'Elements'
|
||||
];
|
||||
|
||||
private static $extensions = [
|
||||
ElementalAreasExtension::class
|
||||
];
|
||||
|
||||
private static $table_name = 'ElementList';
|
||||
|
||||
private static $title = 'Group';
|
||||
|
||||
private static $description = 'Orderable list of elements';
|
||||
|
||||
|
||||
/**
|
||||
* @return DBField
|
||||
*/
|
||||
public function ElementSummary()
|
||||
{
|
||||
$count = $this->Elements()->Count();
|
||||
$suffix = $count === 1 ? 'element': 'elements';
|
||||
$summary = $this->ListDescription ? DBField::create_field('HTMLText', $this->ListDescription)->Summary(10) . '<br />': '';
|
||||
|
||||
return DBField::create_field('HTMLText', $summary . ' <span class="el-meta">Contains ' . $count . ' ' . $suffix . '</span>');
|
||||
}
|
||||
}
|
3
templates/DNADesign/ElementalList/ElementList.ss
Normal file
3
templates/DNADesign/ElementalList/ElementList.ss
Normal file
@ -0,0 +1,3 @@
|
||||
<div class="listelement--container" data-listelement-count="$Elements.Elements.Count">
|
||||
$Elements
|
||||
</div>
|
26
tests/php/ElementListTest.php
Normal file
26
tests/php/ElementListTest.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace DNADesign\ElementalList\Tests;
|
||||
|
||||
use DNADesign\ElementalList\Model\ElementList;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
|
||||
class ElementListTest extends SapphireTest
|
||||
{
|
||||
public function testGetRelations()
|
||||
{
|
||||
$list = ElementList::create();
|
||||
|
||||
$this->assertEquals(['Elements'], $list->getElementalRelations());
|
||||
}
|
||||
|
||||
public function testGetCmsFields()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function testForTemplate()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
21
tests/php/ElementListTest.yml
Normal file
21
tests/php/ElementListTest.yml
Normal file
@ -0,0 +1,21 @@
|
||||
DNADesign\Elemental\Models\ElementalArea:
|
||||
area1:
|
||||
Title: Page A
|
||||
area2:
|
||||
Title: Element A
|
||||
DNADesign\Elemental\Tests\Src\TestPage:
|
||||
page1:
|
||||
Title: Page 1
|
||||
URLSegment: test-page
|
||||
ElementalAreaID: =>DNADesign\Elemental\Models\ElementalArea.area1
|
||||
DNADesign\ElementalList\Model\ElementList:
|
||||
listElement:
|
||||
Title: Element 1
|
||||
ParentID: =>DNADesign\Elemental\Models\ElementalArea.area1
|
||||
ElementsID: =>DNADesign\Elemental\Models\ElementalArea.area2
|
||||
DNADesign\Elemental\Tests\Src\TestElement:
|
||||
testContent:
|
||||
TestValue: foo
|
||||
ParentID: =>DNADesign\Elemental\Models\ElementalArea.area2
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user