Skip to content

Commit

Permalink
Merge branch 'release/3.3.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
janhenckens committed Sep 13, 2023
2 parents 7820954 + c7c7f45 commit a111101
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ config.codekit3
prepros-6.config
/docs/.vuepress/dist
/docs/.vitepress/dist
/docs/.vitepress/cache
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/).

## 3.3.2 - 2023-09-13
### Fixed
- Fixed an issue where sitemaps couldn't be saved for different sites

## 3.3.1 - 2023-08-08
### Fixed
- Permissions for defaults are now really fixed ([#77](https://github.com/studioespresso/craft-seo-fields/issues/77))
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "studioespresso/craft-seo-fields",
"description": "Fields for your SEO & OG meta data",
"type": "craft-plugin",
"version": "3.3.1",
"version": "3.3.2",
"keywords": [
"craft",
"cms",
Expand All @@ -18,7 +18,7 @@
"authors": [
{
"name": "Studio Espresso",
"homepage": "https://www.studioespresso.dev"
"homepage": "https://www.studioespresso.co"
},
{
"name": "Jan Henckens",
Expand Down
4 changes: 2 additions & 2 deletions docs/sitemap.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ Support for custom urls and for registeren custom urls in code will be added in

### Multisite

By default, each site in your Craft install will get the same sitemap.xml, depending on wether the sections you've enabled in the sitemap are enabled for that site and when the section has entries that are enabled for that site. If you need the option to change enable/disable section in the sitemap per site, you can add "sitemapPerSite" => true to config/seo-fields.php.
By default, each site in your Craft install will get the same sitemap.xml, depending on wether the sections you've enabled in the sitemap are enabled for that site and when the section has entries that are enabled for that site. If you need the option to change enable/disable section in the sitemap per site, you can add `sitemapPerSite => true` to config/seo-fields.php.

With that set, refresh the robots settings page and you'll see a sites dropdown at the top so you can switch sites and save a sitemap for each.
With that set, refresh the Sitemap settings page and you'll see a sites dropdown at the top so you can switch sites and save a sitemap for each.
9 changes: 5 additions & 4 deletions src/controllers/DefaultsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ public function actionIndex()

public function actionSettings($siteHandle = null)
{
$currentSite = Craft::$app->sites->getSiteByHandle($siteHandle);
Craft::$app->sites->setCurrentSite($currentSite);
$data = SeoFields::$plugin->defaultsService->getDataBySite($currentSite);
$site = Craft::$app->sites->getSiteByHandle($siteHandle);
Craft::$app->sites->setCurrentSite($site);
$data = SeoFields::$plugin->defaultsService->getDataBySite($site);
return $this->renderTemplate('seo-fields/_defaults', [
'data' => $data
'data' => $data,
'selectedSite' => $site
]);

}
Expand Down
15 changes: 13 additions & 2 deletions src/controllers/SitemapController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Craft;
use craft\helpers\Template;
use craft\records\Section_SiteSettings;
use craft\web\Controller;
use studioespresso\seofields\models\SeoDefaultsModel;
use studioespresso\seofields\records\DefaultsRecord;
Expand All @@ -23,10 +24,19 @@ public function actionIndex()

public function actionSettings($siteHandle = null)
{
$site = Craft::$app->getSites()->getSiteByHandle($siteHandle);
Craft::$app->getSites()->getSiteByHandle($site);
$sectionsForSite = Section_SiteSettings::findAll(['siteId' => $site->id]);
$sections = [];
foreach($sectionsForSite as $s) {
$sections[] = Craft::$app->getSections()->getSectionById($s->sectionId);
}
$data = SeoFields::$plugin->defaultsService->getDataBySiteHandle($siteHandle);
return $this->renderTemplate('seo-fields/_sitemap', [
'data' => $data,
'sitemapPerSite' => SeoFields::$plugin->getSettings()->sitemapPerSite
'sitemapPerSite' => SeoFields::$plugin->getSettings()->sitemapPerSite,
'sections' => $sections,
'selectedSite' => $site
]);
}

Expand All @@ -38,10 +48,11 @@ public function actionSave()
} else {
$model = new SeoDefaultsModel();
}

$data['sitemap'] = Craft::$app->getRequest()->getBodyParam('data');
$data['siteId'] = Craft::$app->getRequest()->getBodyParam('siteId', Craft::$app->getSites()->getPrimarySite()->id);
$model->setAttributes($data);
SeoFields::$plugin->defaultsService->saveDefaults($model, Craft::$app->sites->currentSite->id);
SeoFields::$plugin->defaultsService->saveDefaults($model, $data['siteId']);
SeoFields::$plugin->sitemapSerivce->clearCaches();
}

Expand Down
3 changes: 2 additions & 1 deletion src/services/DefaultsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ public function saveDefaults(SeoDefaultsModel $model, $siteId)
$record = DefaultsRecord::findOne(
['siteId' => $siteId]
);

if (!$record) {
$record = new DefaultsRecord();
}
$record->setAttribute('defaultMeta', $model->toArray(['defaultSiteTitle', 'defaultMetaDescription', 'titleSeperator', 'defaultImage']));
$record->setAttribute('siteId', $model->siteId);
$record->setAttribute('siteId', $model->siteId ?? $siteId);
$record->setAttribute('enableRobots', $model->enableRobots);
$record->setAttribute('robots', $model->robots);
$record->setAttribute('sitemap', $model->sitemap);
Expand Down
7 changes: 3 additions & 4 deletions src/templates/_includes/_sitemapSections.twig
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
<tr>
<th>{{ 'Section'|t('seo-fields') }}</th>
<th>{{ 'Update frequency'|t('seo-fields') }}
<span class="info">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</span>
{# <span class="info">#}
{# </span>#}
</th>
<th>Priority
<span class="info">
Expand All @@ -26,7 +25,7 @@
<tbody>

{% set sitemapSettings = data.sitemap|json_decode %}
{% for section in allSections %}
{% for section in sections %}
{% set settings = attribute(sitemapSettings.entry, section.id) ?? [] %}
<tr>
<th>{{ section.name }}</th>
Expand Down
6 changes: 3 additions & 3 deletions src/templates/_includes/_sites.twig
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{% if craft.app.sites.getEditableSites()|length > 1 %}
<div id="revision-btn" class="btn menubtn" data-icon="world">{{ currentSite.name }}</div>
<div id="revision-btn" class="btn menubtn" data-icon="world">{{ selectedSite.name }}</div>
<div class="menu">
<ul class="padded">
{% for site in craft.app.sites.getAllSites() %}
<li>
<a href="{{ url('seo-fields/' ~ selectedSubnavItem ~ '/' ~ site.handle ) }}"
{% if site.handle == currentSite.handle %}class="sel"{% endif %}>
{% if site.handle == selectedSite.handle %}class="sel"{% endif %}>
{{ site.name }}
</a>
</li>
{% endfor %}
</ul>
</div>
<input type="hidden" name="siteId" value="{{ currentSite.id }}">
<input type="hidden" name="siteId" value="{{ selectedSite.id }}">
{% endif %}
2 changes: 1 addition & 1 deletion src/templates/_sitemap.twig
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
{% block content %}
{{ actionInput('seo-fields/sitemap/save') }}
{% if sitemapPerSite %}
<input type="hidden" name="siteId" value="{{ currentSite.id }}">
<input type="hidden" name="siteId" value="{{ selectedSite.id }}">
{% endif %}

{% if data.id is defined %}
Expand Down

0 comments on commit a111101

Please sign in to comment.