Skip to content

Commit

Permalink
Fixes multisite issues. Bump to 1.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
mmikkel committed Sep 15, 2020
1 parent 95a7150 commit c2eb32f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 36 deletions.
28 changes: 17 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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": "1.1.1",
"version": "1.1.2",
"keywords": [
"craft",
"cms",
Expand Down
32 changes: 17 additions & 15 deletions src/ChildMe.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ protected function addElementTableAttributes()
switch ($class) {
case 'craft\elements\Entry':

/** @var Entry $entry */
$entry = $event->sender;

if ($entry->section->type !== 'structure') {
Expand All @@ -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;
Expand All @@ -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);

Expand Down
16 changes: 7 additions & 9 deletions src/resources/childme.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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('<li><a data-type="' + typeId + '" data-parent="' + $button.data('id') + '" data-section="' + sectionHandle + '" tabindex="0">' + entryTypes[entryTypeIds[j]] + '</a></li>');
menuOptions.push('<li><a data-type="' + typeId + '" data-parent="' + $button.data('id') + '" data-section="' + sectionHandle + (siteHandle ? '" data-site="' + siteHandle : '') + '" tabindex="0">' + entryTypes[entryTypeIds[j]] + '</a></li>');
}

menuHtml += menuOptions.join('') + '</ul></div>';
Expand All @@ -115,14 +114,13 @@
e.preventDefault();
e.stopPropagation();
var $option = $(e.currentTarget);
var siteHandle = this.getSiteHandle();
var segments = ['entries', $option.data('section'), 'new'];
var variables = {
typeId: $option.data('type'),
parentId: $option.data('parent'),
};
if (siteHandle) {
variables.site = siteHandle;
if ($option.data('site')) {
variables['site'] = $option.data('site');
}
var url = Craft.getCpUrl(segments.join('/'), variables);
window.location.href = url;
Expand Down

0 comments on commit c2eb32f

Please sign in to comment.