Skip to content

Commit

Permalink
Custom module to support element type sort
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrapson committed Nov 13, 2018
1 parent 9528c45 commit 1085c8c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},
"autoload" : {
"psr-4" : {
"biglotteryfund\\" : "lib/"
"biglotteryfund\\" : [ "modules/", "lib/" ]
}
},
"config": {
Expand Down
10 changes: 10 additions & 0 deletions config/app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

return [
'modules' => [
'control-panel' => biglotteryfund\Module::class,
],
'bootstrap' => [
'control-panel',
],
];
24 changes: 24 additions & 0 deletions modules/control-panel/Module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
namespace biglotteryfund;

use craft\elements\Entry;
use craft\events\RegisterElementSortOptionsEvent;
use yii\base\Event;

class Module extends \yii\base\Module
{
public function init()
{
parent::init();

// https://github.com/craftcms/cms/issues/2818
// https://docs.craftcms.com/v3/extend/updating-plugins.html#plugin-hooks
Event::on(Entry::class, Entry::EVENT_REGISTER_SORT_OPTIONS, function (RegisterElementSortOptionsEvent $event) {
$event->sortOptions[] = [
'orderBy' => 'typeId',
'label' => \Craft::t('app', 'Entry Type'),
'attribute' => 'type',
];
});
}
}

0 comments on commit 1085c8c

Please sign in to comment.