data['title']; $date = $this->data['publish_today'] ? now() : now()->addDay(); $path = sprintf('%s/%s/%s', static::$section, $date->format('Y/m/d'), Str::slug($title)); $bundle = new Bundle($path, $this->disk); if ($bundle->exists()) { throw new BundleAlreadyExists( sprintf('A bundle already exists in %s', $path) ); } $bundle->markdown()->set(''); $bundle->metadata()->setMany([ 'title' => $title, 'date' => $date->toIso8601String(), ]); $bundle->save(); return $path; } /** * Return a boolean value indicating if the creator can actually make the * bundle using known data. */ public function canCreateBundle(): bool { return array_key_exists('publish_today', $this->data) && !empty($this->data['title']); } /** * Return an array describing what kind of data the creator needs in * addition to the one it already has */ public function formSpecs(): ?array { $specs = []; if (empty($this->data['title'])) { $specs['title'] = fn () => text('Article title', '', '', true); } $today = now()->format('d/m/Y'); $tomorrow = now()->addDay()->format('d/m/Y'); if (!array_key_exists('publish_today', $this->data)) { $specs['publish_today'] = fn () => confirm( 'Do you want to publish today?', true, sprintf('%s (%s)', 'Publish today', $today), sprintf('%s (%s)', 'Publish tomorrow', $tomorrow) ); } return $specs; } /** * Return a boolean value indicating if this creator in particular can * create bundles for specified section */ public static function handles(string $section, ?array $data = []): bool { return $section === static::$section; } }