Skip to content

Commit

Permalink
(feat): implement setting for configuring a fileserver URL
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike van den Hoek committed Jan 12, 2024
1 parent 766dec8 commit a225813
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## Version 4.2

- Feat: implement setting for configuring a fileserver URL

## Version 4.1.5

- Feat: add publication date to the api response
Expand Down
11 changes: 6 additions & 5 deletions config/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@
/**
* Service Providers.
*/
'providers' => [
'providers' => [
/**
* Global providers.
*/
Yard\OpenWOO\OpenWOOServiceProvider::class,
Yard\OpenWOO\ElasticPress\ElasticPressServiceProvider::class,
Yard\OpenWOO\Metabox\MetaboxServiceProvider::class,
Yard\OpenWOO\Taxonomy\TaxonomyServiceProvider::class,

Yard\OpenWOO\Settings\SettingsServiceProvider::class,

/**
* Providers specific to the admin.
*/
'admin' => [
class_exists('\OWC\OpenPub\Base\Settings\SettingsPageOptions') ? Yard\OpenWOO\Admin\AdminServiceProvider::class : Yard\OpenWOO\Foundation\NullServiceProvider::class
class_exists('\OWC\OpenPub\Base\Settings\SettingsPageOptions') ? Yard\OpenWOO\Admin\AdminServiceProvider::class : Yard\OpenWOO\Foundation\NullServiceProvider::class,
],
'cli' => [
'cli' => [
],
]
],
];
2 changes: 1 addition & 1 deletion config/metaboxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@
[
'name' => __('URL Bijlage', OWO_LANGUAGE_DOMAIN),
'id' => 'woo_URL_Bijlage',
'type' => 'text',
'type' => 'text_url',
],
[
'name' => __('Bijlage', OWO_LANGUAGE_DOMAIN),
Expand Down
28 changes: 28 additions & 0 deletions config/settings_pages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

return [
'openwoo-base' => [
'id' => '_owc_openwoo_base_settings',
'title' => __('OpenWOO instellingen', 'openwoo'),
'object_types' => ['options-page'],
'option_key' => '_owc_openwoo_base_settings',
'tab_group' => 'openwoo-base',
'tab_title' => __('Algemeen', 'openwoo'),
'position' => 30,
'icon_url' => 'dashicons-admin-settings',
'fields' => [
'fileserver_title' => [
'name' => __('Fileserver', 'openwoo'),
'desc' => __('Een eigen implementatie in een plug-in of thema is vereist voor het gebruik van een fileserver, deze plug-in biedt deze instellingen pagina aan waarmee je instellingen kunt gebruiken op elke gewenste plek.', 'openwoo'),
'id' => 'openwoo_setting_fileserver_title',
'type' => 'title',
],
'fileserver_url' => [
'name' => __('Fileserver URL', 'openwoo'),
'desc' => __('URL met http(s)://', 'openwoo'),
'id' => 'openwoo_setting_file_server_url',
'type' => 'text',
],
],
],
];
4 changes: 2 additions & 2 deletions openwoo.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Plugin Name: Yard | OpenWOO
* Plugin URI: https://www.yard.nl/
* Description: Adds OpenWOO implementation
* Version: 4.1.5
* Version: 4.2
* Author: Yard | Digital Agency
* Author URI: https://www.yard.nl/
* License: GPL-3.0
Expand All @@ -30,7 +30,7 @@
define('OWO_LANGUAGE_DOMAIN', OWO_SLUG);
define('OWO_DIR', basename(__DIR__));
define('OWO_ROOT_PATH', __DIR__);
define('OWO_VERSION', '4.1.5');
define('OWO_VERSION', '4.2');

/**
* Manual loaded file: the autoloader.
Expand Down
30 changes: 30 additions & 0 deletions src/OpenWOO/Settings/Settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Yard\OpenWOO\Settings;

class Settings
{
/**
* Settings defined on settings page
*/
protected array $settings;

public function __construct(array $settings)
{
$this->settings = $settings;
}

public function getFileServerURL(): string
{
return $this->settings['_owc_openwoo_setting_file_server_url'] ?? '';
}

public static function make(): self
{
$defaultSettings = [
'_owc_openwoo_setting_file_server_url' => '',
];

return new static(wp_parse_args(\get_option('_owc_openwoo_base_settings'), $defaultSettings));
}
}
62 changes: 62 additions & 0 deletions src/OpenWOO/Settings/SettingsServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace Yard\OpenWOO\Settings;

use CMB2;
use Yard\OpenWOO\Foundation\ServiceProvider;

class SettingsServiceProvider extends ServiceProvider
{
const PREFIX = '_owc_';

public function register()
{
$this->plugin->loader->addAction('cmb2_admin_init', $this, 'registerSettingsPages', 10, 0);
}

public function registerSettingsPages(): void
{
$settingsPages = $this->plugin->config->get('settings_pages');

if (! is_array($settingsPages)) {
return;
}

foreach ($settingsPages as $page) {
if (! is_array($page)) {
continue;
}

$this->registerSettingsPage($page);
}
}

protected function registerSettingsPage(array $page): void
{
$fields = $page['fields'] ?? [];
unset($page['fields']); // Fields will be added later on.

$optionsPage = \new_cmb2_box($page);

if (empty($fields) || ! is_array($fields)) {
return;
}

$this->registerSettingsPageFields($optionsPage, $fields);
}

protected function registerSettingsPageFields(CMB2 $optionsPage, array $fields)
{
foreach ($fields as $field) {
if (! is_array($field)) {
continue;
}

if (isset($field['id'])) {
$field['id'] = self::PREFIX . $field['id'];
}

$optionsPage->add_field($field);
}
}
}

0 comments on commit a225813

Please sign in to comment.