Skip to content
This repository has been archived by the owner on May 11, 2023. It is now read-only.

Commit

Permalink
Hide locale, category, related posts columns from index
Browse files Browse the repository at this point in the history
  • Loading branch information
eleriojavere committed Dec 9, 2020
1 parent 8005a92 commit 0f75945
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
8 changes: 8 additions & 0 deletions config/nova-blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,12 @@
'include_froala_texteditor_option' => false,

'include_related_posts_feature' => false,

'hide_category_column_from_index' => false,

'hide_related_posts_column_from_index' => false,

'hide_locale_column_from_index' => false,


];
32 changes: 24 additions & 8 deletions src/Nova/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public function fields(Request $request)
});

$relatedPosts = RelatedPost::where('post_id', $this->id)->pluck('related_post_id');
$showCategoryColumnInIndex = config('nova-blog.hide_category_selector') === true ? null : BelongsTo::make('Category', 'category', 'OptimistDigital\NovaBlog\Nova\Category')->nullable();
$hideCategoryColumnInIndex = config('nova-blog.hide_category_selector') === true ? null : BelongsTo::make('Category', 'category', 'OptimistDigital\NovaBlog\Nova\Category')->nullable()->hideFromIndex();

$postContent = Flexible::make('Post content', 'post_content')->hideFromIndex()
->addLayout('Text section', 'text', [
Expand Down Expand Up @@ -94,35 +96,49 @@ public function fields(Request $request)
DateTime::make('Published at', 'published_at')->rules('required'),
Textarea::make('Post introduction', 'post_introduction'),
config('nova-blog.include_featured_image') === true ? Image::make('Featured image', 'featured_image') : null,
config('nova-blog.hide_category_selector') === true ? null : BelongsTo::make('Category', 'category', 'OptimistDigital\NovaBlog\Nova\Category')->nullable(),

(config('nova-blog.hide_category_column_from_index') === true) ? $hideCategoryColumnInIndex : $showCategoryColumnInIndex,

$postContent,
config('nova-blog.include_related_posts_feature') === true ?
config('nova-blog.include_related_posts_feature') === true && config('nova-blog.hide_related_posts_column_from_index') === false ?
Multiselect
::make('Related posts', 'related_posts')
->options($relatedPostOptions)
->withMeta(['value' => $relatedPosts])
: null,


config('nova-blog.include_related_posts_feature') === true && config('nova-blog.hide_related_posts_column_from_index') === true ?
Multiselect
::make('Related posts', 'related_posts')
->options($relatedPostOptions)
->withMeta(['value' => $relatedPosts])
->hideFromIndex()
: null,
];

if (NovaBlog::hasNovaLang()) {
$fields[] = \OptimistDigital\NovaLang\NovaLangField::make('Locale', 'locale', 'locale_parent_id')->onlyOnForms();
config('nova-blog.hide_locale_column_from_index') === true ? $fields[] = \OptimistDigital\NovaLang\NovaLangField::make('Locale', 'locale', 'locale_parent_id')->onlyOnForms()->hideFromIndex() :
$fields[] = \OptimistDigital\NovaLang\NovaLangField::make('Locale', 'locale', 'locale_parent_id')->onlyOnForms();
} else {
$fields[] = LocaleField::make('Locale', 'locale', 'locale_parent_id')
config('nova-blog.hide_locale_column_from_index') === true ? $fields[] = LocaleField::make('Locale', 'locale', 'locale_parent_id')
->locales($locales)
->onlyOnForms()->hideFromIndex() :
$fields[] = LocaleField::make('Locale', 'locale', 'locale_parent_id')
->locales($locales)
->onlyOnForms();
}

if (count($locales) > 1) {
$fields[] = LocaleField::make('Locale', 'locale', 'locale_parent_id')
config('nova-blog.hide_locale_column_from_index') === true ? $fields[] = LocaleField::make('Locale', 'locale', 'locale_parent_id')
->locales($locales)
->exceptOnForms()
->hideFromIndex() :
$fields[] = LocaleField::make('Locale', 'locale', 'locale_parent_id')
->locales($locales)
->exceptOnForms()
->maxLocalesOnIndex(3);
} else if ($hasManyDifferentLocales) {
$fields[] = Text::make('Locale', 'locale')->exceptOnForms();
config('nova-blog.hide_locale_column_from_index') === true ? $fields[] = Text::make('Locale', 'locale')->exceptOnForms()->hideFromIndex() :
$fields[] = Text::make('Locale', 'locale')->exceptOnForms();
}

if (NovaBlog::hasNovaDrafts()) {
Expand Down

0 comments on commit 0f75945

Please sign in to comment.