Skip to content

Commit

Permalink
Merge branch 'master' into 1.0
Browse files Browse the repository at this point in the history
* master:
  type for gridfield on read only
  published icon also in modeladmin
  Lithuanian language translation added
  Hide blocks tab on no-blockable pages
  Create Croatian (.hr) translation
  Create Croatian (.hr) translation
  Add conditional logic
  allow type for grid field in block admin
  Minor: Making block type translatable
  block icon documentation
  readme refactoring
  type for gridfield
  typo
  published icon POC
  fixing breaks in gridfield
  • Loading branch information
sheadawson committed May 15, 2016
2 parents e3550c9 + 724ca00 commit f37385b
Show file tree
Hide file tree
Showing 9 changed files with 209 additions and 47 deletions.
102 changes: 66 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,43 @@

The Blocks modules aims to provide developers with a flexible foundation for defining reusable blocks of content or widgets that can be managed in the CMS.

### New Features in 1.0

* Blocks are now Versioned
* Block_Controller added - Blocks with Forms now possible
* BlockArea and Sort now managed on BlockSet_Blocks and SiteTree_Blocks many_many_ExtraFields
* Drag and Drop re-ordering of Blocks added
* Duplicate Block action now available in Block Admin
* Global Blocks removed - use BlockSets applied to all pages instead
* BlockSets and Block ExtraCSSClasses can be disabled in yaml config
* Block lists show "Used on" column, displaying Pages/Sets the Block is used on
## Features

* Blocks are Versioned
* Blocks with Forms possible (through `Block_Controller`)
* Drag and Drop re-ordering of Blocks
* Duplicate Blocks
* BlockSets for global blocks
* Allow exclusion of any page types from using Blocks
* Allow disabling of default/example block type - ContentBlock
* Allow disabling of specific blocks
* CMS Interfaces generally tidied up

### Upgrading from 0.x

1. Upgrade your module to the latest code, run dev/build
2. The database structure of Blocks 1.0 differs slightly from earier versions, so backup your database, cross your fingers and run dev/tasks/BlockUpgradeTask. This will adapt your current Block records to the new structure. See BlockUpgradeTask.php for exact details.
3. Check your blocks to make sure they're all happy.
## Upgrading from 0.x

See [the upgrade guide](docs/upgrading.md)

### Requirements
## Requirements

