Skip to content

Commit

Permalink
Merge pull request #17 from thewebmen/feature/single-article-grid-blo…
Browse files Browse the repository at this point in the history
…ck-and-translations

Single article grid element and updated translations
  • Loading branch information
Dennis Prins authored Jul 6, 2022
2 parents 5e4d535 + 3386f6d commit 7c7aee8
Show file tree
Hide file tree
Showing 10 changed files with 200 additions and 67 deletions.
12 changes: 12 additions & 0 deletions lang/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,15 @@ en:
one: 'A type'
other: '{count} types'
SINGULARNAME: 'Type'
TheWebmen\Articles\Models\Author:
PLURALNAME: 'Authors'
PLURALS:
one: 'An author'
other: '{count} authors'
SINGULARNAME: 'Author'
TheWebmen\Articles\Models\Tag:
PLURALNAME: 'Tags'
PLURALS:
one: 'A tag'
other: '{count} tags'
SINGULARNAME: 'Tag'
66 changes: 32 additions & 34 deletions lang/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@ nl:
one: 'Een artikel'
other: '{count} artikelen'
SINGULARNAME: 'Artikel'
TEASERTEXT: 'Teaser tekst'
THUMBNAIL: 'Voorvertoning'
READINGTIME: 'Leestijd (in min.)'
PUBLICATIONDATE: 'Publicatiedatum'
UPDATEDATE: 'Updatedatum'
METADATA: 'Metadata'
SUBTITLE: 'Subtitel'
TheWebmen\Articles\Pages\ArticlesPage:
PLURALNAME: 'Artikelen overzicht paginas'
PLURALS:
one: 'Een artikelen overzicht pagina'
other: '{count} artikelen overzicht paginas'
SINGULARNAME: 'Artikelen overzicht pagina'
ARTICLES: 'Artikelen'
HIGHLIGHTEDARTICLES: 'Gehighlighte artikelen'
PINNEDARTICLES: 'Gepinde artikelen'
db_PageLength: 'Pagina lengte'
TheWebmen\Articles\Extensions:
has_many_Articles: 'Artikelen'
Expand All @@ -27,37 +36,26 @@ nl:
one: 'Een type'
other: '{count} types'
SINGULARNAME: 'Type'
ElementArticles:
Optional: 'Optioneel'
ShowHighlightedArticlesOnly: 'Weergeef alleen uitgelichte artikelen'
ShowPinnedArticlesAtTop: 'Weergeef vastgeprikte artikelen bovenaan'
MaxAmount: 'Maximaal aantal weer te geven artikelen'
ShowMoreArticlesButton: "Weergeef 'meer artikelen' knop"
ShowMoreArticlesButtonText: "'Meer artikelen' knop tekst"
Results: 'Resultaten'
Articles:
NoArticlesFound: 'Geen artikelen gevonden'
Article:
Singular: 'Artikel'
Plural: 'Artikelen'
Title: 'Artikel titel'
Subtitle: 'Artikel subtitel'
Author:
Name: 'Auteur naam'
ReadingTime: 'Leestijd (in min.)'
Date:
Publication: 'Publicatie datum'
Updated: 'Publicatie datum'
Metadata: 'Artikel metadata'
TeaserText: 'Teaser tekst'
HighlightArticle: 'Artikel uitlichten'
PinArticle: 'Artikel vastpinnen'
Theme:
Singular: "Thema"
Plural: "Thema's"
Tag:
Singular: "Tag"
Plural: "Tags"
Type:
Singular: "Type"
Plural: "Types"
TheWebmen\Articles\Models\Author:
PLURALNAME: 'Auteurs'
PLURALS:
one: 'Een auteur'
other: '{count} auteurs'
SINGULARNAME: 'Auteur'
TheWebmen\Articles\Models\Tag:
PLURALNAME: 'Tags'
PLURALS:
one: 'Een tag'
other: '{count} tags'
SINGULARNAME: 'Tag'
NAME: 'Naam'
TheWebmen\Articles\ElementalGrid\ElementArticles:
OPTIONAL: 'Optioneel'
MAXAMOUNT: 'Max. weer te geven aantal'
SHOWMOREBUTTON: 'Toon meer artikelen button'
SHOWMOREBUTTONTEXT: 'Meer artikelen buttontekst'
NOARTICLESFOUND: 'Geen artikelen gevonden'
TheWebmen\Articles\ElementalGrid\ElementArticle:
ARTICLETOSHOW: 'Artikel om weer te geven'
NOARTICLEFOUND: 'Geen artikel gevonden'

105 changes: 105 additions & 0 deletions src/ElementalGrid/ElementArticle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php

namespace TheWebmen\Articles\ElementalGrid;

