Skip to content

Commit

Permalink
Added categories field into Article and RSSProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
ZoranIT committed Feb 12, 2025
1 parent a6a59e2 commit 3f5753e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/Widget/DataType/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Article implements \JsonSerializable, DataTypeInterface
public $permalink;
public $link;
public $image;
public $categories = [];

/** @var \Carbon\Carbon */
public $date;
Expand All @@ -57,6 +58,7 @@ public function jsonSerialize(): array
'date' => $this->date->format('c'),
'publishedDate' => $this->publishedDate->format('c'),
'image' => $this->image,
'categories' => $this->categories,
];
}

Expand All @@ -74,7 +76,9 @@ public function getDefinition(): DataType
->addField('link', __('Link'), 'text')
->addField('date', __('Created Date'), 'datetime')
->addField('publishedDate', __('Published Date'), 'datetime')
->addField('image', __('Image'), 'image');
->addField('image', __('Image'), 'image')
->addField('categories', __('Categories'), 'categories');
return $dataType;
}
}

1 change: 1 addition & 0 deletions lib/Widget/RssProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public function fetchData(DataProviderInterface $dataProvider): WidgetProviderIn
$article->link = $item->getUrl();
$article->date = Carbon::instance($item->getDate());
$article->publishedDate = Carbon::instance($item->getPublishedDate());
$article->categories = $item->getCategories();

// Body safe HTML
$article->content = $dataProvider->getSanitizer(['content' => $item->getContent()])
Expand Down
11 changes: 11 additions & 0 deletions modules/templates/article-elements.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,15 @@ if (
<startWidth>480</startWidth>
<startHeight>100</startHeight>
</template>
<template>
<id>article_categories</id>
<extends override="text" with="data.categories">text</extends>
<title>Categories</title>
<type>element</type>
<dataType>article</dataType>
<icon>fas fa-icons</icon>
<canRotate>true</canRotate>
<startWidth>480</startWidth>
<startHeight>100</startHeight>
</template>
</templates>

0 comments on commit 3f5753e

Please sign in to comment.