Skip to content

Commit

Permalink
Fix disabled blocks being deleted #190
Browse files Browse the repository at this point in the history
v2.2.5
  • Loading branch information
ttempleton committed Feb 23, 2019
1 parent c05ca15 commit aa55894
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.2.5 - 2019-02-23
### Fixed
- Fixed issue in Neo 2.2.4 with disabled blocks being deleted when saving a Neo field's contents

## 2.2.4 - 2019-02-19
### Changed
- Now supports filtering an entry draft's Neo field content with query parameters
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "spicyweb/craft-neo",
"description": "A Matrix-like field type that uses existing fields",
"version": "2.2.4",
"version": "2.2.5",
"type": "craft-plugin",
"keywords": [
"cms",
Expand Down
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": "2.2.4",
"version": "2.2.5",
"description": "A Matrix-like field type that uses existing fields",
"main": "webpack.config.js",
"scripts": {
Expand Down
13 changes: 10 additions & 3 deletions src/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,18 @@ public function normalizeValue($value, ElementInterface $element = null)
{
$elements = $this->_createBlocksFromSerializedData($value, $element);

$query->anyStatus();
if (!Craft::$app->getRequest()->getIsLivePreview())
{
$query->anyStatus();
}
else
{
$query->status = Element::STATUS_ENABLED;
}

$query->limit = null;
$query->setCachedResult($elements);
$query->setAllElements($elements);
$query->useMemoized();
$query->useMemoized($elements);
}
}

Expand Down
15 changes: 5 additions & 10 deletions src/elements/db/BlockQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use yii\db\Connection;

use Craft;
use craft\base\Element;
use craft\base\ElementInterface;
use craft\db\Query;
use craft\elements\db\ElementQuery;
Expand Down Expand Up @@ -252,10 +251,9 @@ public function typeId($value)
*/
public function count($q = '*', $db = null)
{
$isLivePreview = Craft::$app->getRequest()->getIsLivePreview();
$isUsingMemoized = $this->isUsingMemoized();

if (($isLivePreview || $isUsingMemoized) && isset($this->_allElements))
if ($isUsingMemoized && isset($this->_allElements))
{
$this->setCachedResult($this->_getFilteredResult());
}
Expand All @@ -268,10 +266,9 @@ public function count($q = '*', $db = null)
*/
public function all($db = null)
{
$isLivePreview = Craft::$app->getRequest()->getIsLivePreview();
$isUsingMemoized = $this->isUsingMemoized();

if (($isLivePreview || $isUsingMemoized) && isset($this->_allElements))
if ($isUsingMemoized && isset($this->_allElements))
{
$this->setCachedResult($this->_getFilteredResult());
}
Expand All @@ -284,10 +281,9 @@ public function all($db = null)
*/
public function one($db = null)
{
$isLivePreview = Craft::$app->getRequest()->getIsLivePreview();
$isUsingMemoized = $this->isUsingMemoized();

if (($isLivePreview || $isUsingMemoized) && isset($this->_allElements))
if ($isUsingMemoized && isset($this->_allElements))
{
$this->setCachedResult($this->_getFilteredResult());
}
Expand All @@ -300,10 +296,9 @@ public function one($db = null)
*/
public function nth(int $n, Connection $db = null)
{
$isLivePreview = Craft::$app->getRequest()->getIsLivePreview();
$isUsingMemoized = $this->isUsingMemoized();

if (($isLivePreview || $isUsingMemoized) && isset($this->_allElements))
if ($isUsingMemoized && isset($this->_allElements))
{
$this->setCachedResult($this->_getFilteredResult());
}
Expand Down Expand Up @@ -965,7 +960,7 @@ private function __status(array $elements, $value): array
{
if (!$value)
{
$value = Element::STATUS_ENABLED;
return $elements;
}

$newElements = array_filter($elements, function($element) use($value)
Expand Down

0 comments on commit aa55894

Please sign in to comment.