Skip to content

Commit

Permalink
initial craft 5 support
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewmenich committed Jul 22, 2024
1 parent c009646 commit add6168
Show file tree
Hide file tree
Showing 8 changed files with 308 additions and 59 deletions.
15 changes: 13 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "simplygoodwork/craft-block-usage",
"description": "See how Matrix and Neo blocks are being used across your sections.",
"type": "craft-plugin",
"version": "1.0.2",
"version": "2.0.0",
"keywords": [
"craft",
"cms",
Expand All @@ -22,7 +22,7 @@
}
],
"require": {
"craftcms/cms": "^4.0.0"
"craftcms/cms": "^5.0.0"
},
"autoload": {
"psr-4": {
Expand All @@ -40,5 +40,16 @@
"blockUsageService": "simplygoodwork\\blockusage\\services\\BlockUsageService"
},
"class": "simplygoodwork\\blockusage\\BlockUsage"
},
"config": {
"allow-plugins": {
"yiisoft/yii2-composer": true,
"craftcms/plugin-installer": true
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"require-dev": {
"craftcms/rector": "dev-main"
}
}
22 changes: 11 additions & 11 deletions src/BlockUsage.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Block Usage plugin for Craft CMS 4.x
* Block Usage plugin for Craft CMS 5.x
*
* See how Matrix and Neo blocks are being used across your sections.
*
Expand Down Expand Up @@ -99,15 +99,15 @@ static function (Event $event) {
);

// Add the MatrixCriteriaBehavior behavior to ElementQuery objects
Event::on(
ElementQuery::class,
ElementQuery::EVENT_DEFINE_BEHAVIORS,
function(DefineBehaviorsEvent $event) {
$event->sender->attachBehaviors([
MatrixCriteriaBehavior::class,
]);
}
);
// Event::on(
// ElementQuery::class,
// ElementQuery::EVENT_DEFINE_BEHAVIORS,
// function(DefineBehaviorsEvent $event) {
// $event->sender->attachBehaviors([
// MatrixCriteriaBehavior::class,
// ]);
// }
// );

// Add the NeoCriteriaBehavior behavior to ElementQuery objects
Event::on(
Expand Down Expand Up @@ -138,5 +138,5 @@ public function getCpNavItem(): ?array

// Protected Methods
// =========================================================================

}
5 changes: 3 additions & 2 deletions src/behaviors/MatrixCriteriaBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use craft\elements\MatrixBlock;
use craft\events\CancelableEvent;

use craft\records\EntryType;
use yii\base\Behavior;

/**
Expand Down Expand Up @@ -90,7 +91,7 @@ private function applyMatrixCriteriaParams(CancelableEvent $event): void
return;
}
// Set up the matrix block query
$matrixQuery = MatrixBlock::find();
$matrixQuery = EntryType::find();
// Mix in any criteria for the matrix block query
Craft::configure($matrixQuery, $this->matrixCriteria);
// Get the ids of the elements that contain matrix blocks that match the matrix block query
Expand All @@ -116,4 +117,4 @@ private function applyMatrixCriteriaParams(CancelableEvent $event): void
// Add them to the original query that was passed in
$elementQuery->id($ownerIds);
}
}
}
Loading

0 comments on commit add6168

Please sign in to comment.