Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamminf committed Sep 10, 2016
2 parents 7feeedd + e409270 commit 7bb691b
Show file tree
Hide file tree
Showing 20 changed files with 153 additions and 55 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
## Changelog

#### v1.3.5
- `Improved` Added German translations
- `Improved` Localised Neo fields can now contain fields that are also localised
- `Fixed` Entry draft preview links now work correctly with Neo fields
- `Fixed` Neo fields with Redactor (rich text) fields no longer always trigger "Do you like to leave?" prompt
- `Fixed` Duplicating a block now duplicates into the correct locale
- `Fixed` Fixed ordering of child block checkboxes (hopefully for the last time)

#### v1.3.4
- `Improved` Updated Javascript dependencies
- `Fixed` Fixed issues with Neo fields not updating correctly when publishing entry drafts
Expand Down
4 changes: 2 additions & 2 deletions neo/NeoPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function getDescription()

public function getVersion()
{
return '1.3.4';
return '1.3.5';
}

public function getCraftMinimumVersion()
Expand All @@ -37,7 +37,7 @@ public function getPHPMinimumVersion()

public function getSchemaVersion()
{
return '1.2.0';
return '1.3.5';
}

public function getDeveloper()
Expand Down
2 changes: 2 additions & 0 deletions neo/controllers/NeoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function actionRenderBlocks()

$blocks = craft()->request->getPost('blocks');
$namespace = craft()->request->getPost('namespace');
$locale = craft()->request->getPost('locale');

$renderedBlocks = [];

Expand All @@ -53,6 +54,7 @@ public function actionRenderBlocks()
$block->level = $rawBlock['level'];
$block->enabled = isset($rawBlock['enabled']);
$block->collapsed = isset($rawBlock['collapsed']);
$block->locale = $locale;

