Skip to content

Commit

Permalink
Merge branch 'release/3.4.78' into v3
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Jun 13, 2024
2 parents 8fc4469 + 880bb40 commit db5cc85
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 33 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# SEOmatic Changelog

## 3.4.78 - 2024.05.13
### Added
* Added a setting in Plugin Settings -> Tags to specify which site should be used as the `x-default` for `hreflang` tags ([1162](https://github.com/nystudio107/craft-seomatic/issues/1162))

### Changed
* Moved where paginated `hreflang` tags are added for paginated pages, so that they can be overriden via Twig templating code. They are now added inside of `seomatic.helper.paginate()`

### Fixed
* Fixed an issue that could cause an exception to be thrown if the selected asset for the Creator or Identity brand image was deleted ([#1472](https://github.com/nystudio107/craft-seomatic/issues/1472))
* Fixed an issue where the SEO preview for SEO Settings fields and the sidebar wouldn't be displayed correctly for drafts ([#1449](https://github.com/nystudio107/craft-seomatic/issues/1449))

## 3.4.77 - 2024.05.20
### Fixed
* Fixed an issue where the down and up arrows were reversed for sorting purposes
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": "nystudio107/craft-seomatic",
"description": "SEOmatic facilitates modern SEO best practices & implementation for Craft CMS 3. It is a turnkey SEO system that is comprehensive, powerful, and flexible.",
"type": "craft-plugin",
"version": "3.4.77",
"version": "3.4.78",
"keywords": [
"craft",
"cms",
Expand Down
2 changes: 0 additions & 2 deletions src/Seomatic.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,6 @@ public function clearAllCaches()
/** @var ?FastcgiCacheBust $plugin */
$plugin = Craft::$app->getPlugins()->getPlugin('fastcgi-cache-bust');
if ($plugin !== null) {
// FastcgiCacheBust has an error in its PHPdoc
/** @phpstan-ignore-next-line */
$plugin->cache->clearAll();
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@
// Whether to dynamically include the `x-default` hreflang tags
'addXDefaultHrefLang' => true,

// The site to use for the `x-default` hreflang tag (0 defaults to the Primary site)
'xDefaultSite' => 0,

// Whether to dynamically include hreflang tags on paginated pages
'addPaginatedHreflang' => true,

Expand Down
2 changes: 2 additions & 0 deletions src/controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,8 @@ public function actionPlugin(): Response
];
$variables['selectedSubnavItem'] = 'plugin';
$variables['settings'] = Seomatic::$settings;
$sites = ArrayHelper::map(Craft::$app->getSites()->getAllSites(), 'id', 'name');
$variables['sites'] = $sites;

// Render the template
return $this->renderTemplate('seomatic/settings/plugin/_edit', $variables);
Expand Down
4 changes: 2 additions & 2 deletions src/fields/SeoSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public function getInputHtml($value, ElementInterface $element = null): string
$variables['parentBundles'] = [];
// Preview the containers so the preview is correct in the field
if ($element !== null && $element->uri !== null) {
Seomatic::$plugin->metaContainers->previewMetaContainers($element->uri, $element->siteId, true);
Seomatic::$plugin->metaContainers->previewMetaContainers($element->uri, $element->siteId, true, true, $element);
$contentMeta = Seomatic::$plugin->metaBundles->getContentMetaBundleForElement($element);
$globalMeta = Seomatic::$plugin->metaBundles->getGlobalMetaBundle($element->siteId);
$variables['parentBundles'] = [$contentMeta, $globalMeta];
Expand Down Expand Up @@ -396,7 +396,7 @@ public function getTableAttributeHtml($value, ElementInterface $element): string
$html = $cache->getOrSet(
self::CACHE_KEY . $cacheKey,
function() use ($uri, $siteId, $element) {
Seomatic::$plugin->metaContainers->previewMetaContainers($uri, $siteId, true);
Seomatic::$plugin->metaContainers->previewMetaContainers($uri, $siteId, true, true, $element);
$variables = [
'previewTypes' => [
$this->elementDisplayPreviewType,
Expand Down
10 changes: 9 additions & 1 deletion src/helpers/DynamicMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ public static function paginate(Paginate $pageInfo)
'href' => $url,
]);
}
// If this page is paginated, we need to factor that into the cache key
// We also need to re-add the hreflangs
if (Seomatic::$plugin->metaContainers->paginationPage !== '1') {
if (Seomatic::$settings->addHrefLang && Seomatic::$settings->addPaginatedHreflang) {
self::addMetaLinkHrefLang();
}
}
}
}

Expand Down Expand Up @@ -633,14 +640,15 @@ public static function getLocalizedUrls(string $uri = null, int $siteId = null):
$hreflangLanguage = $language;
$hreflangLanguage = strtolower($hreflangLanguage);
$hreflangLanguage = str_replace('_', '-', $hreflangLanguage);
$primary = Seomatic::$settings->xDefaultSite == 0 ? $site->primary : Seomatic::$settings->xDefaultSite == $site->id;
if ($includeUrl) {
$localizedUrls[] = [
'id' => $site->id,
'language' => $language,
'ogLanguage' => $ogLanguage,
'hreflangLanguage' => $hreflangLanguage,
'url' => $url,
'primary' => $site->primary,
'primary' => $primary,
'current' => $thisSite->id === $site->id,
];
}
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/ImageTransform.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public static function assetElementsFromIds($assetIds, $siteId = null): array
}
}

return $assets;
return array_filter($assets);
}

// Protected Static Methods
Expand Down
2 changes: 0 additions & 2 deletions src/helpers/Sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,6 @@ public static function generateSitemap(array $params)
/** @var FastcgiCacheBust $plugin */
$plugin = Craft::$app->getPlugins()->getPlugin('fastcgi-cache-bust');
if ($plugin !== null) {
// FastcgiCacheBust has an error in its PHPdoc
/** @phpstan-ignore-next-line */
$plugin->cache->clearAll();
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ class Settings extends VarsModel
*/
public $addXDefaultHrefLang = true;

/**
* @var int The site to use for the `x-default` hreflang tag (0 defaults to the Primary site)
*/
public $xDefaultSite = 0;

/**
* @var bool Whether to dynamically include hreflang tags on paginated pages
*/
Expand Down Expand Up @@ -290,6 +295,8 @@ public function rules(): array
],
'boolean',
],
['xDefaultSite', 'integer'],
['xDefaultSite', 'default', 'value' => 0],
['cspNonce', 'string'],
['cspNonce', 'in', 'range' => [
'',
Expand Down
2 changes: 1 addition & 1 deletion src/seoelements/SeoEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ function(SectionEvent $event) {
/** @var Entry $entry */
$entry = $context[self::getElementRefHandle()] ?? null;
if ($entry !== null && $entry->uri !== null) {
Seomatic::$plugin->metaContainers->previewMetaContainers($entry->uri, $entry->siteId, true);
Seomatic::$plugin->metaContainers->previewMetaContainers($entry->uri, $entry->siteId, true, true, $entry);
// Render our preview sidebar template
if (Seomatic::$settings->displayPreviewSidebar && Seomatic::$matchedElement) {
$html .= PluginTemplate::renderPluginTemplate('_sidebars/entry-preview.twig');
Expand Down
27 changes: 14 additions & 13 deletions src/services/MetaContainers.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
use Craft;
use craft\base\Component;
use craft\base\Element;
use craft\base\ElementInterface;
use craft\commerce\Plugin as CommercePlugin;
use craft\console\Application as ConsoleApplication;
use craft\elements\GlobalSet;
use craft\helpers\ElementHelper;
use craft\web\UrlManager;
use nystudio107\seomatic\base\MetaContainer;
use nystudio107\seomatic\base\MetaItem;
Expand Down Expand Up @@ -209,13 +211,6 @@ public function getContainersOfType(string $type): array
public function includeMetaContainers()
{
Craft::beginProfile('MetaContainers::includeMetaContainers', __METHOD__);
// If this page is paginated, we need to factor that into the cache key
// We also need to re-add the hreflangs
if ($this->paginationPage !== '1') {
if (Seomatic::$settings->addHrefLang && Seomatic::$settings->addPaginatedHreflang) {
DynamicMetaHelper::addMetaLinkHrefLang();
}
}
// Fire an 'metaBundleDebugData' event
if ($this->hasEventHandlers(self::EVENT_METABUNDLE_DEBUG_DATA)) {
$metaBundle = new MetaBundle([
Expand Down Expand Up @@ -287,10 +282,11 @@ function() use ($uniqueKey) {
* should be factored into the preview
*/
public function previewMetaContainers(
string $uri = '',
int $siteId = null,
bool $parseVariables = false,
bool $includeElement = true
string $uri = '',
int $siteId = null,
bool $parseVariables = false,
bool $includeElement = true,
?ElementInterface $element = null
) {
// If we've already previewed the containers for this request, there's no need to do it again
if (Seomatic::$previewingMetaContainers && !Seomatic::$headlessRequest) {
Expand All @@ -303,7 +299,7 @@ public function previewMetaContainers(
}
Seomatic::$previewingMetaContainers = true;
$this->includeMatchedElement = $includeElement;
$this->loadMetaContainers($uri, $siteId);
$this->loadMetaContainers($uri, $siteId, $element);
// Load in the right globals
$twig = Craft::$app->getView()->getTwig();
$globalSets = GlobalSet::findAll([
Expand Down Expand Up @@ -355,14 +351,19 @@ public function previewMetaContainers(
*
* @param string|null $uri
* @param int|null $siteId
* @param ElementInterface|null $element
*/
public function loadMetaContainers(?string $uri = '', ?int $siteId = null)
public function loadMetaContainers(?string $uri = '', int $siteId = null, ?ElementInterface $element = null)
{
Craft::beginProfile('MetaContainers::loadMetaContainers', __METHOD__);
// Avoid recursion
if (!Seomatic::$loadingMetaContainers) {
Seomatic::$loadingMetaContainers = true;
$this->setMatchedElement($uri, $siteId);
// If this is a draft or revision we're previewing, swap it in so they see the draft preview image & data
if ($element && ElementHelper::isDraftOrRevision($element)) {
Seomatic::setMatchedElement($element);
}
// Get the cache tag for the matched meta bundle
$metaBundle = $this->getMatchedMetaBundle();
$metaBundleSourceId = '';
Expand Down
34 changes: 25 additions & 9 deletions src/templates/settings/plugin/_includes/tags.twig
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,35 @@
id: "addXDefaultHrefLang",
name: "addXDefaultHrefLang",
on: settings.addXDefaultHrefLang,
toggle: ".x-default-wrapper",
warning: configWarning("addXDefaultHrefLang", "seomatic"),
errors: settings.getErrors("addXDefaultHrefLang"),
}) }}

{{ forms.lightswitchField({
label: "Include Paginated `hreflang` Tags"|t("seomatic")|md,
instructions: "Controls whether SEOmatic will automatically include `hreflang` tags on paginated pages. [Learn More](https://moz.com/community/q/hreflang-alternate-pagination)"|t("seomatic"),
id: "addPaginatedHreflang",
name: "addPaginatedHreflang",
on: settings.addPaginatedHreflang,
warning: configWarning("addPaginatedHreflang", "seomatic"),
errors: settings.getErrors("addPaginatedHreflang"),
}) }}
<div class="x-default-wrapper {% if not settings.addXDefaultHrefLang %} hidden{% endif %}">
{{ forms.selectField({
label: "`x-default` site"|md|t("seomatic"),
instructions: "Which site should be used as the `x-default` for the `hreflang` tag (default is the Primary site in Craft)."|md|t("seomatic"),
id: "xDefaultSite",
name: "xDefaultSite",
value: settings.xDefaultSite,
options: {
0: "Primary"|t("seomatic"),
} | merge(sites),
warning: configWarning("xDefaultSite", "seomatic"),
errors: settings.getErrors("xDefaultSite"),
}) }}

{{ forms.lightswitchField({
label: "Include Paginated `hreflang` Tags"|t("seomatic")|md,
instructions: "Controls whether SEOmatic will use `hreflang` tags that point to the paginated page rather than the root page on paginated pages. [Learn More](https://moz.com/community/q/hreflang-alternate-pagination)"|t("seomatic"),
id: "addPaginatedHreflang",
name: "addPaginatedHreflang",
on: settings.addPaginatedHreflang,
warning: configWarning("addPaginatedHreflang", "seomatic"),
errors: settings.getErrors("addPaginatedHreflang"),
}) }}
</div>

{{ forms.lightswitchField({
label: "Generator Enabled"|t("seomatic"),
Expand Down
4 changes: 3 additions & 1 deletion src/translations/en/seomatic.php
Original file line number Diff line number Diff line change
Expand Up @@ -522,5 +522,7 @@
'Body Begin - after the <body> tag ' => 'Body Begin - after the <body> tag ',
'The Asset Transform that should be applied to images before they are added to the sitemap.' => 'The Asset Transform that should be applied to images before they are added to the sitemap.',
'Asset Transform for Images' => 'Asset Transform for Images',
'Sitemap Asset Transform' => 'Sitemap Asset Transform'
'Sitemap Asset Transform' => 'Sitemap Asset Transform',
'Controls whether SEOmatic will use `hreflang` tags that point to the paginated page rather than the root page on paginated pages. [Learn More](https://moz.com/community/q/hreflang-alternate-pagination)' => 'Controls whether SEOmatic will use `hreflang` tags that point to the paginated page rather than the root page on paginated pages. [Learn More](https://moz.com/community/q/hreflang-alternate-pagination)',
'Primary' => 'Primary'
];

0 comments on commit db5cc85

Please sign in to comment.