/** * Fired just before saving the entry. * * @param EntryInterface|PostInterface $entry */ public function creating(EntryInterface $entry) { if (!$entry->getStrId()) { $entry->setAttribute('str_id', str_random()); } parent::creating($entry); }
/** * Handle the command. */ public function handle() { if ($this->entry->isTranslatable() && (!$this->entry->isTrashable() || $this->entry->isForceDeleting())) { foreach ($this->entry->getTranslations() as $translation) { $translation->delete(); } } }
/** * Fired before deleting the file. * * @param EntryInterface|FileInterface $entry * @return bool */ public function deleting(EntryInterface $entry) { /** * Make sure the resource exists * and is deleted successfully. */ if ($resource = $entry->resource()) { return $resource->delete(); } return true; }
/** * Fired after deleting the file. * * @param EntryInterface|FileInterface $entry */ public function deleted(EntryInterface $entry) { /** * Make sure the resource exists * and is deleted successfully. */ if ($entry->isForceDeleting() && ($resource = $entry->resource())) { $resource->delete(); } parent::deleted($entry); }
/** * Fire just before saving a folder. * * @param EntryInterface|FolderInterface $entry */ public function deleting(EntryInterface $entry) { $this->manager->deleteDir($entry->diskPath()); // Delete contained files. foreach ($entry->getFiles() as $file) { $this->files->delete($file); } // Delete contained folders. foreach ($entry->getChildren() as $folder) { $this->folders->delete($folder); } }
/** * Make a route. * * @param $route * @param array $parameters * @return mixed|null|string */ public function make($route, array $parameters = []) { if (method_exists($this, $method = $this->str->camel(str_replace('.', '_', $route)))) { $parameters['parameters'] = $parameters; return $this->container->call([$this, $method], $parameters); } if (!str_contains($route, '.') && ($stream = $this->entry->getStreamSlug())) { $route = "{$stream}.{$route}"; } if (!str_contains($route, '::') && ($namespace = $this->locator->locate($this->entry))) { $route = "{$namespace}::{$route}"; } return $this->url->make($route, $this->entry, $parameters); }
/** * When accessing a property of a decorated entry * object first check to see if the key represents * a streams field. If it does then return the field * type's presenter object. Otherwise handle normally. * * @param $key * @return mixed */ public function __get($key) { if ($assignment = $this->object->getAssignment($key)) { $type = $assignment->getFieldType(); if ($assignment->isTranslatable() && ($locale = config('app.locale'))) { $entry = $this->object->translateOrDefault($locale); $type->setLocale($locale); } else { $entry = $this->object; } $type->setEntry($entry); if (method_exists($type, 'getRelation')) { return $type->decorate($entry->getRelationValue(camel_case($key))); } $type->setValue($entry->getFieldValue($key)); return $type->getPresenter(); } return $this->__getDecorator()->decorate(parent::__get($key)); }
/** * Run after a record has been restored. * * @param EntryInterface $entry */ public function restored(EntryInterface $entry) { $entry->flushCache(); $entry->fireFieldTypeEvents('entry_restored'); $this->events->fire(new EntryWasRestored($entry)); }
/** * Set the entry. * * @param EntryInterface $entry * @param $config */ protected function setEntry(EntryInterface $entry, &$config) { $config['extra']['entry_id'] = $entry->getId(); $config['extra']['entry_type'] = get_class($entry); }