if(!empty($rawBlock['content']))
{
Expand Down
17 changes: 14 additions & 3 deletions neo/fieldtypes/NeoFieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ public function getSettingsHtml()
"Name",
"What this block type will be called in the CP.",
"Handle",
"How you'll refer to this block type in the templates.",
"How youll refer to this block type in the templates.",
"Max Blocks",
"The maximum number of blocks of this type the field is allowed to have.",
"All",
Expand Down Expand Up @@ -440,6 +440,8 @@ public function getInputHtml($name, $value)

$id = craft()->templates->formatInputId($name);
$settings = $this->getSettings();
$field = $settings->getField();
$translatable = $field ? (bool) $field->translatable : false;

if($value instanceof ElementCriteriaModel)
{
Expand All @@ -455,9 +457,11 @@ public function getInputHtml($name, $value)
$html = craft()->templates->render('neo/_fieldtype/input', [
'id' => $id,
'name' => $name,
'field' => $field,
'blockTypes' => $settings->getBlockTypes(),
'blocks' => $value,
'static' => false
'static' => false,
'translatable' => $translatable,
]);

$this->_prepareInputHtml($id, $name, $settings, $value);
Expand All @@ -476,14 +480,18 @@ public function getStaticHtml($value)
if($value)
{
$settings = $this->getSettings();
$field = $settings->getField();
$translatable = $field ? (bool) $field->translatable : false;
$id = StringHelper::randomString();

$html = craft()->templates->render('neo/_fieldtype/input', [
'id' => $id,
'name' => $id,
'field' => $field,
'blockTypes' => $settings->getBlockTypes(),
'blocks' => $value,
'static' => true,
'translatable' => $translatable,
]);

$this->_prepareInputHtml($id, $id, $settings, $value, true);
Expand Down Expand Up @@ -652,6 +660,8 @@ private function _includeResources($class, $settings = [])
*/
private function _prepareInputHtml($id, $name, $settings, $value, $static = false)
{
$locale = $this->element->locale;

$blockTypeInfo = [];
foreach($settings->getBlockTypes() as $blockType)
{
Expand All @@ -665,7 +675,7 @@ private function _prepareInputHtml($id, $name, $settings, $value, $static = fals
'maxBlocks' => $blockType->maxBlocks,
'childBlocks' => $blockType->childBlocks,
'topLevel' => (bool)$blockType->topLevel,
'tabs' => craft()->neo->renderBlockTabs($blockType, null, $name, $static),
'tabs' => craft()->neo->renderBlockTabs($blockType, null, $name, $static, $locale),
];
}

Expand Down Expand Up @@ -712,6 +722,7 @@ private function _prepareInputHtml($id, $name, $settings, $value, $static = fals
"Actions",
"Add a block",
"Add block above",
"Duplicate block",
"Are you sure you want to delete the selected blocks?",
"Expand",
"Collapse",
Expand Down
14 changes: 7 additions & 7 deletions neo/models/Neo_BlockModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public function setAllElements($elements)
public function getAncestors($dist = null)
{
// If the request is in Live Preview mode, use the Neo-extended criteria model, which supports Live Preview mode
if(craft()->request->isLivePreview())
if(craft()->neo->isPreviewMode())
{
if(!isset($this->_liveCriteria['ancestors']))
{
Expand Down Expand Up @@ -191,7 +191,7 @@ public function getAncestors($dist = null)
public function getParent()
{
// If the request is in Live Preview mode, use the Neo-extended criteria model, which supports Live Preview mode
if(craft()->request->isLivePreview())
if(craft()->neo->isPreviewMode())
{
if(!isset($this->_liveCriteria['parent']))
{
Expand All @@ -213,7 +213,7 @@ public function getParent()
public function getDescendants($dist = null)
{
// If the request is in Live Preview mode, use the Neo-extended criteria model, which supports Live Preview mode
if(craft()->request->isLivePreview())
if(craft()->neo->isPreviewMode())
{
if(!isset($this->_liveCriteria['descendants']))
{
Expand Down Expand Up @@ -244,7 +244,7 @@ public function getDescendants($dist = null)
public function getChildren($field = null)
{
// If the request is in Live Preview mode, use the Neo-extended criteria model, which supports Live Preview mode
if(craft()->request->isLivePreview())
if(craft()->neo->isPreviewMode())
{
if(!isset($this->_liveCriteria['children']))
{
Expand All @@ -265,7 +265,7 @@ public function getChildren($field = null)
public function getSiblings()
{
// If the request is in Live Preview mode, use the Neo-extended criteria model, which supports Live Preview mode
if(craft()->request->isLivePreview())
if(craft()->neo->isPreviewMode())
{
if(!isset($this->_liveCriteria['siblings']))
{
Expand All @@ -290,7 +290,7 @@ public function getSiblings()
public function getPrevSibling()
{
// If the request is in Live Preview mode, use the Neo-extended criteria model, which supports Live Preview mode
if(craft()->request->isLivePreview())
if(craft()->neo->isPreviewMode())
{
if(!isset($this->_liveCriteria['prevSibling']))
{
Expand All @@ -316,7 +316,7 @@ public function getPrevSibling()
public function getNextSibling()
{
// If the request is in Live Preview mode, use the Neo-extended criteria model, which supports Live Preview mode
if(craft()->request->isLivePreview())
if(craft()->neo->isPreviewMode())
{
if(!isset($this->_liveCriteria['nextSibling']))
{
Expand Down
4 changes: 2 additions & 2 deletions neo/models/Neo_CriteriaModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function copy()
*/
public function count()
{
if(craft()->request->isLivePreview())
if(craft()->neo->isPreviewMode())
{
return count($this->find());
}
Expand Down Expand Up @@ -181,7 +181,7 @@ protected function setState($state)
*/
private function _runCriteria()
{
if(craft()->request->isLivePreview() && !empty($this->_allElements))
if(craft()->neo->isPreviewMode() && !empty($this->_allElements))
{
$elements = $this->_allElements;

Expand Down
12 changes: 6 additions & 6 deletions neo/resources/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion neo/resources/main.js.map

Large diffs are not rendered by default.

51 changes: 50 additions & 1 deletion neo/services/NeoService.php
Original file line number Diff line number Diff line change
Expand Up @@ -812,9 +812,10 @@ public function deleteBlockById($blockIds)
* @param Neo_BlockModel|null $block
* @param string $namespace
* @param bool|false $static
* @param $locale
* @return array
*/
public function renderBlockTabs(Neo_BlockTypeModel $blockType, Neo_BlockModel $block = null, $namespace = '', $static = false)
public function renderBlockTabs(Neo_BlockTypeModel $blockType, Neo_BlockModel $block = null, $namespace = '', $static = false, $locale = null)
{
$oldNamespace = craft()->templates->getNamespace();
$newNamespace = craft()->templates->namespaceInputName($namespace . '[__NEOBLOCK__][fields]', $oldNamespace);
Expand All @@ -825,6 +826,22 @@ public function renderBlockTabs(Neo_BlockTypeModel $blockType, Neo_BlockModel $b
$fieldLayout = $blockType->getFieldLayout();
$fieldLayoutTabs = $fieldLayout->getTabs();

if(!$block)
{
// Trick Craft into rendering fields of a block type with the correct locale (see below)
$block = new Neo_BlockModel();
}

if($locale)
{
// Rendering the `_includes/fields` template doesn't take a `locale` parameter, even though individual
// field templates do. If no locale is passed when rendering a field (which there won't be when using the
// `fields` template) it defaults to the passed element's locale. The following takes advantage of this
// by setting the locale on the block itself. In the event that only a block type is being rendered, the
// above creates a dummy block to so the locale can be passed.
$block->locale = $locale;
}

foreach($fieldLayoutTabs as $fieldLayoutTab)
{
craft()->templates->startJsBuffer();
Expand Down Expand Up @@ -1010,6 +1027,38 @@ public function deleteStructure(NeoFieldType $fieldType)
return true;
}


// ---- Helpers

/**
* Checks the current route/environment to see if database calls for Neo blocks should be avoided.
* This is so that live preview and entry drafts can use their data instead.
*
* @return bool
*/
public function isPreviewMode()
{
if(craft()->request->isLivePreview())
{
return true;
}

$token = craft()->request->getParam('token');

if($token)
{
$route = craft()->tokens->getTokenRoute($token);

// If an entry draft is being previewed, use the content stored in the draft
if($route && $route['action'] == 'entries/viewSharedEntry')
{
return true;
}
}

return false;
}


// Protected methods

Expand Down
2 changes: 1 addition & 1 deletion neo/templates/_fieldtype/input.twig
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<input type="hidden" name="{{ name }}" value="">
<div id="{{ id }}" class="neo-input{{ static ? ' is-static' }}"></div>
<div id="{{ id }}" class="neo-input neo-input--{{ field.handle }}{{ static ? ' is-static' }}{{ translatable ? ' is-translatable' }}"></div>
16 changes: 16 additions & 0 deletions neo/translations/de.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

return [
"Add block above" => "Block oberhalb hinzuf\xC3\xBCgen",
"Block type" => "Blocktyp",
"The maximum number of blocks of this type the field is allowed to have." => "Die maximale Anzahl an Blocks des Types, die dieses Feld besitzen darf.",
"Child Blocks" => "Kind-Bl\xC3\xB6cke",
"Which block types do you want to allow as children?" => "Welche Blocktypen m\xC3\xB6chtest Du als Kinder erlauben?",
"Delete block type" => "Blocktyp l\xC3\xB6schen",
"Delete group" => "Gruppe l\xC3\xB6schen",
"Top Level" => "H\xC3\xB6chste Ebene",
"Will this block type be allowed at the top level?" => "Soll dieser Blocktyp f\xC3\xBCr die h\xC3\xB6chste Ebene erlaubt sein?",
"Define the types of blocks that can be created within this Neo field, as well as the fields each block type is made up of." => "Definiere die Blocktypen, die dieses Neo-Feld haben darf und die Felder, aus denen jeder Block besteht.",
"Unable to nest Neo fields." => "Neo-Felder k\xC3\xB6nnen nicht verschachtelt werden.",
"Duplicate block" => "Doppelblock",
];
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "craft-neo",
"version": "1.3.4",
"version": "1.3.5",
"description": "A Matrix-like field type that uses existing fields",
"main": "webpack.config.js",
"scripts": {
Expand Down
18 changes: 7 additions & 11 deletions src/configurator/BlockTypeSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export default Settings.extend({
}
},

addChildBlockType(blockType, index = -1)
addChildBlockType(blockType)
{
if(!this._childBlockTypes.includes(blockType))
{
Expand All @@ -269,17 +269,11 @@ export default Settings.extend({
}))

NS.leave()

this._childBlockTypes.push(blockType)
this.$childBlocksContainer.append($checkbox)

if(index < 0 || index >= this._childBlockTypes.length)
{
this._childBlockTypes.push(blockType)
this.$childBlocksContainer.append($checkbox)
}
else
{
this._childBlockTypes.splice(index, 0, blockType)
$checkbox.insertAt(index, this.$childBlocksContainer)
}
this._refreshChildBlocks()

const select = this._childBlocksSelect
const allChecked = select.$all.prop('checked')
Expand Down Expand Up @@ -309,6 +303,8 @@ export default Settings.extend({

const eventNs = '.childBlock' + this.getId()
settings.off(eventNs)

this._refreshChildBlocks()
}
},

Expand Down
9 changes: 3 additions & 6 deletions src/configurator/Configurator.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,10 @@ export default Garnish.Base.extend({

if(item instanceof BlockType)
{
const blockTypes = this.getBlockTypes()
for(let blockType of blockTypes)
for(let blockType of this.getBlockTypes())
{
let btSettings = blockType.getSettings()
let btIndex = blockTypes.indexOf(blockType)

if(btSettings) btSettings.addChildBlockType(item, btIndex)
const btSettings = blockType.getSettings()
if(btSettings) btSettings.addChildBlockType(item)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/configurator/templates/blocktype_settings.twig
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
id: 'handle'|ns('id'),
name: 'handle'|ns,
label: "Handle"|t,
instructions: "How you'll refer to this block type in the templates."|t,
instructions: "How you&#8217;ll refer to this block type in the templates."|t,
required: true,
class: 'code',
value: handle,
Expand Down
Loading

0 comments on commit 7bb691b

Please sign in to comment.