* SilverStripe CMS ~3.1
* [GridFieldExtensions](https://github.com/silverstripe-australia/silverstripe-gridfieldextensions)
* [MultivalueField](https://github.com/nyeholt/silverstripe-multivaluefield)
* [GridField BetterButtons](https://github.com/unclecheese/silverstripe-gridfield-betterbuttons)

### Recommended
## Recommended
* [GridField Copybutton](https://github.com/unisolutions/silverstripe-copybutton) (duplication of blocks, from BlockAdmin)

## Installation

#### Composer

composer require sheadawson/silverstripe-blocks
```sh
composer require sheadawson/silverstripe-blocks
```

Install via composer, run dev/build
Install via composer, run `dev/build`

## Quickstart

### 1. Define Block Areas and Settings for your theme in mysite/_config/config.yml
### 1. Define Block Areas and Settings for your theme in `mysite/_config/config.yml`

``` yml
BlockManager:
Expand All @@ -68,11 +63,11 @@ BlockManager:
block_area_preview: false # Disable block area preview button in CMS (default if undeclared: true)
```
Remember to run ?flush=1 after modifying your .yml config to make sure it gets applied.
Remember to run `?flush=1` after modifying your `.yml` config to make sure it gets applied.

### 2. Add Block Areas to your themes templates

Adding the BeforeContent and AfterContent blocks would look something like
Adding the `BeforeContent` and `AfterContent` blocks would look something like

```html
<article>
Expand All @@ -83,7 +78,7 @@ Adding the BeforeContent and AfterContent blocks would look something like
</article>
```

$BlockArea(BeforeContent) will loop over and display all blocks assigned to the BeforeContent area on the current page
`$BlockArea(BeforeContent)` will loop over and display all blocks assigned to the `BeforeContent` area on the current page

You can limit a block area to a maximum number of blocks using the second limit parameter

Expand All @@ -95,35 +90,46 @@ You can limit a block area to a maximum number of blocks using the second limit

### 3. Add Blocks to a page in the CMS

You will now be able to add Blocks to Pages via the CMS page edit view and in the Blocks model admin. You can also define "BlockSets" in the Blocks model admin. BlockSets can be used to apply a common collection of blocks to pages that match the criteria you define on the set.
You will now be able to add Blocks to Pages via the CMS page edit view and in the Blocks model admin. You can also define
"BlockSets" in the Blocks model admin. BlockSets can be used to apply a common collection of blocks to pages that match the criteria you define on the set.

This module ships with a basic `ContentBlock`, but this can be disabled through the `BlockManager::use_default_blocks config.

This module ships with a basic "ContentBlock", but this can be disabled through the BlockManager::use_default_blocks config.

#### Restrict Blocks to viewer groups or logged in users
## Help


### Restrict Blocks to viewer groups or logged in users

When editing a block, you can restrict who can see it in the frontend by selecting "logged in users" or "users from these groups" under the Viewer Groups tab.

### Templates

There are 2 types of templates you should be aware of.

#### BlockArea Template
### BlockArea Template

The BlockArea template is responsible for looping over and rendering all blocks in that area. You can override this by creating a copy of the default BlockArea.ss and placing it in your theme's templates/Includes folder.
The `BlockArea` template is responsible for looping over and rendering all blocks in that area. You can override this by
creating a copy of the default `BlockArea.ss` and placing it in your theme's `templates/Includes` folder.

It's likely that your block areas may require different templates. You can achieve this by creating a BlockArea_{AreaName}.ss template.
It's likely that your block areas may require different templates. You can achieve this by creating a `BlockArea_{AreaName}.ss` template.

#### Block Template
### Block Template

Each subclass of Block requires it's own template with the same name as the class. So, SlideshowBlock.php would have a SlideshowBlock.ss template. If your block requires different templates depending on the BlockArea it's in, you can create SlideshowBlock_{AreaName}.ss
Each subclass of Block requires it's own template with the same name as the class. So, `SlideshowBlock.php` would have a
`SlideshowBlock.ss` template. If your block requires different templates depending on the `BlockArea` it's in, you can
create `SlideshowBlock_{AreaName}.ss`

The current page scope can be accessed from Block templates with `$CurrentPage`.

### Block Area Preview

To aid website admins in identifying the areas they can apply blocks to, a "Preview Block Areas for this page" button is available in the cms. This opens the frontend view of the page in a new tab with ?block_preview=1. In Block Preview mode, Block Areas in the template are highlighted and labeled.
To aid website admins in identifying the areas they can apply blocks to, a "Preview Block Areas for this page" button
is available in the cms. This opens the frontend view of the page in a new tab with `?block_preview=1`.
In Block Preview mode, Block Areas in the template are highlighted and labeled.

There is some markup required in your BlockArea templates to facilitate this: The css class "block-area" and the data-areaid='$AreaID' attribute.
There is some markup required in your BlockArea templates to facilitate this: The css class `block-area` and the
`data-areaid='$AreaID'` attribute.

```html
<div class='block-area' data-areaid='$AreaID'>
Expand Down Expand Up @@ -159,7 +165,31 @@ The BlockAdmin section is not always needed to be used. If you wish, you can rem
CMSMenu::remove_menu_item('BlockAdmin');
```

### Screenshots
### Block icons

Until this module properly supports icons, you can define icons by creating a `getTypeForGridfield` method in your block.
Here's an example that uses font awesome:


```php
public function getIcon()
{
return '<i class="fa fa-thumbs-up fa-3x" title="' . $this->singular_name() . '" aria-hidden="true"></i>';
}
public function getTypeForGridfield()
{
$icon = $this->getIcon();
if ($icon) {
$obj = HTMLText::create();
$obj->setValue($icon);
return $obj;
} else {
return parent::getTypeForGridfield();
}
}
```

## Screenshots

![](docs/images/overview-1.0.png)
Overview
Expand Down
28 changes: 27 additions & 1 deletion code/dataobjects/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,32 @@ class Block extends DataObject implements PermissionProvider
public function fieldLabels($includerelations = true)
{
$labels = parent::fieldLabels($includerelations);

$labels = array_merge($labels, array(
'singular_name' => _t('Block.BlockType', 'Block Type'),
'Title' => _t('Block.Title', 'Title'),
'isPublishedField' => _t('Block.IsPublishedField', 'Published'),
'UsageListAsString' => _t('Block.UsageListAsString', 'Used on'),
'ExtraCSSClasses' => _t('Block.ExtraCSSClasses', 'Extra CSS Classes'),
'Content' => _t('Block.Content', 'Content'),
'ClassName' => 'Block Typeeee'
'ClassName' => _t('Block.BlockType', 'Block Type'),
));

return $labels;
}

public function getDefaultSearchContext()
{
$context = parent::getDefaultSearchContext();

$results = $this->blockManager->getBlockClasses();
if (sizeof($results) > 1) {
$classfield = new DropdownField('ClassName', _t('Block.BlockType', 'Block Type'));
$classfield->setSource($results);
$classfield->setEmptyString(_t('Block.Any', '(any)'));
$context->addField($classfield);
}

return $context;
}

Expand All @@ -97,6 +101,14 @@ public function getDefaultSearchContext()
*/
protected $controller;

/**
* @return mixed
*/
public function getTypeForGridfield()
{
return $this->singular_name();
}

public function getCMSFields()
{
Requirements::add_i18n_javascript(BLOCKS_DIR.'/javascript/lang');
Expand Down Expand Up @@ -410,6 +422,20 @@ public function isPublishedNice()
return $field->Nice();
}

/**
* @return HTMLText
*/
public function isPublishedIcon()
{
$obj = HTMLText::create();
if ($this->isPublished()) {
$obj->setValue('<img src="/framework/admin/images/alert-good.gif" />');
} else {
$obj->setValue('<img src="/framework/admin/images/alert-bad.gif" />');
}
return $obj;
}

/**
* CSS Classes to apply to block element in template.
*
Expand Down
2 changes: 0 additions & 2 deletions code/extensions/BlocksSiteTreeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ public function updateCMSFields(FieldList $fields)
$fields->addFieldToTab('Root.Blocks',
CheckboxField::create('InheritBlockSets', _t('BlocksSiteTreeExtension.InheritBlocksFromBlockSets', 'Inherit Blocks from Block Sets')));
}
} else {
$fields->addFieldToTab('Root.Blocks', LiteralField::create('Blocks', _t('BlocksSiteTreeExtension.NoBlockAreasConfigured', 'This page type has no Block Areas configured.')));
}
}

Expand Down
10 changes: 5 additions & 5 deletions code/forms/GridfieldConfig_BlockManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct($canAdd = true, $canEdit = true, $canDelete = true,
if ($editableRows) {
$this->addComponent($editable = new GridFieldEditableColumns());
$displayfields = array(
'singular_name' => array('title' => _t('Block.BlockType', 'Block Type'), 'field' => 'ReadonlyField'),
'TypeForGridfield' => array('title' => _t('Block.BlockType', 'Block Type'), 'field' => 'LiteralField'),
'Title' => array('title' => _t('Block.Title', 'Title'), 'field' => 'ReadonlyField'),
'BlockArea' => array(
'title' => _t('Block.BlockArea', 'Block Area').'
Expand All @@ -38,8 +38,8 @@ public function __construct($canAdd = true, $canEdit = true, $canDelete = true,
->setHasEmptyDefault(true);
},
),
'isPublishedNice' => array('title' => _t('Block.IsPublishedField', 'Published'), 'field' => 'ReadonlyField'),
'UsageListAsString' => array('title' => _t('Block.UsageListAsString', 'Used on'), 'field' => 'ReadonlyField'),
'isPublishedIcon' => array('title' => _t('Block.IsPublishedField', 'Published'), 'field' => 'LiteralField'),
'UsageListAsString' => array('title' => _t('Block.UsageListAsString', 'Used on'), 'field' => 'LiteralField'),
);

if ($aboveOrBelow) {
Expand All @@ -55,10 +55,10 @@ public function __construct($canAdd = true, $canEdit = true, $canDelete = true,
$this->addComponent($dcols = new GridFieldDataColumns());

$displayfields = array(
'singular_name' => _t('Block.BlockType', 'Block Type'),
'TypeForGridfield' => array('title' => _t('Block.BlockType', 'Block Type'), 'field' => 'LiteralField'),
'Title' => _t('Block.Title', 'Title'),
'BlockArea' => _t('Block.BlockArea', 'Block Area'),
'isPublishedNice' => _t('Block.IsPublishedField', 'Published'),
'isPublishedIcon' => array('title' => _t('Block.IsPublishedField', 'Published'), 'field' => 'LiteralField'),
'UsageListAsString' => _t('Block.UsageListAsString', 'Used on'),
);
$dcols->setDisplayFields($displayfields);
Expand Down
7 changes: 7 additions & 0 deletions docs/upgrading.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Upgrading

## Upgrading from 0.x

1. Upgrade your module to the latest code, run dev/build
2. The database structure of Blocks 1.0 differs slightly from earier versions, so backup your database, cross your fingers and run dev/tasks/BlockUpgradeTask. This will adapt your current Block records to the new structure. See BlockUpgradeTask.php for exact details.
3. Check your blocks to make sure they're all happy.
3 changes: 3 additions & 0 deletions javascript/lang/hr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ss.i18n.addDictionary('hr', {
'BLOCKS.ALERTCLASSNAME' : "Vrsta bloka će se ažurirati nakon spremanja stranice"
});
49 changes: 49 additions & 0 deletions lang/hr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
hr:
Block:
Any: (bilo koji)
BlockArea: 'Područje bloka'
BlockSetsAsString: 'Blok setovi: {sets}'
BlockType: 'Vrsta bloka'
Content: Sadržaj
CreateBlock: 'Kreiraj blok'
DeleteBlock: 'Obriši blok'
EditBlock: 'Uredi block'
ExtraCSSClasses: 'Dodatne CSS klase'
IsPublishedField: Objavljen
PLURALNAME: Blokovi
PagesAsString: 'Stranice: {pages}'
PermissionCategory: Blokovi
PublishBlock: 'Objavi blok'
SINGULARNAME: Blok
Title: Naslov
TitleRequired: 'Naslov bloka je obavezan'
UsageListAsString: 'Korišten na'
ViewerGroups: 'Grupe za pregled'
BlockAdmin:
MENUTITLE: Blokovi
BlockSet:
ApplyBlockSetToSelectedPageParentsAsWellAsChildren: 'Primjeni blok set na označene stranice roditelja kao i djece'
CreateBlockSet: 'Kreiraj blok set'
DeleteBlockSet: 'Obriši blok set'
EditBlockSet: 'Uredi blok set'
OnlyApplyToChildrenOfThesePages: 'Primjeni samo na djecu ovih stranica:'
OnlyApplyToThesePageTypes: 'Primjeni samo na ove tipove stranica:'
OnlyApplyToThesePageTypesDescription: 'Odabrani tipovi stranica će naslijediti ovaj blok set automatski. Ostavite sve neoznačeno kako bi primjenili na sve tipove stranica.'
PLURALNAME: 'Blok setovi'
SINGULARNAME: 'Blok set'
Settings: Postavke
YouCanAddBlocksToThisSetOnceYouHaveSavedIt: 'Možete dodati blokove na ovaj set nakon što ga spremite po prvi puta'
BlocksSiteTreeExtension:
BlocksInheritedFromBlockSets: 'Blokovi nasljeđeni iz blok setova'
DisableInheritedBlocks: 'Onemogući nasljeđivanje blokova'
DisableInheritedBlocksDescription: 'Označi samo nasljeđene blokove koje ne želite prikazati na ovoj stranici.'
InheritBlocksFromBlockSets: 'Nasljeđeni blokovi iz blok setova'
InheritedBlocksEditLink: 'Savjet: Nasljeđeni blokovi mogu se uređivati {link_start}Blok admin sekciji{link_end}'
NoBlockAreasConfigured: 'Ovaj tip stranice nema konfiguriranih blok područja.'
NoInheritedBlocksToDisable: 'Ova stranica nema nasljećenih blokova za onemogućavanje.'
PreviewBlockAreasLink: 'Pregled blok područja za ovu stranicu'
ContentBlock:
PLURALNAME: 'Sadržajni blokovi'
SINGULARNAME: 'Sadržajni blok'
GridFieldConfigBlockManager:
AboveOrBelow: 'Iznad ili ispod'
Loading

0 comments on commit f37385b

Please sign in to comment.