Skip to content

Commit

Permalink
fix multiple applying, empty strings
Browse files Browse the repository at this point in the history
  • Loading branch information
kringkaste committed Dec 14, 2022
1 parent c872cba commit d650ba5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Release Notes for Glossary Plugin

## 2.0.1 - 2022-12-15

### Fixed

- Missing definitions when applying the glossary multiple times. (#5)
- Remove empty strings from terms breaking the frontend. (#7)

## 2.0.0 - 2022-05-04

### Added
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "codemonauts/craft-glossary",
"description": "Add glossaries with tooltips to Craft CMS.",
"version": "2.0.0",
"version": "2.0.1",
"type": "craft-plugin",
"keywords": [
"craft",
Expand Down
1 change: 1 addition & 0 deletions src/elements/Term.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ public function defineRules(): array
$rules = parent::defineRules();

$rules[] = [['term'], 'required', 'on' => self::SCENARIO_LIVE];
$rules[] = [['term', 'synonyms'], 'trim'];
$rules[] = [['glossaryId'], 'integer'];
$rules[] = [['caseSensitive', 'matchSubstring'], 'boolean'];

Expand Down
12 changes: 7 additions & 5 deletions src/services/Terms.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use codemonauts\glossary\elements\Glossary;
use codemonauts\glossary\elements\Term;
use Craft;
use craft\helpers\ArrayHelper;
use craft\helpers\Html;
use Exception;
use Twig\Error\SyntaxError;
Expand All @@ -13,8 +14,9 @@

class Terms extends Component
{
protected $renderedTerms = '';
private $usedTerms = [];
protected string $renderedTerms = '';

protected array $usedTerms = [];

/**
* Returns all terms to search for.
Expand All @@ -29,12 +31,12 @@ public function parseTerms(Term $term): array
$term->term,
];

if ($term->synonyms !== '') {
if (!empty($term->synonyms)) {
$synonyms = explode(',', $term->synonyms);
$terms = array_merge($terms, $synonyms);
}

return $terms;
return ArrayHelper::filterEmptyStringsFromArray($terms);
}

/**
Expand All @@ -51,7 +53,7 @@ public function renderTerms(string $text, Glossary $glossary): string
$originalText = $text;

try {
$termTemplate = $glossary->termTemplate !== '' ? $glossary->termTemplate : '<span>{{ text }}</span>';
$termTemplate = !empty($glossary->termTemplate) ? $glossary->termTemplate : '<span>{{ text }}</span>';
$replacements = [];
$terms = Term::find()->glossary($glossary)->all();

Expand Down

0 comments on commit d650ba5

Please sign in to comment.