From afb543aa0b57b0368fdf6a2a0583a47f93d4d267 Mon Sep 17 00:00:00 2001 From: Mats Mikkel Rummelhoff Date: Sat, 18 May 2024 14:11:19 +0200 Subject: [PATCH] Allow empty entryTypes array to prevent New Child button from rendering. Bump to 2.2.0 --- CHANGELOG.md | 4 ++++ composer.json | 2 +- src/ChildMe.php | 6 +++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cfb23b..5d2f022 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/composer.json b/composer.json index 1730f4d..e57e2cd 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/src/ChildMe.php b/src/ChildMe.php index 5af3639..5593006 100644 --- a/src/ChildMe.php +++ b/src/ChildMe.php @@ -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) {