Skip to content

Commit

Permalink
Adds the "ungroupedTypesPosition" setting. Bump to 1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mmikkel committed Aug 5, 2022
1 parent 37bb880 commit 0e2f33a
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## 1.5.0 - 2022-08-05
### Added
- Added the `ungroupedTypesPosition` field config setting, which can be used to specify the display order for ungrouped block types

## 1.4.5 - 2022-07-14
### Improved
- MatrixMate now defers registering its CP resources to an `Application::EVENT_INIT` event handler, reducing the risk of conflicting with other plugins.
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,21 @@ To explicitly hide one or several block types, add an array of block type handle

This setting will hide any and all block types added to it, regardless of whether those types have been added to any groups or not, and regardless of the value for the `hideUngroupedTypes` setting.

#### ungroupedTypesPosition [string]
*Default: `'before'`*

If set to `'after'`, buttons for ungrouped block types will render _after_ the group buttons.

```php
...
'matrixFieldHandle' => [
'groups' => [...],
'ungroupedTypesPosition' => 'after',
],
```

This setting only applies when using the grouping feature.

### Advanced configuration

*Danger Zone*
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vaersaagod/matrixmate",
"description": "Welding Matrix into shape, mate!",
"type": "craft-plugin",
"version": "1.4.5",
"version": "1.5.0",
"keywords": [
"craft",
"cms",
Expand Down
17 changes: 14 additions & 3 deletions src/assetbundles/matrixmate/dist/js/MatrixMate.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,24 @@
}).get().reverse());

if ($hiddenUngroupedOrigButtons.length) {
var ungroupedTypesPosition = fieldConfig.ungroupedTypesPosition || 'before';
var $ul = $('<ul />');
if (ungroupedTypesPosition === 'after') {
$hiddenUngroupedOrigButtons = $($hiddenUngroupedOrigButtons.get().reverse());
}
$hiddenUngroupedOrigButtons.each(function (index) {
var $btn = $(this).clone();
if (index === $hiddenUngroupedOrigButtons.length - 1) {
$btn.addClass('icon add');
if (ungroupedTypesPosition === 'after') {
if (!index) {
$btn.addClass('icon add');
}
$matrixmateButtons.append($btn);
} else {
if (index === $hiddenUngroupedOrigButtons.length - 1) {
$btn.addClass('icon add');
}
$matrixmateButtons.prepend($btn);
}
$matrixmateButtons.prepend($btn);
var type = $btn.data('type');
var $li = $('<li/>');
var $a = $('<a/>').attr('data-type', type).text($btn.text());
Expand Down
5 changes: 5 additions & 0 deletions src/services/MatrixMateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ public function getFieldConfig(): ?array
// Hide ungrouped types?
$contextSettings['hideUngroupedTypes'] = !!($contextSettings['hideUngroupedTypes'] ?? false);

// Ungrouped types position
if (!isset($contextSettings['ungroupedTypesPosition']) || !in_array($contextSettings['ungroupedTypesPosition'], ['before', 'after'])) {
$contextSettings['ungroupedTypesPosition'] = 'before';
}

// Explicitly hidden types
$hiddenTypes = $contextSettings['hiddenTypes'] ?? null;
if (\is_string($hiddenTypes)) {
Expand Down

0 comments on commit 0e2f33a

Please sign in to comment.