Skip to content

Commit

Permalink
feat: add tags
Browse files Browse the repository at this point in the history
  • Loading branch information
7underlines committed Jan 6, 2025
1 parent 908991f commit 332ff6b
Show file tree
Hide file tree
Showing 26 changed files with 136 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG_de-DE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 4.2.0
- Tags hinzugefügt [5](https://github.com/Werkstattl/OpenBlogware/issues/5)

# 4.1.4
- Fehler bei Author für Meta-Daten behoben [9](https://github.com/Werkstattl/OpenBlogware/issues/9)

Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG_en-GB.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 4.2.0
- Added tags [5](https://github.com/Werkstattl/OpenBlogware/issues/5)

# 4.1.4
- Fixed author for meta data [9](https://github.com/Werkstattl/OpenBlogware/issues/9)

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": "werkstattl/openblogware",
"description": "OpenBlogware: A Blog Module for Shopware 6.",
"version": "4.1.4",
"version": "4.2.0",
"type": "shopware-platform-plugin",
"keywords": ["blog", "news"],
"license":"MIT",
Expand Down
35 changes: 35 additions & 0 deletions src/Content/Blog/Aggregate/BlogEntriesTagMappingDefinition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);

namespace Werkl\OpenBlogware\Content\Blog\Aggregate;

use Shopware\Core\Framework\DataAbstractionLayer\Field\FkField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\PrimaryKey;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\Required;
use Shopware\Core\Framework\DataAbstractionLayer\Field\ManyToOneAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection;
use Shopware\Core\Framework\DataAbstractionLayer\MappingEntityDefinition;
use Shopware\Core\System\Tag\TagDefinition;
use Werkl\OpenBlogware\Content\Blog\BlogEntriesDefinition;


class BlogEntriesTagMappingDefinition extends MappingEntityDefinition
{
public const ENTITY_NAME = 'werkl_blog_entries_tag';

public function getEntityName(): string
{
return self::ENTITY_NAME;
}

protected function defineFields(): FieldCollection
{
return new FieldCollection([
(new FkField('werkl_blog_entries_id', 'blogId', BlogEntriesDefinition::class))->addFlags(new PrimaryKey(), new Required()),
(new FkField('tag_id', 'tagId', TagDefinition::class))->addFlags(new PrimaryKey(), new Required()),

new ManyToOneAssociationField('blog', 'werkl_blog_entries_id', BlogEntriesDefinition::class, 'id', false),
new ManyToOneAssociationField('tag', 'tag_id', TagDefinition::class, 'id', false),
]);
}
}
2 changes: 2 additions & 0 deletions src/Content/Blog/BlogEntriesDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Shopware\Core\Framework\DataAbstractionLayer\Field\TranslatedField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\TranslationsAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection;
use Shopware\Core\System\Tag\TagDefinition;
use Werkl\OpenBlogware\Content\Blog\Aggregate\BlogCategoryMappingDefinition;
use Werkl\OpenBlogware\Content\Blog\BlogEntriesTranslation\BlogEntriesTranslationDefinition;
use Werkl\OpenBlogware\Content\BlogAuthor\BlogAuthorDefinition;
Expand Down Expand Up @@ -81,6 +82,7 @@ protected function defineFields(): FieldCollection
(new ManyToManyAssociationField('blogCategories', BlogCategoryDefinition::class, BlogCategoryMappingDefinition::class, 'werkl_blog_entries_id', 'werkl_blog_category_id'))->addFlags(new CascadeDelete(), new ApiAware(), new SearchRanking(SearchRanking::ASSOCIATION_SEARCH_RANKING)),
(new ManyToOneAssociationField('blogAuthor', 'author_id', BlogAuthorDefinition::class, 'id', false))->addFlags(new ApiAware(), new SearchRanking(SearchRanking::ASSOCIATION_SEARCH_RANKING)),
(new OneToOneAssociationField('cmsPage', 'cms_page_id', 'id', CmsPageDefinition::class, false))->addFlags(new ApiAware()),
(new ManyToManyAssociationField('tags', TagDefinition::class, 'werkl_blog_entries_tag', 'werkl_blog_entries_id', 'tag_id'))->addFlags(new ApiAware()),
]);
}
}
24 changes: 23 additions & 1 deletion src/Content/Blog/BlogEntriesEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Shopware\Core\Framework\DataAbstractionLayer\Entity;
use Shopware\Core\Framework\DataAbstractionLayer\EntityCustomFieldsTrait;
use Shopware\Core\Framework\DataAbstractionLayer\EntityIdTrait;
use Shopware\Core\System\Tag\TagCollection;
use Werkl\OpenBlogware\Content\Blog\BlogEntriesTranslation\BlogEntriesTranslationCollection;
use Werkl\OpenBlogware\Content\BlogAuthor\BlogAuthorEntity;
use Werkl\OpenBlogware\Content\BlogCategory\BlogCategoryCollection;
Expand Down Expand Up @@ -57,6 +58,11 @@ class BlogEntriesEntity extends Entity

