Skip to content

Commit

Permalink
(feat): PDC item table of contents, enabled by setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike van den Hoek authored and mvdhoek1 committed Sep 30, 2024
1 parent c26ea77 commit 314b5b8
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Feat

- Theme tiles, enabled by setting.
- PDC item table of contents, enabled by setting.

## Version [3.12.2] (2024-08-19)

Expand Down
3 changes: 2 additions & 1 deletion config/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
'escape_element' => OWC\PDC\Base\RestAPI\ItemFields\EscapeElementField::class,
'seopress' => OWC\PDC\Base\RestAPI\ItemFields\SeoPress::class,
'yoast' => OWC\PDC\Base\RestAPI\ItemFields\Yoast::class,
'hide_feedback_form' => OWC\PDC\Base\RestAPI\SharedFields\HideFeedbackForm::class
'hide_feedback_form' => OWC\PDC\Base\RestAPI\SharedFields\HideFeedbackForm::class,
'table_of_contents_is_active' => OWC\PDC\Base\RestAPI\ItemFields\TableOfContentsField::class
],
],
'subthema' => [
Expand Down
6 changes: 6 additions & 0 deletions config/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@
'desc' => __('Enable theme tiles.', 'pdc-base'),
'id' => 'setting_pdc_use_theme_tiles',
'type' => 'checkbox',
],
'pdc_use_table_of_contents' => [
'name' => __('Table of contents', 'pdc-base'),
'desc' => __('Enable use of table of contents.', 'pdc-base'),
'id' => 'setting_pdc_use_table_of_contents',
'type' => 'checkbox',
],
'upl_heading' => [
'type' => 'heading',
Expand Down
22 changes: 22 additions & 0 deletions config/table_of_contents_metabox.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

return [
'table_of_contents' => [
'id' => 'table_of_contents',
'title' => __('Table of contents', 'pdc-base'),
'post_types' => ['pdc-item'],
'context' => 'normal',
'priority' => 'high',
'autosave' => true,
'fields' => [
'table_of_contents' => [
[
'name' => __('Table of contents', 'pdc-base'),
'desc' => __('Use this option if you want to use a table of contents', 'pdc-base'),
'id' => 'pdc_use_table_of_contents',
'type' => 'checkbox',
]
],
]
]
];
Binary file modified languages/pdc-base-nl_NL.mo
Binary file not shown.
25 changes: 19 additions & 6 deletions languages/pdc-base-nl_NL.po
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,15 @@ msgstr "Alternatieve titel"

#: config/metaboxes.php:19
msgid "Use this option if you want to use an alternative title"
msgstr "Gebruik deze mogelijkheid als de website een alternatieve titel gebruikt"
msgstr "Gebruik deze optie als de website een alternatieve titel gebruikt"

#: config/metaboxes.php:24
msgid "Synonyms"
msgstr "Synoniemen"

#: config/metaboxes.php:25
msgid "Use this option to add an comma separated list of synonyms or related terms"
msgstr "Gebruik deze mogelijkheid om een komma gescheiden lijst van synoniemen of gerelateerde termen mee te geven"
msgstr "Gebruik deze optie om een komma gescheiden lijst van synoniemen of gerelateerde termen mee te geven"

#: config/metaboxes.php:31
msgid "Is this product active yes/no"
Expand Down Expand Up @@ -830,18 +830,22 @@ msgstr "Thema tegels"

#: config/settings.php:87
msgid "Enable theme tiles."
msgstr "Gebruik thema tegels"
msgstr "Gebruik thema tegels."

#: config/settings.php:93
msgid "Enable use of table of contents."
msgstr "Gebruik inhoudsopgaven."

#: config/settings.php:99
msgid "The Uniform Product list of names (upl)"
msgstr "De Uniforme Productnamenlijst (UPL)"

#: config/settings.php:96
#: config/settings.php:102
#: config/theme_tiles_metabox.php:27
msgid "URL"
msgstr "URL"

#: config/settings.php:97
#: config/settings.php:103
msgid "URL used for retrieving UPL terms."
msgstr "URL om de UPL termen op te halen."

Expand Down Expand Up @@ -965,10 +969,19 @@ msgstr "Tegels"
msgid "Add new tile"
msgstr "Voeg nieuwe tegel toe"

#: config/theme_tiles_metabox.php:
#: config/theme_tiles_metabox.php:22
msgid "Title"
msgstr "Titel"

#: config/table_of_contents_metabox.php:6
#: config/table_of_contents_metabox.php:14
msgid "Table of contents"
msgstr "Inhoudsopgave"

#: config/table_of_contents_metabox.php:15
msgid "Use this option if you want to use a table of contents"
msgstr "Gebruik deze optie als er een inhoudsopgave getoond moet worden op de website"

#: src/Base/Foundation/DependencyChecker.php:70
msgid "The following plugins are required to use the PDC:"
msgstr "De volgende plugins zijn vereist om gebruik te maken van de PDC:"
Expand Down
20 changes: 17 additions & 3 deletions languages/pdc-base.pot
Original file line number Diff line number Diff line change
Expand Up @@ -862,15 +862,19 @@ msgid "Enable theme tiles."
msgstr ""

#: config/settings.php:93
msgid "Enable use of table of contents."
msgstr ""

#: config/settings.php:99
msgid "The Uniform Product list of names (upl)"
msgstr ""

#: config/settings.php:96
#: config/settings.php:102
#: config/theme_tiles_metabox.php:27
msgid "URL"
msgstr ""

#: config/settings.php:97
#: config/settings.php:103
msgid "URL used for retrieving UPL terms."
msgstr ""

Expand Down Expand Up @@ -996,10 +1000,20 @@ msgstr ""
msgid "Add new tile"
msgstr ""

#: config/theme_tiles_metabox.php:
#: config/theme_tiles_metabox.php:22
msgid "Title"
msgstr ""

#: config/settings.php:92
#: config/table_of_contents_metabox.php:6
#: config/table_of_contents_metabox.php:14
msgid "Table of contents"
msgstr ""

#: config/table_of_contents_metabox.php:15
msgid "Use this option if you want to use a table of contents"
msgstr ""

#: src/Base/Foundation/DependencyChecker.php:70
msgid "The following plugins are required to use the PDC:"
msgstr ""
Expand Down
9 changes: 9 additions & 0 deletions src/Base/Metabox/MetaboxServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public function registerMetaboxes(array $rwmbMetaboxes): array
$configMetaboxes = $this->getTilesMetabox($configMetaboxes);
}

