Skip to content

Commit

Permalink
Fix #932
Browse files Browse the repository at this point in the history
  • Loading branch information
ttempleton committed Aug 28, 2024
1 parent 8395093 commit b000919
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fixed
- Fixed a bug where moving an entry between sections would cause nested Neo content to lose structure data
- Fixed an error that occurred when converting a block type to an entry type (including during Neo-to-Matrix conversion) if any block type field layout tabs or elements had condition rules applied
- Fixed an error that occurred when setting parent block condition rules on block type field layout elements
- Fixed a style bug that occurred when input blocks had UI elements

## 5.2.2 - 2024-08-20
Expand Down
27 changes: 26 additions & 1 deletion src/elements/conditions/BlockCondition.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace benf\neo\elements\conditions;

use benf\neo\Plugin as Neo;
use craft\db\Table;
use craft\elements\conditions\ElementCondition;
use craft\elements\conditions\LevelConditionRule;
use craft\helpers\Db;
use craft\models\FieldLayout;

/**
Expand All @@ -16,6 +18,25 @@
*/
class BlockCondition extends ElementCondition
{
/**
* @inheritdoc
*/
public function getBuilderConfig(): array
{
$config = parent::getBuilderConfig();

// Ensure UUIDs set on field layouts
if (isset($config['fieldLayouts'])) {
$fieldLayouts = $this->getFieldLayouts();

for ($i = 0; $i < count($fieldLayouts); $i++) {
$config['fieldLayouts'][$i]['uid'] = $fieldLayouts[$i]->uid;
}
}

return $config;
}

/**
* @inheritdoc
*/
Expand All @@ -26,8 +47,12 @@ protected function selectableConditionRules(): array

// Get all field layouts associated with this object's associated Neo field(s), then temporarily replace this
// object's field layouts so we get all possible parent block condition rules
$layoutIds = array_values(Db::idsByUids(
Table::FIELDLAYOUTS,
array_map(fn($layout) => $layout->uid, $this->getFieldLayouts()),
));
$layoutBlockTypes = Neo::$plugin->blockTypes->getByCriteria([
'fieldLayoutId' => array_map(fn($layout) => $layout->id, $this->getFieldLayouts()),
'fieldLayoutId' => $layoutIds,
]);
$fieldBlockTypes = Neo::$plugin->blockTypes->getByCriteria([
'fieldId' => array_values(array_unique(array_map(fn($blockType) => $blockType->fieldId, $layoutBlockTypes))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Craft;
use craft\base\ElementInterface;
use craft\base\FieldInterface;
use craft\db\Table;
use craft\helpers\Db;
use yii\base\InvalidConfigException;

/**
Expand Down Expand Up @@ -71,8 +73,12 @@ protected function fieldInstances(): array
$selectedInstanceLabel = null;

// Get all of the block type field layouts associated with the Neo field(s)
$layoutIds = array_values(Db::idsByUids(
Table::FIELDLAYOUTS,
array_map(fn($layout) => $layout->uid, $this->getCondition()->getFieldLayouts()),
));
$layoutBlockTypes = Neo::$plugin->blockTypes->getByCriteria([
'fieldLayoutId' => array_map(fn($layout) => $layout->id, $this->getCondition()->getFieldLayouts()),
'fieldLayoutId' => $layoutIds,
]);
$fieldBlockTypes = Neo::$plugin->blockTypes->getByCriteria([
'fieldId' => array_values(array_unique(array_map(fn($blockType) => $blockType->fieldId, $layoutBlockTypes))),
Expand Down

0 comments on commit b000919

Please sign in to comment.