protected ?CmsPageEntity $cmsPage;

/**
* @var TagCollection|null
*/
protected ?TagCollection $tags = null;

public function getTitle(): ?string
{
return $this->title;
Expand Down Expand Up @@ -226,4 +232,20 @@ public function setCmsPageId(string $cmsPageId): void
{
$this->cmsPageId = $cmsPageId;
}
}

/**
* @return TagCollection|null
*/
public function getTags(): ?TagCollection
{
return $this->tags;
}

/**
* @param TagCollection|null $tags
*/
public function setTags(?TagCollection $tags): void
{
$this->tags = $tags;
}
}
1 change: 1 addition & 0 deletions src/Content/Blog/BlogSeoUrlRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function prepareCriteria(Criteria $criteria, SalesChannelEntity $salesCha
$criteria->addAssociations([
'blogCategories',
'blogAuthor',
'tags'
]);
}

Expand Down
1 change: 1 addition & 0 deletions src/Content/Blog/DataResolver/BlogCmsElementResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public function collect(CmsSlotEntity $slot, ResolverContext $resolverContext):
'blogAuthor.media',
'blogAuthor.blogEntries',
'blogCategories',
'tags'
]);

$criteria->addSorting(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function collect(CmsSlotEntity $slot, ResolverContext $resolverContext):
new EqualsFilter('customFields.salesChannelIds', null),
]));
$criteria
->addAssociations(['blogAuthor', 'blogCategories'])
->addAssociations(['blogAuthor', 'blogCategories', 'tags'])
->addAssociation('cmsPage.sections.backgroundMedia')
->addAssociation('cmsPage.sections.blocks.backgroundMedia');
$criteria
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ private function createCriteria(FieldConfigCollection $config, SalesChannelConte
'blogAuthor.media',
'blogAuthor.blogEntries',
'blogCategories',
'tags',
]);

$showTypeConfig = $config->get('showType') ?? null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function collect(CmsSlotEntity $slot, ResolverContext $resolverContext):
new ContainsFilter('customFields.salesChannelIds', $resolverContext->getSalesChannelContext()->getSalesChannelId()),
new EqualsFilter('customFields.salesChannelIds', null),
]));
$criteria->addAssociations(['blogAuthor', 'blogAuthor.media', 'blogAuthor.blogEntries', 'blogCategories']);
$criteria->addAssociations(['blogAuthor', 'blogAuthor.media', 'blogAuthor.blogEntries', 'blogCategories', 'tags']);

$criteriaCollection = new CriteriaCollection();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ private function getBlogs(string $term, int $limit, Context $context): EntitySea
$criteria->setTerm($term);
$criteria->setLimit($limit);
$criteria->addAssociation('media');
$criteria->addAssociation('tags');
$criteria->addAssociation('blogCategories');
$criteria->getAssociation('blogCategories')->addSorting(new FieldSorting('level', FieldSorting::ASCENDING));

Expand Down
2 changes: 1 addition & 1 deletion src/Controller/BlogRssController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function rss(Request $request, SalesChannelContext $context): Response
$dateTime = new \DateTime();

$criteria = new Criteria();
$criteria->addAssociations(['blogAuthor.salutation']);
$criteria->addAssociations(['blogAuthor.salutation', 'tags']);
$criteria->addFilter(
new EqualsFilter('active', true),
new RangeFilter('publishedAt', [RangeFilter::LTE => $dateTime->format(\DATE_ATOM)])
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/StoreApi/BlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected function buildCriteria(Request $request, Criteria $criteria): Criteria
}
}

$criteria->addAssociations(['blogAuthor.salutation', 'blogCategories']);
$criteria->addAssociations(['blogAuthor.salutation', 'blogCategories', 'tags']);

return $criteria;
}
Expand Down
34 changes: 34 additions & 0 deletions src/Migration/Migration1736010505Tags.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
declare(strict_types=1);

namespace Werkl\OpenBlogware\Migration;

use Doctrine\DBAL\Connection;
use Shopware\Core\Framework\Migration\MigrationStep;