if ($this->plugin->settings->useTableOfContents()) {
$configMetaboxes = $this->getTableOfContentsMetabox($configMetaboxes);
}

if ($this->plugin->settings->useFeedbackForm()) {
$configMetaboxes = $this->getFeedbackFormMetabox($configMetaboxes);
}
Expand Down Expand Up @@ -87,6 +91,11 @@ protected function getTilesMetabox(array $configMetaboxes): array
return array_merge($configMetaboxes, $this->plugin->config->get('theme_tiles_metabox'));
}

protected function getTableOfContentsMetabox(array $configMetaboxes): array
{
return array_merge($configMetaboxes, $this->plugin->config->get('table_of_contents_metabox'));
}

protected function getFeedbackFormMetabox(array $configMetaboxes): array
{
$feedbackFormMetabox = $this->plugin->config->get('hide_feedback_form_metabox');
Expand Down
11 changes: 10 additions & 1 deletion src/Base/Models/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,16 @@ public function getMeta(string $value, $default = '', $single = true, $prefix =

public function getEscapeElement(): bool
{
return $this->getMeta('escape_element_active', '0', true, '_owc_');
$value = $this->getMeta('escape_element_active', '0', true, '_owc_');

return boolval($value);
}

public function useTableOfContents(): bool
{
$value = $this->getMeta('pdc_use_table_of_contents', '0', true, '_owc_');

return boolval($value);
}

/**
Expand Down
30 changes: 30 additions & 0 deletions src/Base/RestAPI/ItemFields/TableOfContentsField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* Adds boolean field to the output which indicates if the item uses table of contents.
*/

namespace OWC\PDC\Base\RestAPI\ItemFields;

use OWC\PDC\Base\Models\Item;
use OWC\PDC\Base\Support\CreatesFields;
use WP_Post;

class TableOfContentsField extends CreatesFields
{
/**
* The condition for the creator.
*/
protected function condition(): callable
{
return function () {
return $this->plugin->settings->useTableOfContents();
};
}

public function create(WP_Post $post): bool
{
$itemModel = new Item($post->to_array());

return $itemModel->useTableOfContents();
}
}
10 changes: 9 additions & 1 deletion src/Base/Settings/SettingsPageOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ public function useThemeTiles(): bool
return boolval($setting);
}

public function useTableOfContents(): bool
{
$setting = $this->settings['_owc_setting_pdc_use_table_of_contents'] ?? false;

return boolval($setting);
}

/**
* URL used for retrieving UPL terms.
*/
Expand All @@ -150,7 +157,8 @@ public static function make(): self
'_owc_setting_pdc_enable_show_on' => 0,
'_owc_setting_pdc_use_feedback_form' => 0,
'_owc_upl_terms_url' => '',
'_owc_setting_pdc_use_theme_tiles' => 0
'_owc_setting_pdc_use_theme_tiles' => 0,
'_owc_setting_pdc_use_table_of_contents' => 0,
];

return new static(wp_parse_args(get_option('_owc_pdc_base_settings'), $defaultSettings));
Expand Down

0 comments on commit 314b5b8

Please sign in to comment.