Skip to content

Commit

Permalink
refactor: Re-apply fix
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Jan 15, 2025
1 parent 81047cf commit 26d2842
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
15 changes: 14 additions & 1 deletion src/controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -537,12 +537,18 @@ public function actionEditContent(
}
$variables['typeMenu'] = $typeMenu;
$variables['currentTypeId'] = null;
if (!empty($typeMenu)) {
$variables['specificTypeId'] = null;
if (count($typeMenu) > 1) {
$currentType = reset($typeMenu);
$variables['currentType'] = $typeMenu[$typeId] ?? $currentType;
$variables['currentTypeId'] = $typeId ?? key($typeMenu);
$typeId = (int)$variables['currentTypeId'];
}
// If there's only one EntryType, don't bother displaying the menu
if (count($typeMenu) === 1) {
$variables['typeMenu'] = [];
$variables['specificTypeId'] = $typeId ?? key($typeMenu);
}
$pluginName = Seomatic::$settings->pluginName;
// Asset bundle
try {
Expand Down Expand Up @@ -653,6 +659,7 @@ public function actionSaveContent(): Response
$sourceHandle = $request->getParam('sourceHandle');
$siteId = $request->getParam('siteId');
$typeId = $request->getParam('typeId') ?? null;
$specificTypeId = $request->getParam('specificTypeId') ?? null;
$globalsSettings = $request->getParam('metaGlobalVars');
$bundleSettings = $request->getParam('metaBundleSettings');
$sitemapSettings = $request->getParam('metaSitemapVars');
Expand Down Expand Up @@ -691,6 +698,12 @@ public function actionSaveContent(): Response
Seomatic::$plugin->metaBundles->syncBundleWithConfig($metaBundle, true);
$metaBundle->typeId = $typeId;
Seomatic::$plugin->metaBundles->updateMetaBundle($metaBundle, $siteId);
// If there's also a specific typeId associated with this section, save the same
// metabundle there too, to fix: https://github.com/nystudio107/craft-seomatic/issues/1557
if (!empty($specificTypeId)) {
$metaBundle->typeId = $specificTypeId;
Seomatic::$plugin->metaBundles->updateMetaBundle($metaBundle, $siteId);
}

Seomatic::$plugin->clearAllCaches();
Craft::$app->getSession()->setNotice(Craft::t('seomatic', 'SEOmatic content settings saved.'));
Expand Down
7 changes: 2 additions & 5 deletions src/seoelements/SeoEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,8 @@ public static function typeMenuFromHandle(string $sourceHandle): array
$section = self::sourceModelFromHandle($sourceHandle);
if ($section !== null) {
$entryTypes = $section->getEntryTypes();
// Only create a menu if there's more than 1 entry type
if (count($entryTypes) > 1) {
foreach ($entryTypes as $entryType) {
$typeMenu[$entryType->id] = $entryType->name;
}
foreach ($entryTypes as $entryType) {
$typeMenu[$entryType->id] = $entryType->name;
}
}

Expand Down

0 comments on commit 26d2842

Please sign in to comment.