Skip to content

Commit

Permalink
Merge branch 'release/4.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
janhenckens committed Jan 21, 2024
2 parents 62d45cc + e60469c commit cdc4fe7
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ 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/).

## 4.0.1 - 2024-01-21
### Fixed
- Fixed on issue on the schema settings screen, when no settings had been defined yet


## 4.0.0 - 2024-01-20
### Added
- JSON-LD Schema.org markup
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": "studioespresso/craft-seo-fields",
"description": "Fields for your SEO & OG meta data",
"type": "craft-plugin",
"version": "4.0.0",
"version": "4.0.1",
"keywords": [
"craft",
"cms",
Expand Down
49 changes: 41 additions & 8 deletions src/models/SeoFieldModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,49 @@ public function getSchema(Element $element = null)
return null;
}

$schema = SeoFields::getInstance()->schemaService->getSchemaForElement($element);
if ($schema) {
\Craft::$app->getView()->registerScript(
Json::encode($schema),
View::POS_END, [
'type' => 'application/ld+json'
]
);
try {
$schema = null;
$settings = $this->siteDefault->getSchema();
switch (get_class($element)) {
case Entry::class:
$schemaSettings = $settings['sections'];
$sectionId = $element->section->id;
$schemaClass = $schemaSettings[$sectionId];

/** @var $schema Schema */
$schema = \Craft::createObject($schemaClass);
$schema->name($this->getMetaTitle($element, false) ?? "");
$schema->description($this->getMetaDescription() ?? "");
$schema->url($element->getUrl() ?? "");
break;
case Category::class:
$schemaSettings = $settings['groups'];
$groupId = $element->group->id;
$schemaClass = $schemaSettings[$groupId];

/** @var $schema Schema */
$schema = Craft::createObject($schemaClass);
$schema->name($this->getMetaTitle($element, false) ?? "");
$schema->description($this->getMetaDescription() ?? "");
$schema->url($element->getUrl() ?? "");
break;
}
if ($schema) {
\Craft::$app->getView()->registerScript(
Json::encode($schema),
View::POS_END, [
'type' => 'application/ld+json'
]
);
}


} catch (\Exception $e) {
\Craft::error($e, SeoFields::class);
return null;
}


}

public function getSiteNameWithSeperator()
Expand Down
6 changes: 3 additions & 3 deletions src/templates/_includes/_schema/_sections.twig
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
<tbody>

{% set schemaSettings = data.schema|json_decode %}
{% set sectionSettings = schemaSettings.sections %}
{% set sectionSettings = schemaSettings.sections ?? [] %}
{% for section in sections %}
{% set settings = attribute(sectionSettings, section.id) ?? [] %}
{% set settings = attribute(sectionSettings, section.id) ?? null %}
<tr>
<th>{{ section.name }}</th>
<td>
Expand All @@ -24,7 +24,7 @@
options: options,
includeEnvVars: false,
allowedEnvValues: false,
value: settings,
value: settings ,
}) }}
</td>
</tr>
Expand Down

0 comments on commit cdc4fe7

Please sign in to comment.