Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules
composer.lock
node_modules
vendor
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release Notes for Glossary Plugin

## 3.1.0 - 2024-09-15

### Fixed

- Workaround twig template deprecations that cause errors.

## 2.0.1 - 2022-12-15

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ A glossary plugin for Craft CMS.

## Requirements

* Craft CMS >= 4.0.0
* Craft CMS >= 5.0.0

## Installation

Expand Down
16 changes: 14 additions & 2 deletions 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.1",
"version": "3.1.0",
"type": "craft-plugin",
"keywords": [
"craft",
Expand All @@ -23,7 +23,8 @@
"issues": "https://github.com/codemonauts/craft-glossary/issues"
},
"require": {
"craftcms/cms": "^4.0.0"
"craftcms/cms": "^5.0.0-beta.1",
"php": "^8.2"
},
"autoload": {
"psr-4": {
Expand All @@ -34,5 +35,16 @@
"handle": "glossary",
"class": "codemonauts\\glossary\\Glossary",
"name": "Glossary"
},
"config": {
"allow-plugins": {
"yiisoft/yii2-composer": true,
"craftcms/plugin-installer": true
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"require-dev": {
"craftcms/rector": "dev-main"
}
}
6 changes: 3 additions & 3 deletions src/elements/Glossary.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public static function defineSearchableAttributes(): array
/**
* @inheritDoc
*/
protected static function defineFieldLayouts(string $source): array
protected static function defineFieldLayouts(?string $source): array
{
return [];
}
Expand All @@ -200,7 +200,7 @@ public function getFieldLayout(): ?FieldLayout
/**
* @inheritDoc
*/
public function tableAttributeHtml(string $attribute): string
public function attributeHtml(string $attribute): string
{
if ($attribute === 'default') {
return $this->default ? '<div data-icon="check" aria-label="' . Craft::t('app', 'Yes') . '""></div>' : '';
Expand All @@ -210,7 +210,7 @@ public function tableAttributeHtml(string $attribute): string
return Term::find()->glossaryId($this->id)->count();
}

return parent::tableAttributeHtml($attribute);
return parent::attributeHtml($attribute);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/elements/Term.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public static function defineSearchableAttributes(): array
/**
* @inheritDoc
*/
public function tableAttributeHtml(string $attribute): string
public function attributeHtml(string $attribute): string
{
if ($attribute === 'caseSensitive') {
return $this->caseSensitive ? '<div data-icon="check" aria-label="' . Craft::t('app', 'Yes') . '""></div>' : '';
Expand All @@ -211,13 +211,13 @@ public function tableAttributeHtml(string $attribute): string
return $this->matchSubstring ? '<div data-icon="check" aria-label="' . Craft::t('app', 'Yes') . '""></div>' : '';
}

return parent::tableAttributeHtml($attribute);
return parent::attributeHtml($attribute);
}

/**
* @inheritDoc
*/
protected static function defineFieldLayouts(string $source): array
protected static function defineFieldLayouts(?string $source): array
{
if ($source === '*') {
$glossaries = GlossaryPlugin::getInstance()->getGlossaries()->getAllGlossaries();
Expand Down
3 changes: 2 additions & 1 deletion src/elements/db/TermQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class TermQuery extends ElementQuery
public function glossary($value): TermQuery
{
if ($value instanceof GlossaryElement) {
$this->glossaryId = $value->id;
// $this->glossaryId = $value->id;
$this->glossaryId = $value['id'];
} elseif ($value !== null) {
$this->glossaryId = GlossaryRecord::find()
->select(['id'])
Expand Down
14 changes: 13 additions & 1 deletion src/services/Terms.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Twig\Error\SyntaxError;
use yii\base\Component;
use function Symfony\Component\String\s;
use craft\elements\Entry;

class Terms extends Component
{
Expand Down Expand Up @@ -100,6 +101,17 @@ public function renderTerms(string $text, Glossary $glossary): string
$variables = $term->getFieldValues();
$variables['term'] = $term;

// Construct the search string
$searchString = 'title:"' . $term . '"';

// Perform the search
$entry = Entry::find()
->section('glossary')
->search($searchString)
->one();

$variables['caption'] = $entry->caption;

try {
$this->usedTerms[$term->id] = $view->renderTemplate($glossary->tooltipTemplate, $variables, 'site');
} catch (SyntaxError $e) {
Expand Down Expand Up @@ -144,4 +156,4 @@ public function getRenderedTerms(): string
{
return $this->renderedTerms;
}
}
}