<?php
|
namespace JVBase\registrar\config;
|
|
use JVBase\registrar\Registrar;
|
|
if (!defined('ABSPATH')) {
|
exit;
|
}
|
|
final class Feed extends Config {
|
protected array $single = [];
|
protected array $archive = [];
|
protected array $config = [];
|
protected string $slug;
|
|
public function __construct(string $slug) {
|
$this->slug = $slug;
|
$this->config = $this->defaultConfig();
|
}
|
|
public function defaultConfig():array
|
{
|
return [
|
'is_gallery' => false,
|
'icon' => Registrar::getInstance($this->slug)->getIcon(),
|
'content' => $this->slug,
|
// 'taxonomies' => Registrar::getInstance($this->slug)->registrar->taxonomies,
|
];
|
}
|
|
protected function allowedConfig():array
|
{
|
return ['is_gallery', 'content', 'context', 'taxonomies','icon','source','custom_order','images','fields'];
|
}
|
|
public function setGallery(bool $set = true):self
|
{
|
$this->config['is_gallery'] = $set;
|
return $this;
|
}
|
public function setIcon(string $icon):self
|
{
|
$this->config['icon'] = $icon;
|
return $this;
|
}
|
public function setCustomOrder(array $order):self
|
{
|
$this->config['custom_order'] = $order;
|
return $this;
|
}
|
public function getCustomOrder():array {
|
return $this->config['custom_order']??[];
|
}
|
public function setImages(string|array $images):self
|
{
|
$images = is_string($images) ? [$images] : $images;
|
$images = array_filter($images, function($imgField) {
|
return array_key_exists($imgField, Registrar::getInstance($this->slug)->getFields());
|
});
|
if (empty($images)) {
|
$images = ['post_thumbnail'];
|
}
|
$this->config['images'] = $images;
|
return $this;
|
}
|
public function setFields(array $fields):self
|
{
|
$fields = array_filter($fields, function($field){
|
return array_key_exists($field, Registrar::getInstance($this->slug)->getFields());
|
});
|
if (empty($fields)) {
|
$fields = ['post_title', 'post_date','post_excerpt'];
|
}
|
$this->config['fields'] = $fields;
|
return $this;
|
}
|
public function getConfig():array
|
{
|
return $this->config;
|
}
|
|
|
}
|