diff --git a/CHANGELOG.md b/CHANGELOG.md index f7fcee5..d593767 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,26 +4,32 @@ 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.1.2 - 2020-09-15 +### Fixed +- Fixes an issue where Child Me! could fail to select the correct site on multisite installs, upon creating new categories or entries via the entry type menu + ## 1.1.1 - 2020-05-05 -### Fixed -- Fixes an issue where entry type menus would not be displayed for entries loaded in with AJAX on paginated entry indexes -- Fixes an issue where Child Me! could redirect to the wrong URL for multi-site installs +### Fixed +- Fixes an issue where entry type menus would not be displayed for entries loaded in with AJAX on paginated entry indexes +- Fixes an issue where Child Me! could redirect to the wrong URL for multi-site installs ## 1.1.0 - 2020-03-08 -### Fixed -- Fixes an issue where entry type menus could be cut off on Craft 3.4+ -- Fixes issues with multi-site on Craft 3.2+ -### Changed -- Child Me! now requires Craft 3.2.0 +### Fixed +- Fixes an issue where entry type menus could be cut off on Craft 3.4+ +- Fixes issues with multi-site on Craft 3.2+ + +### Changed +- Child Me! now requires Craft 3.2.0 ## 1.0.6 - 2019-10-21 ### Fixed - Fixes an issue where Child Me! could conflict with other plugins ## 1.0.5 - 2019-10-15 -### Fixed -- Fixes an issue where sort order was not respected for entry types. Fixes #2 -## Improved +### Fixed +- Fixes an issue where sort order was not respected for entry types. Fixes #2 + +## Improved - Reduces number of database queries in the Control Panel ## 1.0.4 - 2018-06-05 diff --git a/composer.json b/composer.json index d064dce..57291b0 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "mmikkel/child-me", "description": "Easily create child elements", "type": "craft-plugin", - "version": "1.1.1", + "version": "1.1.2", "keywords": [ "craft", "cms", diff --git a/src/ChildMe.php b/src/ChildMe.php index c345cbd..46f3a67 100644 --- a/src/ChildMe.php +++ b/src/ChildMe.php @@ -160,6 +160,7 @@ protected function addElementTableAttributes() switch ($class) { case 'craft\elements\Entry': + /** @var Entry $entry */ $entry = $event->sender; if ($entry->section->type !== 'structure') { @@ -174,24 +175,25 @@ protected function addElementTableAttributes() 'parentId' => $entry->id, ]; + $attributes = [ + 'data-section="' . $entry->section->handle . '"', + 'data-id="' . $entry->id . '"', + ]; + if (Craft::$app->getIsMultiSite()) { - $siteId = $entry->siteId ?? null; - $site = $siteId ? Craft::$app->getSites()->getSiteById($siteId) : null; - if ($site) { - $variables['site'] = $site->handle; - } + $site = $entry->getSite(); + $variables['site'] = $site->handle; + $attributes[] = 'data-site="' . $site->handle . '"'; } $newUrl = UrlHelper::cpUrl(implode('/', ['entries', $entry->section->handle, 'new']), $variables); - $html = $this->getElementTableAttributeHtml($newUrl, $visible, [ - 'data-section="' . $entry->section->handle . '"', - 'data-id="' . $entry->id . '"' - ]); + $html = $this->getElementTableAttributeHtml($newUrl, $visible, $attributes); break; case 'craft\elements\Category': + /** @var Category $category */ $category = $event->sender; $maxLevels = $category->group->maxLevels; $visible = !$maxLevels || $category->level < $maxLevels; @@ -200,15 +202,15 @@ protected function addElementTableAttributes() 'parentId' => $category->id, ]; + $urlSegments = ['categories', $category->group->handle, 'new']; + if (Craft::$app->getIsMultiSite()) { - $siteId = $category->siteId ?? null; - $site = $siteId ? Craft::$app->getSites()->getSiteById($siteId) : null; - if ($site) { - $variables['site'] = $site->handle; - } + $site = $category->getSite(); + $variables['site'] = $site->handle; + $urlSegments[] = $site->handle; } - $newUrl = UrlHelper::cpUrl(implode('/', ['categories', $category->group->handle, 'new']), $variables); + $newUrl = UrlHelper::cpUrl(implode('/', $urlSegments), $variables); $html = $this->getElementTableAttributeHtml($newUrl, $visible); diff --git a/src/resources/childme.js b/src/resources/childme.js index cdcac75..7e4e61e 100644 --- a/src/resources/childme.js +++ b/src/resources/childme.js @@ -63,13 +63,10 @@ } }, - getSiteHandle: function () { - var siteId = Craft.getLocalStorage('BaseElementIndex.siteId'); - return this.data['sites']['site:' + siteId] || null; - }, - createEntryTypeMenu: function ($button) { + console.log($button.data()); + var sectionHandle = $button.data('section') || null; if (!sectionHandle) { return null; @@ -85,12 +82,14 @@ var menuOptions = []; var typeId; + var siteHandle = $button.data('site') || null; + for (var j = 0; j < entryTypeIds.length; ++j) { typeId = parseInt(entryTypeIds[j].split(':').pop(), 10); if (!typeId || isNaN(typeId)) { continue; } - menuOptions.push('