Skip to content

Commit

Permalink
Allow empty entryTypes array to prevent New Child button from renderi…
Browse files Browse the repository at this point in the history
…ng. Bump to 2.2.0
  • Loading branch information
mmikkel committed May 18, 2024
1 parent 949bc29 commit afb543a
Show file tree
Hide file tree
Showing 3 changed files with 8 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/).

## 2.2.0 - 2024-05-18
### Changed
- Setting the `EVENT_DEFINE_ENTRY_TYPES::$entryTypes` attribute to an empty array now results in the "New child" button not being rendered, instead of defaulting to the current entry's entry type.

## 2.1.0 - 2024-05-09
### Fixed
- Fixed a bug that prevented the "New child" button from appearing in certain situations
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": "mmikkel/child-me",
"description": "Easily create child elements",
"type": "craft-plugin",
"version": "2.1.0",
"version": "2.2.0",
"keywords": [
"craft",
"cms",
Expand Down
6 changes: 3 additions & 3 deletions src/ChildMe.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,14 @@ private function _renderChildMeButtonForEntry(Entry $entry): string
$entryTypesEvent = new DefineEntryTypesEvent([
'entry' => $entry,
'section' => $section->handle,
'entryTypes' => $section->getEntryTypes(),
'entryTypes' => $entryTypes,
]);
$this->trigger(self::EVENT_DEFINE_ENTRY_TYPES, $entryTypesEvent);
$entryTypes = array_values($entryTypesEvent->entryTypes ?? []);
$entryTypes = array_values($entryTypesEvent->entryTypes);
}

if (empty($entryTypes)) {
$entryTypes = [$entry->getType()];
return '';
}

$links = array_map(static function (EntryType $entryType) use ($entry, $section) {
Expand Down

0 comments on commit afb543a

Please sign in to comment.