class Migration1736010505Tags extends MigrationStep
{
public function getCreationTimestamp(): int
{
return 1736010505;
}

public function update(Connection $connection): void
{
$connection->executeStatement('
CREATE TABLE IF NOT EXISTS `werkl_blog_entries_tag` (
`werkl_blog_entries_id` BINARY(16) NOT NULL,
`tag_id` BINARY(16) NOT NULL,
PRIMARY KEY (`werkl_blog_entries_id`,`tag_id`),
KEY `fk.werkl_blog_entries_tag.werkl_blog_entries_id` (`werkl_blog_entries_id`),
KEY `fk.werkl_blog_entries_tag.tag_id` (`tag_id`),
CONSTRAINT `fk.werkl_blog_entries_tag.werkl_blog_entries_id` FOREIGN KEY (`werkl_blog_entries_id`) REFERENCES `werkl_blog_entries` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk.werkl_blog_entries_tag.tag_id` FOREIGN KEY (`tag_id`) REFERENCES `tag` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
'); }

public function updateDestructive(Connection $connection): void
{
// implement update destructive
}
}
1 change: 1 addition & 0 deletions src/Page/Blog/BlogPageLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ private function loadBlogEntry(string $articleId, SalesChannelContext $context):
$criteria = (new Criteria([$articleId]))
->addAssociation('author.salutation')
->addAssociation('blogCategories')
->addAssociation('tags')
->addAssociation('blogAuthor');
$this->eventDispatcher->dispatch(new BlogPageCriteriaEvent($articleId, $criteria, $context));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Shopware.Component.register('sw-cms-el-blog-single-select', {
if (this.element.config.blogEntry.value) {
const criteria = new Criteria();
criteria.addAssociation('blogCategories');
criteria.addAssociation('tags');

this.repository
.get(this.element.config.blogEntry.value, Context.api, criteria)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ Component.extend('werkl-cms-sidebar', 'sw-cms-sidebar', {
return this.repositoryFactory.create('media');
},

tagRepository() {
return this.repositoryFactory.create('tag');
},

positionIdentifierExtension() {
return 'werkl-cms-sidebar-extension';
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@
:categoriesCollection="blog.blogCategories"
></werkl-blog-category-tree-field>
{% endblock %}
{% block werkl_blog_cms_sidebar_page_settings_tags %}
<sw-entity-tag-select
v-if="blog && !isLoading"
v-model:entityCollection="blog.tags"
class="sw-blog-detail-base__tags"
:label="$tc('werkl-blog.detail.tagsLabel')"
:placeholder="$tc('werkl-blog.detail.tagsPlaceholder')"
/>
{% endblock %}
</div>
</template>
{% endblock %}
Expand Down Expand Up @@ -249,4 +258,4 @@
</template>
</werkl-blog-extension-component-sections>
{% endblock %}
{% endblock %}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Component.extend('werkl-blog-detail', 'sw-cms-detail', {

criteria
.addAssociation('blogCategories')
.addAssociation('tags')

.getAssociation('cmsPage')
.getAssociation('sections')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Component.register('werkl-blog-list', {
const criteria = new Criteria(this.page, this.limit);
criteria.addAssociation('blogAuthor');
criteria.addAssociation('blogCategories');
criteria.addAssociation('tags');

criteria.addSorting(Criteria.sort('publishedAt', 'DESC', false));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
"teaserLabel": "Teaser",
"teaserImageLabel": "Teaser Bild",
"teaserPlaceholder": "Der Teaser Text, welcher im Blog Listing angezeigt wird ...",
"tagsLabel": "Tags",
"tagsPlaceholder": "Füge Tags hinzu ...",
"editorCardTitle": "Dein Artikel",
"editorLabel": "Blog Inhalt",
"editorPlaceholder": "Starte deinen Blog Beitrag ...",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
"teaserLabel": "Teaser",
"teaserImageLabel": "Teaser Image",
"teaserPlaceholder": "The teaser text which will be shown as an introduction within the blog listing ...",
"tagsLabel": "Tags",
"tagsPlaceholder": "Enter a tag ...",
"editorCardTitle": "Your article",
"editorLabel": "Blog Content",
"editorPlaceholder": "Start your blog post ...",
Expand Down
4 changes: 4 additions & 0 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
<tag name="shopware.entity.definition"/>
</service>

<service id="Werkl\OpenBlogware\Content\Blog\Aggregate\BlogEntriesTagMappingDefinition">
<tag name="shopware.entity.definition"/>
</service>

<service id="Werkl\OpenBlogware\Content\BlogAuthor\BlogAuthorDefinition">
<tag name="shopware.entity.definition"/>
</service>
Expand Down
Empty file modified src/Resources/public/administration/css/werkl-open-blogware.css
100644 → 100755
Empty file.

Large diffs are not rendered by default.

0 comments on commit 332ff6b

Please sign in to comment.