Skip to content

Commit

Permalink
Merge branch 'master' into 1.0
Browse files Browse the repository at this point in the history
* master:
  Update README.md
  Remove translation from the todo list
  Create a Finnish translation.
  Make the module translatable.
  • Loading branch information
sheadawson committed Feb 28, 2016
2 parents c14e98d + c649423 commit c467563
Show file tree
Hide file tree
Showing 9 changed files with 205 additions and 65 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ BlockManager:
...
```

### Remove the Blocks button from the main CMS menu

The BlockAdmin section is not always needed to be used. If you wish, you can remove the button from the menu by inserting this to `mysite/_config.php`:

``` php
CMSMenu::remove_menu_item('BlockAdmin');
```

### Screenshots

![](docs/images/overview-1.0.png)
Expand All @@ -164,6 +172,5 @@ Add an existing block

## TODO

- [ ] Add language/translation support
- [ ] Re-add: Sorting primarily by Area (in order of declaration in config), on Pages (removed in favor of dr'ndr sorting)
- [ ] Add icon/pic to base Block as method of recognition when dealing with lots of different blocks
66 changes: 40 additions & 26 deletions code/dataobjects/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,40 @@ class Block extends DataObject implements PermissionProvider
);

private static $summary_fields = array(
'singular_name' => 'Block Type',
'Title' => 'Title',
'isPublishedField' => 'Published',
'UsageListAsString' => 'Used on',
'singular_name',
'Title',
'isPublishedField',
'UsageListAsString',
);

private static $searchable_fields = array(
'Title' => array(
'title' => 'Title'
),
'ClassName' => array(
'title' => 'Block Type'
)
'Title',
'ClassName',
);

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'
));
return $labels;
}

public function getDefaultSearchContext()
{
$context = parent::getDefaultSearchContext();
$results = $this->blockManager->getBlockClasses();
if (sizeof($results) > 1) {
$classfield = new DropdownField('ClassName', 'Block Type');
$classfield = new DropdownField('ClassName', _t('Block.BlockType', 'Block Type'));
$classfield->setSource($results);
$classfield->setEmptyString('(any)');
$classfield->setEmptyString(_t('Block.Any', '(any)'));
$context->addField($classfield);
}
return $context;
Expand Down Expand Up @@ -100,14 +111,14 @@ public function getCMSFields()

// ClassNmae - block type/class field
$classes = $this->blockManager->getBlockClasses();
$fields->addFieldToTab('Root.Main', DropdownField::create('ClassName', 'Block Type', $classes)->addExtraClass('block-type'), 'Title');
$fields->addFieldToTab('Root.Main', DropdownField::create('ClassName', _t('Block.BlockType', 'Block Type'), $classes)->addExtraClass('block-type'), 'Title');

// BlockArea - display areas field if on page edit controller
if (Controller::curr()->class == 'CMSPageEditController') {
$currentPage = Controller::curr()->currentPage();
$fields->addFieldToTab(
'Root.Main',
DropdownField::create('ManyMany[BlockArea]', 'BlockArea', $this->blockManager->getAreasForPageType($currentPage->ClassName))
DropdownField::create('ManyMany[BlockArea]', _t('Block.BlockArea','Block Area'), $this->blockManager->getAreasForPageType($currentPage->ClassName))
->setHasEmptyDefault(true)
->setRightTitle($currentPage->areasPreviewButton()),
'ClassName'
Expand Down Expand Up @@ -149,6 +160,7 @@ public function getCMSFields()
$viewersOptionsSource['OnlyTheseUsers'] = _t('SiteTree.ACCESSONLYTHESE', 'Only these people (choose from list)');
$viewersOptionsField->setSource($viewersOptionsSource)->setValue('Anyone');

$fields->addFieldToTab('Root', new Tab('ViewerGroups', _t('Block.ViewerGroups', 'Viewer Groups')));
$fields->addFieldsToTab('Root.ViewerGroups', array(
$viewersOptionsField,
$viewerGroupsField,
Expand Down Expand Up @@ -183,7 +195,7 @@ public function validate()
$result = parent::validate();

if (!$this->Title) {
$result->error('Block Title is required');
$result->error(_t('Block.TitleRequired', 'Block Title is required'));
}

return $result;
Expand Down Expand Up @@ -305,20 +317,20 @@ public function providePermissions()
{
return array(
'BLOCK_EDIT' => array(
'name' => 'Edit a Block',
'category' => 'Blocks',
'name' => _t('Block.EditBlock', 'Edit a Block'),
'category' => _t('Block.PermissionCategory', 'Blocks'),
),
'BLOCK_DELETE' => array(
'name' => 'Delete a Block',
'category' => 'Blocks',
'name' => _t('Block.DeleteBlock', 'Delete a Block'),
'category' => _t('Block.PermissionCategory', 'Blocks'),
),
'BLOCK_CREATE' => array(
'name' => 'Create a Block',
'category' => 'Blocks',
'name' => _t('Block.CreateBlock', 'Create a Block'),
'category' => _t('Block.PermissionCategory', 'Blocks'),
),
'BLOCK_PUBLISH' => array(
'name' => 'Publish a Block',
'category' => 'Blocks',
'name' => _t('Block.PublishBlock', 'Publish a Block'),
'category' => _t('Block.PermissionCategory', 'Blocks'),
),
);
}
Expand Down Expand Up @@ -353,14 +365,16 @@ public function UsageListAsString()
{
$pages = implode(', ', $this->Pages()->column('URLSegment'));
$sets = implode(', ', $this->BlockSets()->column('Title'));
$_t_pages = _t('Block.PagesAsString', 'Pages: {pages}', '', array('pages' => $pages));
$_t_sets = _t('Block.BlockSetsAsString', 'Block Sets: {sets}', '', array('sets' => $sets));
if ($pages && $sets) {
return "Pages: $pages<br />Block Sets: $sets";
return "$_t_pages<br />$_t_sets";
}
if ($pages) {
return "Pages: $pages";
return $_t_pages;
}
if ($sets) {
return "Block Sets: $sets";
return $_t_sets;
}
}

Expand Down
28 changes: 14 additions & 14 deletions code/dataobjects/BlockSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ public function getCMSFields()

$fields->removeFieldFromTab('Root', 'PageParents');

$fields->addFieldToTab('Root.Main', HeaderField::create('SettingsHeading', 'Settings'), 'Title');
$fields->addFieldToTab('Root.Main', MultiValueCheckboxField::create('PageTypes', 'Only apply to these Page Types:', $this->pageTypeOptions())
->setDescription('Selected Page Types will inherit this Block Set automatically. Leave all unchecked to apply to all page types.'));
$fields->addFieldToTab('Root.Main', TreeMultiselectField::create('PageParents', 'Only apply to children of these Pages:', 'SiteTree'));
$fields->addFieldToTab('Root.Main', CheckboxField::create('IncludePageParent', 'Apply block set to selected page parents as well as children'));
$fields->addFieldToTab('Root.Main', HeaderField::create('SettingsHeading', _t('BlockSet.Settings', 'Settings')), 'Title');
$fields->addFieldToTab('Root.Main', MultiValueCheckboxField::create('PageTypes', _t('BlockSet.OnlyApplyToThesePageTypes', 'Only apply to these Page Types:'), $this->pageTypeOptions())
->setDescription(_t('BlockSet.OnlyApplyToThesePageTypesDescription', 'Selected Page Types will inherit this Block Set automatically. Leave all unchecked to apply to all page types.')));
$fields->addFieldToTab('Root.Main', TreeMultiselectField::create('PageParents', _t('BlockSet.OnlyApplyToChildrenOfThesePages', 'Only apply to children of these Pages:'), 'SiteTree'));
$fields->addFieldToTab('Root.Main', CheckboxField::create('IncludePageParent', _t('BlockSet.ApplyBlockSetToSelectedPageParentsAsWellAsChildren','Apply block set to selected page parents as well as children')));

if (!$this->ID) {
$fields->addFieldToTab('Root.Main', LiteralField::create('NotSaved', "<p class='message warning'>You can add Blocks to this set once you have saved it for the first time</p>"));
$fields->addFieldToTab('Root.Main', LiteralField::create('NotSaved', "<p class='message warning'>"._t('BlockSet.YouCanAddBlocksToThisSetOnceYouHaveSavedIt', 'You can add Blocks to this set once you have saved it for the first time').'</p>'));

return $fields;
}
Expand All @@ -67,8 +67,8 @@ public function getCMSFields()

$gridSource = $this->Blocks()->Sort('Sort');

$fields->addFieldToTab('Root.Main', HeaderField::create('BlocksHeading', 'Blocks'));
$fields->addFieldToTab('Root.Main', GridField::create('Blocks', 'Blocks', $gridSource, $gridConfig));
$fields->addFieldToTab('Root.Main', HeaderField::create('BlocksHeading', _t('Block.PLURALNAME', 'Blocks')));
$fields->addFieldToTab('Root.Main', GridField::create('Blocks', _t('Block.PLURALNAME', 'Blocks'), $gridSource, $gridConfig));

return $fields;
}
Expand Down Expand Up @@ -138,16 +138,16 @@ public function providePermissions()
{
return array(
'BLOCKSET_EDIT' => array(
'name' => 'Edit a Block Set',
'category' => 'Blocks',
'name' => _t('BlockSet.EditBlockSet','Edit a Block Set'),
'category' => _t('Block.PermissionCategory', 'Blocks'),
),
'BLOCKSET_DELETE' => array(
'name' => 'Delete a Block Set',
'category' => 'Blocks',
'name' => _t('BlockSet.DeleteBlockSet','Delete a Block Set'),
'category' => _t('Block.PermissionCategory', 'Blocks'),
),
'BLOCKSET_CREATE' => array(
'name' => 'Create a Block Set',
'category' => 'Blocks',
'name' => _t('BlockSet.CreateBlockSet','Create a Block Set'),
'category' => _t('Block.PermissionCategory', 'Blocks'),
),
);
}
Expand Down
21 changes: 19 additions & 2 deletions code/dataobjects/ContentBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,25 @@

class ContentBlock extends Block
{
private static $singular_name = 'Content Block';
private static $plural_name = 'Content Blocks';
/**
* If the singular name is set in a private static $singular_name, it cannot be changed using the translation files
* for some reason. Fix it by defining a method that handles the translation.
* @return string
*/
public function singular_name()
{
return _t('ContentBlock.SINGULARNAME', 'Content Block');
}

/**
* If the plural name is set in a private static $plural_name, it cannot be changed using the translation files
* for some reason. Fix it by defining a method that handles the translation.
* @return string
*/
public function plural_name()
{
return _t('ContentBlock.PLURALNAME', 'Content Blocks');
}

private static $db = array(
'Content' => 'HTMLText',
Expand Down
21 changes: 11 additions & 10 deletions code/extensions/BlocksSiteTreeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function updateCMSFields(FieldList $fields)
$areas = $this->blockManager->getAreasForPageType($this->owner->ClassName);

if ($areas && count($areas)) {
$fields->addFieldToTab('Root', new Tab('Blocks', _t('Block.PLURALNAME')));
$fields->addFieldToTab('Root.Blocks',
LiteralField::create('PreviewLink', $this->areasPreviewButton()));

Expand All @@ -61,7 +62,7 @@ public function updateCMSFields(FieldList $fields)
// 'Name' => 'ASC'
// ));

$fields->addFieldToTab('Root.Blocks', GridField::create('Blocks', 'Blocks', $gridSource, $gridConfig));
$fields->addFieldToTab('Root.Blocks', GridField::create('Blocks', _t('Block.PLURALNAME', 'Blocks'), $gridSource, $gridConfig));

// Blocks inherited from BlockSets
if ($this->blockManager->getUseBlockSets()) {
Expand All @@ -72,28 +73,28 @@ public function updateCMSFields(FieldList $fields)

if ($activeInherited->count()) {
$fields->addFieldsToTab('Root.Blocks', array(
GridField::create('InheritedBlockList', 'Blocks Inherited from Block Sets', $activeInherited,
GridField::create('InheritedBlockList', _t('BlocksSiteTreeExtension.BlocksInheritedFromBlockSets', 'Blocks Inherited from Block Sets'), $activeInherited,
GridFieldConfig_BlockManager::create(false, false, false)),
LiteralField::create('InheritedBlockListTip', "<p class='message'>Tip: Inherited blocks can be edited in the <a href='admin/block-admin'>Block Admin area</a><p>"),
LiteralField::create('InheritedBlockListTip', "<p class='message'>"._t('BlocksSiteTreeExtension.InheritedBlocksEditLink', 'Tip: Inherited blocks can be edited in the {link_start}Block Admin area{link_end}', '', array('link_start' => '<a href="admin/block-admin">', 'link_end' => '</a>')).'<p>'),
));
}

$fields->addFieldToTab('Root.Blocks',
ListBoxField::create('DisabledBlocks', 'Disable Inherited Blocks',
ListBoxField::create('DisabledBlocks', _t('BlocksSiteTreeExtension.DisableInheritedBlocks', 'Disable Inherited Blocks'),
$inheritedBlocks->map('ID', 'Title'), null, null, true)
->setDescription('Select any inherited blocks that you would not like displayed on this page.')
->setDescription(_t('BlocksSiteTreeExtension.DisableInheritedBlocksDescription', 'Select any inherited blocks that you would not like displayed on this page.'))
);
} else {
$fields->addFieldToTab('Root.Blocks',
ReadonlyField::create('DisabledBlocksReadOnly', 'Disable Inherited Blocks',
'This page has no inherited blocks to disable.'));
ReadonlyField::create('DisabledBlocksReadOnly', _t('BlocksSiteTreeExtension.DisableInheritedBlocks', 'Disable Inherited Blocks'),
_t('BlocksSiteTreeExtension.NoInheritedBlocksToDisable','This page has no inherited blocks to disable.')));
}

$fields->addFieldToTab('Root.Blocks',
CheckboxField::create('InheritBlockSets', 'Inherit Blocks from Block Sets'));
CheckboxField::create('InheritBlockSets', _t('BlocksSiteTreeExtension.InheritBlocksFromBlockSets', 'Inherit Blocks from Block Sets')));
}
} else {
$fields->addFieldToTab('Root.Blocks', LiteralField::create('Blocks', 'This page type has no Block Areas configured.'));
$fields->addFieldToTab('Root.Blocks', LiteralField::create('Blocks', _t('BlocksSiteTreeExtension.NoBlockAreasConfigured', 'This page type has no Block Areas configured.')));
}
}

Expand Down Expand Up @@ -291,6 +292,6 @@ public function areasPreviewLink()
* */
public function areasPreviewButton()
{
return "<a class='ss-ui-button ss-ui-button-small' style='font-style:normal;' href='".$this->areasPreviewLink()."' target='_blank'>Preview Block Areas for this page</a>";
return "<a class='ss-ui-button ss-ui-button-small' style='font-style:normal;' href='".$this->areasPreviewLink()."' target='_blank'>"._t('BlocksSiteTreeExtension.PreviewBlockAreasLink', 'Preview Block Areas for this page').'</a>';
}
}
24 changes: 12 additions & 12 deletions code/forms/GridfieldConfig_BlockManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,26 @@ public function __construct($canAdd = true, $canEdit = true, $canDelete = true,
if ($editableRows) {
$this->addComponent($editable = new GridFieldEditableColumns());
$displayfields = array(
'singular_name' => array('title' => 'Block Type', 'field' => 'ReadonlyField'),
'Title' => array('title' => 'Title', 'field' => 'ReadonlyField'),
'singular_name' => array('title' => _t('Block.BlockType', 'Block Type'), 'field' => 'ReadonlyField'),
'Title' => array('title' => _t('Block.Title', 'Title'), 'field' => 'ReadonlyField'),
'BlockArea' => array(
'title' => 'Block Area
'title' => _t('Block.BlockArea', 'Block Area').'
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
// the &nbsp;s prevent wrapping of dropdowns
'callback' => function () use ($areasFieldSource) {
return DropdownField::create('BlockArea', 'Block Area', $areasFieldSource)
->setHasEmptyDefault(true);
},
),
'isPublishedNice' => array('title' => 'Published', 'field' => 'ReadonlyField'),
'UsageListAsString' => array('title' => 'Used on', 'field' => 'ReadonlyField'),
'isPublishedNice' => array('title' => _t('Block.IsPublishedField', 'Published'), 'field' => 'ReadonlyField'),
'UsageListAsString' => array('title' => _t('Block.UsageListAsString', 'Used on'), 'field' => 'ReadonlyField'),
);

if ($aboveOrBelow) {
$displayfields['AboveOrBelow'] = array(
'title' => 'Above or Below',
'title' => _t('GridFieldConfigBlockManager.AboveOrBelow', 'Above or Below'),
'callback' => function () {
return DropdownField::create('AboveOrBelow', 'Above or Below', BlockSet::config()->get('above_or_below_options'));
return DropdownField::create('AboveOrBelow', _t('GridFieldConfigBlockManager.AboveOrBelow', 'Above or Below'), BlockSet::config()->get('above_or_below_options'));
},
);
}
Expand All @@ -55,11 +55,11 @@ public function __construct($canAdd = true, $canEdit = true, $canDelete = true,
$this->addComponent($dcols = new GridFieldDataColumns());

$displayfields = array(
'singular_name' => 'Block Type',
'Title' => 'Title',
'BlockArea' => 'Block Area',
'isPublishedNice' => 'Published',
'UsageListAsString' => 'Used on',
'singular_name' => _t('Block.BlockType', 'Block Type'),
'Title' => _t('Block.Title', 'Title'),
'BlockArea' => _t('Block.BlockArea', 'Block Area'),
'isPublishedNice' => _t('Block.IsPublishedField', 'Published'),
'UsageListAsString' => _t('Block.UsageListAsString', 'Used on'),
);
$dcols->setDisplayFields($displayfields);
$dcols->setFieldCasting(array('UsageListAsString' => 'HTMLText->Raw'));
Expand Down
3 changes: 3 additions & 0 deletions javascript/lang/fi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ss.i18n.addDictionary('fi', {
'BLOCKS.ALERTCLASSNAME' : "Laatikon tyyppi päivitetään kun sivu tallennetaan"
});
Loading

0 comments on commit c467563

Please sign in to comment.