use DNADesign\Elemental\Models\BaseElement;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\TreeDropdownField;
use TheWebmen\Articles\Pages\ArticlePage;

/**
* Class ElementArticle
* @package TheWebmen\Articles\ElementalGrid
*
* @method ArticlePage ArticlePage()
*/
class ElementArticle extends BaseElement
{
/**
* @var string
*/
private static $table_name = 'Element_Article';

/**
* @var string
*/
private static $singular_name = 'Article';

/**
* @var string
*/
private static $plural_name = 'Articles';

/**
* @var string
*/
private static $description = 'Show an article in a grid element';

/**
* @var string
*/
private static $icon = 'font-icon-p-list';

/**
* @var array
*/
private static $has_one = [
'ArticlePage' => ArticlePage::class,
];

/**
* @var array
*/
private static $db = [
'ShowMoreArticlesButton' => 'Boolean',
'ShowMoreArticlesButtonText' => 'Varchar(255)',
];

public function getCMSFields(): FieldList
{
$fields = parent::getCMSFields();

$fields->addFieldsToTab(
'Root.Main',
[
TreeDropdownField::create('ArticlePageID', _t(__CLASS__ . '.ARTICLETOSHOW'), ArticlePage::class),
]
);

$fields->removeByName(
[
'ShowMoreArticlesButton',
'ShowMoreArticlesButtonText',
]
);

$fields->addFieldsToTab(
'Root.Main',
[
CheckboxField::create(
'ShowMoreArticlesButton',
_t('TheWebmen\Articles\ElementalGrid.SHOWMOREBUTTON', "Show 'more articles' button")
),
TextField::create(
'ShowMoreArticlesButtonText',
_t('TheWebmen\Articles\ElementalGrid.SHOWMOREBUTTONTEXT', "Show 'more articles' button")
)
->displayIf('ShowMoreArticlesButton')
->isChecked()
->end(),
]
);

$this->extend('onAfterUpdateCMSFields', $fields);

return $fields;
}

public function getType(): string
{
return 'Article';
}
}
18 changes: 9 additions & 9 deletions src/ElementalGrid/ElementArticles.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ public function getCMSFields(): FieldList
'Themes',
sprintf(
'%s (%s)',
_t('Theme.Plural', 'Themes'),
strtolower(_t('ElementArticles.Optional', 'Optional'))
_t('TheWebmen\Articles\Pages\ArticleThemePage.PLURALNAME', 'Themes'),
strtolower(_t(__CLASS__ . '.OPTIONAL', 'Optional'))
),
ArticleThemePage::get()->filter('ParentID', $this->ArticlesPage()->ID),
$this->Themes()
Expand All @@ -127,8 +127,8 @@ public function getCMSFields(): FieldList
'Types',
sprintf(
'%s (%s)',
_t('Type.Plural', 'Types'),
strtolower(_t('ElementArticles.Optional', 'Optional'))
_t('TheWebmen\Articles\Pages\ArticleTypePage.PLURALNAME', 'Types'),
strtolower(_t(__CLASS__ . '.OPTIONAL', 'Optional'))
),
ArticleTypePage::get()->filter('ParentID', $this->ArticlesPage()->ID),
$this->Types()
Expand All @@ -137,23 +137,23 @@ public function getCMSFields(): FieldList
'Authors',
sprintf(
'%s (%s)',
_t('Author.Plural', 'Authors'),
strtolower(_t('ElementArticles.Optional', 'Optional'))
_t('TheWebmen\Articles\Models\Author.PLURALNAME', 'Authors'),
strtolower(_t(__CLASS__ . '.OPTIONAL', 'Optional'))
),
$this->ArticlesPage()->Authors(),
$this->Authors()
)->setCanCreate(false),
NumericField::create(
'MaxAmount',
_t('ElementArticles.MaxAmount', 'Max. amount of articles shown')
_t(__CLASS__ . '.MAXAMOUNT', 'Max. amount of articles shown')
),
CheckboxField::create(
'ShowMoreArticlesButton',
_t('ElementArticles.ShowMoreArticlesButton', "Show 'more articles' button")
_t(__CLASS__ . '.SHOWMOREBUTTON', "Show 'more articles' button")
),
TextField::create(
'ShowMoreArticlesButtonText',
_t('ElementArticles.ShowMoreArticlesButtonText', "Show 'more articles' button text")
_t(__CLASS__ . '.SHOWMOREBUTTONTEXT', "Show 'more articles' button text")
)
->displayIf('ShowMoreArticlesButton')
->isChecked()
Expand Down
4 changes: 2 additions & 2 deletions src/Forms/ArticleFilterForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(RequestHandler $controller = null, $name = self::DEF
$fields->push(
DropdownField::create(
'type',
_t('Type.Singular', 'Type'),
_t('TheWebmen\Articles\Pages\ArticleTypePage.SINGULARNAME', 'Type'),
$controller->getTypes()->map('URLSegment', 'Title')->toArray()
)->setHasEmptyDefault(true)->setEmptyString('Choose a type')
);
Expand All @@ -33,7 +33,7 @@ public function __construct(RequestHandler $controller = null, $name = self::DEF
$fields->push(
CheckboxSetField::create(
'thema',
_t('Theme.Singular', 'Theme'),
_t('TheWebmen\Articles\Pages\ArticleThemePage.SINGULARNAME', 'Theme'),
$controller->getThemes()->map('URLSegment', 'Title')->toArray()
)
);
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function getCMSFields()

$fields->removeByName('ArticlesPageID');

$fields->renameField('Title', 'Name');
$fields->renameField('Title', _t(__CLASS__ . '.NAME', 'Name'));

$this->extend('onAfterUpdateCMSFields', $fields);

Expand Down
22 changes: 11 additions & 11 deletions src/Pages/ArticlePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function getCMSFields(): FieldList

$fields->insertAfter(
'URLSegment',
TextField::create('Subtitle', _t('Article.Subtitle', 'Article subtitle'))
TextField::create('Subtitle', _t(__CLASS__ . '.SUBTITLE', 'Subtitle'))
);

$fields->replaceField('Content', HTMLEditorField::create('Content'));
Expand All @@ -121,20 +121,20 @@ public function getCMSFields(): FieldList
'Subtitle',
FieldGroup::create(
[
TextField::create('ReadingTime', _t('Article.ReadingTime', 'Reading time (in min.)')),
DatetimeField::create('PublicationDate', _t('Article.Date.Publication', 'Publication date')),
DatetimeField::create('UpdatedDate', _t('Article.Date.Updated', 'Updated date')),
TextField::create('ReadingTime', _t(__CLASS__ . '.READINGTIME', 'Reading time (in min.)')),
DatetimeField::create('PublicationDate', _t(__CLASS__ . '.PUBLICATIONDATE', 'Publication date')),
DatetimeField::create('UpdatedDate', _t(__CLASS__ . '.UPDATEDATE', 'Update date')),
]
)
->setName('ArticleMetadata')
->setTitle(_t('Article.Metadata', 'Article metadata'))
->setTitle(_t(__CLASS__ . '.METADATA', 'Metadata'))
);

$fields->insertAfter(
'ArticleMetadata',
TagField::create(
'Themes',
_t('Theme.Plural', 'Themes'),
_t('TheWebmen\Articles\Pages\ArticleThemePage.PLURALNAME', 'Themes'),
ArticleThemePage::get()->filter('ParentID', $this->ParentID),
$this->Themes()
)->setCanCreate(false)
Expand All @@ -144,7 +144,7 @@ public function getCMSFields(): FieldList
'Themes',
TagField::create(
'Tags',
_t('Tag.Plural', 'Tags'),
_t('TheWebmen\Articles\Models\Tag.PLURALNAME', 'Tags'),
Tag::get()->filter(
[
'ArticlesPageID' => $this->ParentID,
Expand All @@ -158,7 +158,7 @@ public function getCMSFields(): FieldList
'Tags',
DropdownField::create(
'AuthorID',
_t('Author.Singular', 'Author'),
_t('TheWebmen\Articles\Models\Author.SINGULARNAME', 'Author'),
Author::get()->filter(
[
'ArticlesPageID' => $this->ParentID,
Expand All @@ -172,7 +172,7 @@ public function getCMSFields(): FieldList
'AuthorID',
DropdownField::create(
'TypeID',
_t('Type.Singular', 'Type'),
_t('TheWebmen\Articles\Pages\ArticleTypePage.SINGULARNAME', 'Type'),
ArticleTypePage::get()->filter(
[
'ParentID' => $this->ParentID
Expand All @@ -184,13 +184,13 @@ public function getCMSFields(): FieldList

$fields->insertAfter(
'TypeID',
HTMLEditorField::create('TeaserText', _t('Article.TeaserText', 'Teaser text'))
HTMLEditorField::create('TeaserText', _t(__CLASS__ . '.TEASERTEXT', 'Teaser text'))
->setRows(5)
);

$fields->insertAfter(
'TeaserText',
UploadField::create('Thumbnail', _t('Article.Thumbnail', 'Thumbnail'))
UploadField::create('Thumbnail', _t(__CLASS__ . '.THUMBNAIL', 'Thumbnail'))
->setFolderName('Thumbnails')
);

Expand Down
Loading

0 comments on commit 7c7aee8

Please sign in to comment.