| | |
| | | * @var bool Whether to make this a calendar type (example: events) |
| | | */ |
| | | protected bool $is_calendar = false; |
| | | protected ?MakeCalendarType $isCalendarHandler = null; |
| | | |
| | | /** |
| | | * @var bool Whether this is a before/after post type |
| | | */ |
| | |
| | | |
| | | /** Helpers **/ |
| | | protected MakeCalendarType|false $calendar = false; |
| | | protected bool $hasIntegrations = true; |
| | | protected array $integrationConfigs = []; |
| | | protected array $integrationFields = []; |
| | | protected MakeTrackChanges $trackChanges; |
| | |
| | | $this->setFields(); |
| | | |
| | | add_action('init', [$this, 'register'], 2); |
| | | add_filter('jvbDashboardPage', [$this, 'renderDashPage'], 10, 3); |
| | | if ($this->slug !== 'dash') { |
| | | add_action(BASE.'dashboard_page_'.$this->slug, [$this, 'renderDashPage'], 10, 2); |
| | | } |
| | | |
| | | } |
| | | |
| | | public static function maybeExcludeSingles(array $IDs):array |
| | |
| | | } |
| | | public function hasIntegration(string $integration):bool |
| | | { |
| | | if (!$this->hasIntegrations) { |
| | | return false; |
| | | } |
| | | return array_key_exists($integration, $this->integrationConfigs); |
| | | } |
| | | public function hasAnyIntegrations(array $integrations = []):bool |
| | | { |
| | | if (!$this->hasIntegrations) { |
| | | return false; |
| | | } |
| | | |
| | | if (empty($integrations)) { |
| | | $integrations = array_keys($this->integrationConfigs); |
| | | return !empty($integrations); |
| | |
| | | foreach ($flags as $flag) { |
| | | $this->$flag = true; |
| | | switch ($flag) { |
| | | case 'is_calendar': |
| | | $this->calendar = new MakeCalendarType($this->slug, $this); |
| | | break; |
| | | case 'is_content': |
| | | add_action('init', [$this, 'setupContent'], 20); |
| | | break; |
| | |
| | | public static function withIntegration(string $integration, ?string $type = null):array |
| | | { |
| | | self::ensureInstanced(); |
| | | |
| | | if (!Site::has($integration)) { |
| | | Site::getInstance(); |
| | | if (!Site::hasIntegration($integration)) { |
| | | error_log('[Registrar]::withIntegration Integration not available to fetch: '.$integration); |
| | | return []; |
| | | } |
| | |
| | | if (!is_null($type) && $inst->type !== $type) { |
| | | return false; |
| | | } |
| | | return array_key_exists($integration, $this->integrationConfigs); |
| | | return array_key_exists($integration, $inst->integrationConfigs); |
| | | })); |
| | | } |
| | | |
| | |
| | | $this->isTimelineHandler = new MakeTimelineType($this->slug); |
| | | $this->registrar->hierarchical = true; |
| | | } |
| | | if ($this->is_calendar) { |
| | | $this->isCalendarHandler = new MakeCalendarType($this->slug, $this); |
| | | } |
| | | |
| | | if (!is_null($this->rewrite_taxonomy)) { |
| | | $this->registrar->addTaxonomyRewrite($this->rewrite_taxonomy); |
| | |
| | | return $this; |
| | | } |
| | | |
| | | public function renderDashPage(string $content, string $page, string $slug):string |
| | | public function renderDashPage(string $page, string $slug):void |
| | | { |
| | | if ($slug === $this->slug) { |
| | | ob_start(); |
| | | $crud = new CRUD($slug); |
| | | $crud->render(); |
| | | return ob_get_clean(); |
| | | } |
| | | |
| | | return $content; |
| | | $crud = new CRUD($slug); |
| | | $crud->render(); |
| | | } |
| | | |
| | | public function setupContent():void |
| | |
| | | |
| | | return [$images,$fields]; |
| | | } |
| | | |
| | | public function setHasIntegrations(bool $has = true):void |
| | | { |
| | | $this->hasIntegrations = $has; |
| | | } |
| | | } |