Skip to content

Commit

Permalink
Merge branch 'release/3.5.6' into v3
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Nov 13, 2024
2 parents e916ab0 + 68f7535 commit 646bcf5
Show file tree
Hide file tree
Showing 46 changed files with 781 additions and 844 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# SEOmatic Changelog

## 3.5.6 - 2024.11.12
### Added
* Added the **Site Alternate Name** property to Site Settings, used in the JSON-LD for the homepage, if the MainEntityOfPage is WebPage or WebSite ([#1482](https://github.com/nystudio107/craft-seomatic/issues/1482))
* Added **Letterbox** crop mode for SEO image transforms ([#1337](https://github.com/nystudio107/craft-seomatic/issues/1337))

### Changed
* No longer do a potentially expensive query on page load for sections that have a massive number of entries ([#1526](https://github.com/nystudio107/craft-seomatic/issues/1526))
* If the current route is the homepage, set the `name` and `alternateName` JSON-LD for the `mainEntityOfPage` to `seomatic.site.siteName` and `seomatic.site.identity.genericAlternateName` respectively, rather than the `seomatic.meta.seoTitle` ([#1482](https://github.com/nystudio107/craft-seomatic/issues/1482))
* The SEO preview display in Content SEO will pull an entry from the specific Entry Type rather than just the first entry ([#1535](https://github.com/nystudio107/craft-seomatic/issues/1535))
* Text and Asset pull sources in Content SEO will now display only fields from the specific Entry Type rather than all fields for that Section ([#1535](https://github.com/nystudio107/craft-seomatic/issues/1535))

### Fixed
* Fixed an issue where an exception would be thrown if the Campaign plugin was installed first, and then you newly installed SEOmatic ([#1530](https://github.com/nystudio107/craft-seomatic/issues/1530))

## 3.5.5 - 2024.10.21
### Fixed
* Fixed `togImageField` field typo in the FeedMe integration ([#1520](https://github.com/nystudio107/craft-seomatic/issues/1520))
Expand Down
415 changes: 179 additions & 236 deletions buildchain/package-lock.json

Large diffs are not rendered by default.

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.5.5",
"version": "3.5.6",
"keywords": [
"craft",
"cms",
Expand Down
892 changes: 395 additions & 497 deletions docs/package-lock.json

Large diffs are not rendered by default.

23 changes: 12 additions & 11 deletions src/base/SeoElementInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace nystudio107\seomatic\base;

use craft\base\ElementInterface;

use craft\base\Model;
use craft\elements\db\ElementQueryInterface;
use nystudio107\seomatic\models\MetaBundle;
Expand Down Expand Up @@ -74,36 +73,38 @@ public static function sitemapElementsQuery(MetaBundle $metaBundle): ElementQuer
* and Element ID
*
* @param MetaBundle $metaBundle
* @param int $elementId
* @param int $siteId
* @param int $elementId
* @param int $siteId
*
* @return null|ElementInterface
*/
public static function sitemapAltElement(
MetaBundle $metaBundle,
int $elementId,
int $siteId
int $elementId,
int $siteId
);

/**
* Return a preview URI for a given $sourceHandle and $siteId
* This just returns the first element
*
* @param string $sourceHandle
* @param int|null $siteId
* @param string $sourceHandle
* @param int|null $siteId
* @param int|string|null $typeId
*
* @return string|null
* @return ?string
*/
public static function previewUri(string $sourceHandle, $siteId);
public static function previewUri(string $sourceHandle, $siteId, $typeId = null);

/**
* Return an array of FieldLayouts from the $sourceHandle
*
* @param string $sourceHandle
* @param int|string|null $typeId
*
* @return array
*/
public static function fieldLayouts(string $sourceHandle): array;
public static function fieldLayouts(string $sourceHandle, $typeId = null): array;

/**
* Return the (entry) type menu as a $id => $name associative array
Expand Down Expand Up @@ -136,7 +137,7 @@ public static function sourceModelFromHandle(string $sourceHandle);
* Return the most recently updated Element from a given source model
*
* @param Model $sourceModel
* @param int $sourceSiteId
* @param int $sourceSiteId
*
* @return null|ElementInterface
*/
Expand Down
20 changes: 13 additions & 7 deletions src/controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,8 @@ public function actionEditContent(
$variables['sourceType'] = $metaBundle->sourceType;
// Pass in the pull fields
$groupName = ucfirst($metaBundle->sourceType);
$this->setContentFieldSourceVariables($sourceBundleType, $sourceHandle, $groupName, $variables);
$uri = $this->uriFromSourceBundle($sourceBundleType, $sourceHandle, $siteId);
$this->setContentFieldSourceVariables($sourceBundleType, $sourceHandle, $groupName, $variables, $typeId);
$uri = $this->uriFromSourceBundle($sourceBundleType, $sourceHandle, $siteId, $typeId);
// Preview the meta containers
Seomatic::$plugin->metaContainers->previewMetaContainers(
$uri,
Expand Down Expand Up @@ -1219,20 +1219,23 @@ protected function cullDisabledSites(string $sourceBundleType, string $sourceHan
* @param string $sourceHandle
* @param string $groupName
* @param array $variables
* @param int|string|null $typeId
*/
protected function setContentFieldSourceVariables(
string $sourceBundleType,
string $sourceHandle,
string $groupName,
array &$variables
array &$variables,
$typeId = null
) {
$variables['textFieldSources'] = array_merge(
['entryGroup' => ['optgroup' => $groupName . ' Fields'], 'title' => 'Title'],
FieldHelper::fieldsOfTypeFromSource(
$sourceBundleType,
$sourceHandle,
FieldHelper::TEXT_FIELD_CLASS_KEY,
false
false,
$typeId
)
);
$variables['assetFieldSources'] = array_merge(
Expand All @@ -1241,7 +1244,8 @@ protected function setContentFieldSourceVariables(
$sourceBundleType,
$sourceHandle,
FieldHelper::ASSET_FIELD_CLASS_KEY,
false
false,
$typeId
)
);
$variables['assetVolumeTextFieldSources'] = array_merge(
Expand All @@ -1263,13 +1267,15 @@ protected function setContentFieldSourceVariables(
}

/**
* /**
* @param string $sourceBundleType
* @param string $sourceHandle
* @param null|int $siteId
* @param int|string|null $typeId
*
* @return string
*/
protected function uriFromSourceBundle(string $sourceBundleType, string $sourceHandle, $siteId): string
protected function uriFromSourceBundle(string $sourceBundleType, string $sourceHandle, $siteId, $typeId): string
{
$uri = null;
// Pick an Element to be used for the preview
Expand All @@ -1278,7 +1284,7 @@ protected function uriFromSourceBundle(string $sourceBundleType, string $sourceH
} else {
$seoElement = Seomatic::$plugin->seoElements->getSeoElementByMetaBundleType($sourceBundleType);
if ($seoElement !== null) {
$uri = $seoElement::previewUri($sourceHandle, $siteId);
$uri = $seoElement::previewUri($sourceHandle, $siteId, $typeId);
}
}
// Special-case for the __home__ slug, and default to /
Expand Down
22 changes: 22 additions & 0 deletions src/helpers/DynamicMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
use nystudio107\seomatic\models\jsonld\OpeningHoursSpecification;
use nystudio107\seomatic\models\jsonld\Organization;
use nystudio107\seomatic\models\jsonld\Thing;
use nystudio107\seomatic\models\jsonld\WebPage;
use nystudio107\seomatic\models\jsonld\WebSite;
use nystudio107\seomatic\models\MetaBundle;
use nystudio107\seomatic\models\MetaJsonLd;
use nystudio107\seomatic\Seomatic;
Expand Down Expand Up @@ -290,6 +292,7 @@ public static function addDynamicMetaToContainers(string $uri = null, int $siteI
if (!$request->getIsConsoleRequest()) {
$response = Craft::$app->getResponse();
if ($response->statusCode < 400) {
self::handleHomepage();
self::addMetaJsonLdBreadCrumbs($siteId);
if (Seomatic::$settings->addHrefLang) {
self::addMetaLinkHrefLang($uri, $siteId);
Expand Down Expand Up @@ -317,6 +320,25 @@ public static function addDynamicMetaToContainers(string $uri = null, int $siteI
Craft::endProfile('DynamicMeta::addDynamicMetaToContainers', __METHOD__);
}

/**
* If this is the homepage, and the MainEntityOfPage is WebPage or a WebSite, set the name
* and alternateName so it shows up in SERP as per:
* https://developers.google.com/search/docs/appearance/site-names
*
* @return void
*/
public static function handleHomepage()
{
if (Seomatic::$matchedElement && Seomatic::$matchedElement->uri === '__home__') {
$mainEntity = Seomatic::$plugin->jsonLd->get('mainEntityOfPage');
if ($mainEntity instanceof WebPage || $mainEntity instanceof WebSite) {
/** WebPage $mainEntity */
$mainEntity->name = "{{ seomatic.site.siteName }}";
$mainEntity->alternateName = "{{ seomatic.site.siteAlternateName }}";
}
}
}

/**
* Add breadcrumbs to the MetaJsonLdContainer
*
Expand Down
6 changes: 4 additions & 2 deletions src/helpers/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,22 +266,24 @@ public static function fieldsOfTypeFromGlobals(string $fieldClassKey, bool $keys
* @param string $sourceHandle
* @param string $fieldClassKey
* @param bool $keysOnly
* @param int|string|null $typeId
*
* @return array
*/
public static function fieldsOfTypeFromSource(
string $sourceBundleType,
string $sourceHandle,
string $fieldClassKey,
bool $keysOnly = true
bool $keysOnly = true,
$typeId = null
): array {
$foundFields = [];
$layouts = [];
// Get the layouts
if ($sourceBundleType !== MetaBundles::GLOBAL_META_BUNDLE) {
$seoElement = Seomatic::$plugin->seoElements->getSeoElementByMetaBundleType($sourceBundleType);
if ($seoElement !== null) {
$layouts = $seoElement::fieldLayouts($sourceHandle);
$layouts = $seoElement::fieldLayouts($sourceHandle, $typeId);
}
}
// Iterate through the layouts looking for the fields of the type $fieldType
Expand Down
7 changes: 6 additions & 1 deletion src/models/MetaSiteVars.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,16 @@ class MetaSiteVars extends VarsModel

// Public Properties
// =========================================================================

/**
* @var string The name of the website
*/
public $siteName = '';

/**
* @var string The alternate name of the website
*/
public $siteAlternateName = '';

/**
* @var Entity|array
*/
Expand Down Expand Up @@ -171,6 +175,7 @@ public function rules(): array
[
[
'siteName',
'siteAlternateName',
'twitterHandle',
'facebookProfileId',
'facebookAppId',
Expand Down
11 changes: 7 additions & 4 deletions src/seoelements/SeoCampaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,11 @@ public static function sitemapAltElement(
*
* @param string $sourceHandle
* @param int|null $siteId
* @param int|string|null $typeId
*
* @return string|null
* @return ?string
*/
public static function previewUri(string $sourceHandle, $siteId)
public static function previewUri(string $sourceHandle, $siteId, $typeId = null)
{
$uri = null;
$element = CampaignElement::find()
Expand All @@ -278,10 +279,11 @@ public static function previewUri(string $sourceHandle, $siteId)
* Return an array of FieldLayouts from the $sourceHandle
*
* @param string $sourceHandle
* @param int|string|null $typeId
*
* @return array
*/
public static function fieldLayouts(string $sourceHandle): array
public static function fieldLayouts(string $sourceHandle, $typeId = null): array
{
$layouts = [];
try {
Expand Down Expand Up @@ -444,11 +446,12 @@ public static function sourceHandleFromElement(ElementInterface $element)
public static function createContentMetaBundle(Model $sourceModel)
{
/** @var CampaignTypeModel $sourceModel */
$sourceModel->attachBehavior('SEOmaticCampaignBehavior', CampaignBehavior::class);
$sites = Craft::$app->getSites()->getAllSites();
/** @var Site $site */
foreach ($sites as $site) {
$seoElement = self::class;
Seomatic::$plugin->metaBundles->createMetaBundleFromSeoElement($seoElement, $sourceModel, $site->id);
Seomatic::$plugin->metaBundles->createMetaBundleFromSeoElement($seoElement, $sourceModel, $site->id, null, true);
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/seoelements/SeoCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,11 @@ public static function sitemapAltElement(
*
* @param string $sourceHandle
* @param int|null $siteId
* @param int|string|null $typeId
*
* @return string|null
* @return ?string
*/
public static function previewUri(string $sourceHandle, $siteId)
public static function previewUri(string $sourceHandle, $siteId, $typeId = null)
{
$uri = null;
$element = Category::find()
Expand All @@ -273,10 +274,11 @@ public static function previewUri(string $sourceHandle, $siteId)
* Return an array of FieldLayouts from the $sourceHandle
*
* @param string $sourceHandle
* @param int|string|null $typeId
*
* @return array
*/
public static function fieldLayouts(string $sourceHandle): array
public static function fieldLayouts(string $sourceHandle, $typeId = null): array
{
$layouts = [];
$layoutId = null;
Expand Down Expand Up @@ -437,7 +439,7 @@ public static function createContentMetaBundle(Model $sourceModel)
/** @var Site $site */
foreach ($sites as $site) {
$seoElement = self::class;
Seomatic::$plugin->metaBundles->createMetaBundleFromSeoElement($seoElement, $sourceModel, $site->id);
Seomatic::$plugin->metaBundles->createMetaBundleFromSeoElement($seoElement, $sourceModel, $site->id, null, true);
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/seoelements/SeoDigitalProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,11 @@ public static function sitemapAltElement(
*
* @param string $sourceHandle
* @param int|null $siteId
* @param int|string|null $typeId
*
* @return string|null
* @return ?string
*/
public static function previewUri(string $sourceHandle, $siteId)
public static function previewUri(string $sourceHandle, $siteId, $typeId = null)
{
$uri = null;
$element = Product::find()
Expand All @@ -266,10 +267,11 @@ public static function previewUri(string $sourceHandle, $siteId)
* Return an array of FieldLayouts from the $sourceHandle
*
* @param string $sourceHandle
* @param int|string|null $typeId
*
* @return array
*/
public static function fieldLayouts(string $sourceHandle): array
public static function fieldLayouts(string $sourceHandle, $typeId = null): array
{
$layouts = [];
$digitalProducts = DigitalProductsPlugin::getInstance();
Expand Down Expand Up @@ -445,7 +447,7 @@ public static function createContentMetaBundle(Model $sourceModel)
/** @var Site $site */
foreach ($sites as $site) {
$seoElement = self::class;
Seomatic::$plugin->metaBundles->createMetaBundleFromSeoElement($seoElement, $sourceModel, $site->id);
Seomatic::$plugin->metaBundles->createMetaBundleFromSeoElement($seoElement, $sourceModel, $site->id, null, true);
}
}

Expand Down
Loading

0 comments on commit 646bcf5

Please sign in to comment.