Skip to content
This repository was archived by the owner on May 31, 2022. It is now read-only.

Commit a730313

Browse files
author
Matthias Leutenegger
committed
Touchup
1 parent cbdcf58 commit a730313

File tree

8 files changed

+99
-69
lines changed

8 files changed

+99
-69
lines changed

README.md

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SilverStripe elemental bootstrap listgroup section
1+
# SilverStripe elemental bootstrap list group section
22

33
[![Build Status](https://travis-ci.com/syntro-opensource/silverstripe-elemental-bootstrap-listgroupsection.svg?branch=master)](https://travis-ci.com/syntro-opensource/silverstripe-elemental-bootstrap-listgroupsection)
44
[![phpstan](https://img.shields.io/badge/PHPStan-enabled-success)](https://github.com/phpstan/phpstan)
@@ -10,7 +10,10 @@ This module is part of a larger collection. See
1010
[`syntro/silverstripe-elemental-bootstrap-collection`](https://github.com/syntro-opensource/silverstripe-elemental-bootstrap-collection)
1111
for details.
1212

13-
Provides a simple section displaying a listgroup.
13+
Provides a simple section displaying a list group.
14+
15+
![list](docs/img/list.png "List")
16+
1417

1518
## Requirements
1619

@@ -30,23 +33,8 @@ See [License](license.md)
3033

3134
## Documentation
3235

33-
* [Customize](docs/en/customizing.md)
34-
35-
<!-- ## Example configuration (optional)
36-
If your module makes use of the config API in SilverStripe it's a good idea to provide an example config
37-
here that will get the module working out of the box and expose the user to the possible configuration options.
38-
39-
Provide a yaml code example where possible.
40-
41-
```yaml
42-
43-
Page:
44-
config_option: true
45-
another_config:
46-
- item1
47-
- item2
36+
All configuration options follow [the base items config](https://github.com/syntro-opensource/silverstripe-elemental-bootstrap-baseitems#documentation).
4837

49-
``` -->
5038

5139
## Maintainers
5240
* Matthias Leutenegger <hello@syntro.ch>

composer.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "syntro/silverstripe-elemental-bootstrap-listgroupsection",
3-
"description": "A bootsttrap based accordion section",
3+
"description": "A bootstrap based list section",
44
"type": "silverstripe-vendormodule",
55
"keywords": [
66
"silverstripe",
@@ -12,6 +12,8 @@
1212
"silverstripe/framework": "^4.0",
1313
"silverstripe/admin": "^1.0",
1414
"dnadesign/silverstripe-elemental": "^4",
15+
"gorriecoe/silverstripe-link": "^1",
16+
"gorriecoe/silverstripe-linkfield": "^1",
1517
"syntro/silverstripe-elemental-bootstrap-baseitems": "dev-master",
1618
"syntro/silverstripe-elemental-icons": "dev-master"
1719
},
@@ -28,11 +30,6 @@
2830
"phpunit": "../../bin/phpunit -c 'phpunit.xml.dev'",
2931
"phpunit-flush": "../../bin/phpunit . '' flush=1"
3032
},
31-
"extra": {
32-
"expose": [
33-
"client"
34-
]
35-
},
3633
"autoload": {
3734
"psr-4": {
3835
"Syntro\\SilverStripeElementalBootstrapAccordionSection\\": "src/",

docs/en/customizing.md

Lines changed: 0 additions & 15 deletions
This file was deleted.

docs/en/img/list.png

932 KB
Loading

lang/de.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
de:
22
Syntro\SilverStripeElementalBootstrapListgroupSection\Elements\ListgroupSection:
3-
BlockType: Listen-Abschnitt
3+
BlockType: Listen Abschnitt
4+
LISTITEMS: Listen Einträge
5+
CONTENT: Inhalt
6+
SUMMARY:
7+
one: 'Ein Eintrag'
8+
other: '{count} Einträge'
9+
Syntro\SilverStripeElementalBootstrapListgroupSection\Model\ListgroupItem:
10+
IMAGE: Bild
11+
TITLE: Titel
12+
CONTENT: Inhalt
13+
CALLTOACTIONLINK: Call to action Link

src/Elements/ListgroupSection.php

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Syntro\SilverStripeElementalBaseitems\Elements\BootstrapSectionBaseElement;
1616
use Syntro\SilverStripeElementalBootstrapListgroupSection\Model\ListgroupItem;
1717

18-
1918
/**
2019
* Bootstrap based Listgroup section
2120
*
@@ -64,16 +63,7 @@ class ListgroupSection extends BootstrapSectionBaseElement
6463
* @config
6564
* @var array
6665
*/
67-
private static $background_colors = [
68-
'default' => 'Default',
69-
'light' => 'Lightgrey',
70-
'dark' => 'Dark',
71-
];
72-
73-
private static $text_colors = [
74-
'default' => 'Default',
75-
'white' => 'White'
76-
];
66+
private static $background_colors = [];
7767

7868
/**
7969
* Color mapping from background color. This is mainly intended
@@ -83,10 +73,7 @@ class ListgroupSection extends BootstrapSectionBaseElement
8373
* @config
8474
* @var array
8575
*/
86-
private static $text_colors_by_background = [
87-
'light' => 'default',
88-
'dark' => 'light',
89-
];
76+
private static $text_colors_by_background = [];
9077

9178
private static $db = [
9279
'Content' => 'Text',
@@ -103,13 +90,29 @@ class ListgroupSection extends BootstrapSectionBaseElement
10390
'ListgroupItems'
10491
];
10592

93+
/**
94+
* fieldLabels - apply labels
95+
*
96+
* @param boolean $includerelations = true
97+
* @return array
98+
*/
99+
public function fieldLabels($includerelations = true)
100+
{
101+
$labels = parent::fieldLabels($includerelations);
102+
$labels['ListgroupItems'] = _t(__CLASS__ . '.LISTITEMS', 'List items');
103+
$labels['Content'] = _t(__CLASS__ . '.CONTENT', 'Content');
104+
return $labels;
105+
}
106+
106107
/**
107108
* @return FieldList
108109
*/
109110
public function getCMSFields()
110111
{
111112
$this->beforeUpdateCMSFields(function ($fields) {
112113

114+
$fields->dataFieldByName('Content')->setTitle($this->fieldLabel('Content'));
115+
113116
if ($this->ID) {
114117
/** @var GridField $items */
115118
$items = $fields->dataFieldByName('ListgroupItems');
@@ -125,7 +128,6 @@ public function getCMSFields()
125128

126129
$fields->addFieldToTab('Root.Main', $items);
127130
}
128-
129131
});
130132

131133
return parent::getCMSFields();
@@ -136,7 +138,15 @@ public function getCMSFields()
136138
*/
137139
public function getSummary()
138140
{
139-
return DBField::create_field('HTMLText', $this->Content)->Summary(20);
141+
return sprintf(
142+
'%s: "%s"',
143+
_t(
144+
__CLASS__ . '.SUMMARY',
145+
'one item|{count} items',
146+
['count' => $this->ListgroupItems()->count()]
147+
),
148+
implode('", "', $this->ListgroupItems()->map('Title')->keys())
149+
);
140150
}
141151

142152
/**
@@ -149,6 +159,11 @@ protected function provideBlockSchema()
149159
return $blockSchema;
150160
}
151161

162+
/**
163+
* getType - get type
164+
*
165+
* @return string
166+
*/
152167
public function getType()
153168
{
154169
return _t(__CLASS__ . '.BlockType', 'Listgroup Section');

src/Model/ListgroupItem.php

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
<?php
2+
23
namespace Syntro\SilverStripeElementalBootstrapListgroupSection\Model;
34

45
use SilverStripe\Forms\TextField;
56
use SilverStripe\Assets\Image;
67
use SilverStripe\Forms\TextareaField;
8+
use SilverStripe\Forms\FieldList;
79
use SilverStripe\AssetAdmin\Forms\UploadField;
10+
use gorriecoe\Link\Models\Link;
11+
use gorriecoe\LinkField\LinkField;
812
use Syntro\SilverStripeElementalBaseitems\Model\BaseItem;
913
use Syntro\SilverStripeElementalBootstrapListgroupSection\Elements\ListgroupSection;
1014

@@ -37,19 +41,43 @@ class ListgroupItem extends BaseItem
3741
private static $has_one = [
3842
'Section' => ListgroupSection::class,
3943
'Image' => Image::class,
44+
'CTALink' => Link::class
4045
];
4146

4247
/**
4348
* @var array
4449
*/
4550
private static $owns = [
46-
'Image'
51+
'Image',
52+
'CTALink'
4753
];
4854

4955
private static $defaults = [
5056
'ShowTitle' => true
5157
];
5258

59+
private static $summary_fields = [
60+
'Image.StripThumbnail',
61+
'Title'
62+
];
63+
64+
/**
65+
* fieldLabels - apply labels
66+
*
67+
* @param boolean $includerelations = true
68+
* @return array
69+
*/
70+
public function fieldLabels($includerelations = true)
71+
{
72+
$labels = parent::fieldLabels($includerelations);
73+
$labels['Image.StripThumbnail'] = _t(__CLASS__ . '.IMAGE', 'Image');
74+
$labels['Image'] = _t(__CLASS__ . '.IMAGE', 'Image');
75+
$labels['Title'] = _t(__CLASS__ . '.TITLE', 'Title');
76+
$labels['Content'] = _t(__CLASS__ . '.CONTENT', 'Content');
77+
$labels['CTALink'] = _t(__CLASS__ . '.CALLTOACTIONLINK', 'Call to action Link');
78+
return $labels;
79+
}
80+
5381
/**
5482
* @return FieldList
5583
*/
@@ -60,28 +88,28 @@ public function getCMSFields()
6088
$fields->removeByName([
6189
'Sort',
6290
'SectionID',
91+
'CTALinkID'
6392
]);
6493

6594
// Add Image Upload Field
6695
$fields->addFieldToTab(
6796
'Root.Main',
6897
$imageField = UploadField::create(
6998
'Image',
70-
'Image'
99+
$this->fieldLabel('Image')
71100
),
72101
'Content'
73102
);
74103
$imageField->setFolderName('Uploads/ListgroupItems');
75104

76-
// Add content field
77-
// $fields->addFieldToTab(
78-
// 'Root.Main',
79-
// TextareaField::create(
80-
// 'Content',
81-
// 'Content'
82-
// ),
83-
// 'CTALink'
84-
// );
105+
$fields->addFieldToTab(
106+
'Root.Main',
107+
LinkField::create(
108+
'CTALink',
109+
$this->fieldLabel('CTALink'),
110+
$this
111+
)
112+
);
85113
});
86114

87115
return parent::getCMSFields();

templates/Syntro/BootstrapElemental/Blocks/ListgroupSection.ss

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<div class="col-12">
1717
<ul class="list-group shadow">
1818
<% loop ListgroupItems %>
19-
<li class="list-group-item text-left">
19+
<li class="list-group-item text-left text-dark">
2020
<div class="row align-items-center">
2121
<% if Image %>
2222
<div class="col-12 col-md-4 col-lg-3 mb-3 mb-md-0">
@@ -28,6 +28,13 @@
2828
<h3>$Title</h3>
2929
<% end_if %>
3030
$Content
31+
<% if CTALink %>
32+
<% with CTALink %>
33+
<a {$IDAttr} class="mx-1 text-$Up.LinkColor" href="{$LinkURL}"{$TargetAttr}>
34+
{$Title}
35+
</a>
36+
<% end_with %>
37+
<% end_if %>
3138
</div>
3239
</div>
3340
</li>

0 commit comments

Comments
 (0)