public function onBeforeWrite() { parent::onBeforeWrite(); if (!$this->Content) { $this->Content = '<p>$List</p>'; } }
/** * Iterate through all the modules and add their content to the parent page, so it can be found in searches. */ public function onBeforeWrite() { $pageClass = get_called_class(); // Behaviour can be disabled via the config $writeContent = Config::inst()->get($pageClass, 'write_content'); // If a custom config doesn't exist, check ModularPage if (is_null($writeContent)) { $writeContent = Config::inst()->get('ModularPage', 'write_content'); } if ($writeContent) { $classes = ClassInfo::subclassesFor(__CLASS__); // Only run this code if we're on a valid instance of this class. // Fixes bug when changaing page type via the CMS (e.g. ModularPage -> Page) if (in_array($this->ClassName, $classes)) { if ($this->Modules()->Count()) { $searchBody = ''; foreach ($this->Modules() as $module) { $searchBody .= $module->getSearchBody() . PHP_EOL; } $this->Content = $searchBody; } } } parent::onBeforeWrite(); }
/** * If no publish date is set, set the date to now. **/ public function onBeforeWrite() { parent::onBeforeWrite(); if (!$this->PublishDate) { $this->setCastedField("PublishDate", time()); } }
function onBeforeWrite() { parent::onBeforeWrite(); if ($this->ID) { $this->RootFolder()->Title = $this->Title; } }
public function onBeforeWrite() { if (!$this->ID) { $this->isInsert = true; } parent::onBeforeWrite(); }
/** * Overwrites default behaviour onBeforeWrite * * This method sets the page name based on the selected MovieTitle. If no movie title exists, * it will retain the existing page title (and navigation labels). * It clears the URL Segment variable as the SiteTree::onBeforeWrite will determine a new url-segment * based on the new page tile (which is the movie title). */ protected function onBeforeWrite() { if ($this->MovieTitle) { $this->Title = $this->MovieTitle; $this->URLSegment = ''; } parent::onBeforeWrite(); }
public function onBeforeWrite() { parent::onBeforeWrite(); $parent = $this->Parent(); if ($parent && $parent instanceof SummitPage && $parent->SummitID > 0) { $this->SummitID = $parent->SummitID; } }
function onBeforeWrite() { // Move to Photo Gallery Holder if created under something else if ($this->Parent()->ClassName != "PhotoGalleryHolder" && PhotoGalleryHolder::get()->count() > 0) { $this->ParentID = PhotoGalleryHolder::get()->first()->ID; } parent::onBeforeWrite(); }
public function onBeforeWrite() { parent::onBeforeWrite(); // set the filing mode, now that it's being obsolete if ($this->AutoFiling && !$this->FilingMode) { $this->FilingMode = 'day'; $this->AutoFiling = false; } }
/** * Set firstWrite flag if this is the first time this Product is written. * * @see SiteTree::onBeforeWrite() * @see Product::onAfterWrite() */ public function onBeforeWrite() { parent::onBeforeWrite(); if (!$this->ID) { $this->firstWrite = true; } //Save in base currency $shopConfig = ShopConfig::current_shop_config(); $this->Currency = $shopConfig->BaseCurrency; }
/** * Creates a report template instance if one does not exist. */ protected function onBeforeWrite() { parent::onBeforeWrite(); if (!$this->ReportTemplateID && $this->ReportType && ClassInfo::exists($this->ReportType)) { $template = Object::create($this->ReportType); $template->Title = $this->Title; $template->write(); $this->ReportTemplateID = $template->ID; } }
/** * When saving, check to see whether we should delete the * listing source ID */ public function onBeforeWrite() { parent::onBeforeWrite(); if (!$this->ID) { $this->Content = '$Listing'; } if ($this->ClearSource) { $this->ClearSource = false; $this->ListingSourceID = 0; } }
/** * Make sure Geonetwork url ends with an /. */ function onBeforeWrite() { parent::onBeforeWrite(); $geoUrl = $this->GeonetworkBaseURL; if (strlen($geoUrl) > 1) { $geoUrlLen = strlen($geoUrl) - 1; if ($geoUrl[$geoUrlLen] != '/') { $this->GeonetworkBaseURL .= '/'; } } }
/** * The "default" structure used for this report when auto generating etc */ public function onBeforeWrite() { parent::onBeforeWrite(); if (!$this->ReportTemplateID && $this->ReportType && ClassInfo::exists($this->ReportType)) { $template = Object::create($this->ReportType); // create the template first. This is what all actual reports are based on when they're generated, either // automatically or by the 'generate' button $template->Title = $this->Title . ' Preview'; $template->write(); $this->ReportTemplateID = $template->ID; } }
/** * We have to change it to copy all the content from the original page first. */ function onBeforeWrite() { // Don't do this stuff when we're publishing if (!$this->extension_instances['Versioned']->migratingVersion) { if (isset($this->changed['CopyContentFromID']) && $this->changed['CopyContentFromID'] && $this->CopyContentFromID != 0 && $this instanceof VirtualPage) { $source = DataObject::get_one("SiteTree", sprintf('`SiteTree`.`ID` = %d', $this->CopyContentFromID)); $this->copyFrom($source); $this->URLSegment = $source->URLSegment . '-' . $this->ID; } } parent::onBeforeWrite(); }
/** * Regenerate the URLSegment and MenuTitle based off the title */ protected function onBeforeWrite() { parent::onBeforeWrite(); $this->MenuTitle = $this->Title; $this->URLSegment = $this->generateURLSegment($this->Title); $count = 2; while (!$this->validURLSegment()) { $this->URLSegment = preg_replace('/-[0-9]+$/', null, $this->URLSegment) . '-' . $count; $count++; } $this->syncLinkTracking(); }
function onBeforeWrite() { // Change MenuTitle, so date appears in CMS SiteTree $this->MenuTitle = $this->Date . ": " . $this->Title; // Move to News holder if created under something else if ($this->Parent()->ClassName != "NewsHolder") { $this->ParentID = NewsHolder::get()->first()->ID; } // Add Today's Date if None if (!$this->Date) { $this->Date = date('Y-m-d'); } parent::onBeforeWrite(); }
public function onBeforeWrite() { parent::onBeforeWrite(); if ($contentItems = @json_decode($this->WidgetifyContent)) { $rawContent = ''; foreach ($contentItems as $contentItem) { if (isset($contentItem->WidgetId)) { if ($contentItem->WidgetId == '_DYNAMIC_') { $rawContent .= $contentItem->DynamicContent . "\r\n"; } } } $this->WidgetifyContentRaw = $rawContent; } }
/** * Before writing, convert any page links to appropriate * new, non-published, pages * * @see sapphire/core/model/SiteTree#onBeforeWrite() */ protected function onBeforeWrite() { parent::onBeforeWrite(); // Changes in 2.4 mean that $this->Content can now become polluted with UTF-8 HTML entitised garbage // we'll leave this legacy conversion in for now? $this->Content = str_replace(' ', '', $this->Content); $formatter = $this->getFormatter(); $formatter->analyseSavedContent($this); // set a lock expiry in the past if there's not one already set if (!$this->WikiLockExpiry) { $this->WikiLockExpiry = date('Y-m-d H:i:s'); } // Make sure to set the last editor to the current user if (Member::currentUser()) { $this->WikiLastEditor = Member::currentUser()->Email; } }
public function onBeforeWrite() { parent::onBeforeWrite(); // Make sure a valid date range is entered if (DateTime::createFromFormat('Y-m-d', $this->StartDate) > DateTime::createFromFormat('Y-m-d', $this->EndDate)) { throw new ValidationException("End date cannot occur before start date"); } // Make sure something is set... if ($this->ShortDescription === "") { $this->ShortDescription = "(No description set)"; } // Write the ics file for the event $service = new IcsGenerator($this->Title); $service->generateEventList(null, $this->ID); // Attach the file to this page $this->CalFileID = $service->getFileObject()->ID; $this->CalFileURL = $service->getFileObject()->getURL(); }
public function onBeforeWrite() { parent::onBeforeWrite(); $imageAdded = false; if ($this->AutomaticallyIncludedFolderID) { debug::log("A"); if ($folder = Folder::get()->byID($this->AutomaticallyIncludedFolderID)) { if ($files = Image::get()->filter("ParentID", $folder->ID)) { foreach ($files as $file) { if (ImageGalleryEntry::get()->filter(array("ImageID" => $file->ID, "ParentID" => $this->ID))->count()) { //do nothing //debug::log("already exists"); } else { $ImageGalleryEntry = new ImageGalleryEntry(); $ImageGalleryEntry->Title = $file->Title; $ImageGalleryEntry->ImageID = $file->ID; $ImageGalleryEntry->ParentID = $this->ID; $ImageGalleryEntry->write(); $imageAdded = true; //debug::log("writing"); } } } else { //debug::log("D"); } } else { //debug::log("C"); } } else { //debug::log("B"); } if ($ImageGalleryEntries = ImageGalleryEntry::get()->filter(array("ParentID" => $this->ID))) { foreach ($ImageGalleryEntries as $ImageGalleryEntry) { $image = Image::get()->filter(array("ID" => $ImageGalleryEntry->ImageID))->exclude(array("Title" => $ImageGalleryEntry->Title))->First(); if ($image) { $image->Title = $image->Name = $ImageGalleryEntry->Title; $image->write(); } } } if ($imageAdded) { //LeftAndMain::force_reload(); } }
/** * When the article is saved, and this article's section dictates that it * needs to be filed, then do so */ public function onBeforeWrite() { parent::onBeforeWrite(); // dummy initial date if (!$this->OriginalPublishedDate) { // @TODO Fix this to be correctly localized!! $this->OriginalPublishedDate = date('Y-m-d 12:00:00'); } $parent = $this->Parent(); // just in case we've been moved, update our section $section = $this->findSection(); $this->NewsSectionID = $section->ID; $newlyCreated = $section->ID == $parent->ID; $changedPublishDate = $this->isChanged('OriginalPublishedDate', 2); if (($changedPublishDate || $newlyCreated) && ($section->AutoFiling || $section->FilingMode)) { if (!$this->Created) { $this->Created = date('Y-m-d H:i:s'); } $pp = $this->PartitionParent(); if ($pp->ID != $this->ParentID) { $this->ParentID = $pp->ID; } } }
/** * Apply the parent holder media type and update any respective media type attributes. */ public function onBeforeWrite() { parent::onBeforeWrite(); // Set the default media page date. if (is_null($this->Date)) { $this->Date = date('Y-m-d'); } // Confirm that the external link exists. if ($this->ExternalLink) { if (stripos($this->ExternalLink, 'http') === false) { $this->ExternalLink = 'http://' . $this->ExternalLink; } $file_headers = @get_headers($this->ExternalLink); if (!$file_headers || strripos($file_headers[0], '404 Not Found')) { $this->ExternalLink = null; } } // Apply the changes from each media type attribute. foreach ($this->record as $name => $value) { if (strrpos($name, 'MediaAttribute')) { $ID = substr($name, 0, strpos($name, '_')); $attribute = MediaAttribute::get_by_id('MediaAttribute', $ID); $attribute->Content = $value; $attribute->write(); } } // Apply the parent holder media type. $parent = $this->getParent(); if ($parent) { $type = $parent->MediaType(); if ($type->exists()) { $this->MediaTypeID = $type->ID; $type = $type->Title; } else { $existing = MediaType::get_one('MediaType'); $parent->MediaTypeID = $existing->ID; $parent->write(); $this->MediaTypeID = $existing->ID; $type = $existing->Title; } // Merge the default and custom default media types and their respective attributes. $temporary = array(); foreach (self::$custom_defaults as $default => $attributes) { if (isset(self::$page_defaults[$default])) { self::$page_defaults[$default] = array_unique(array_merge(self::$page_defaults[$default], $attributes)); } else { $temporary[$default] = $attributes; } } $defaults = array_merge(self::$page_defaults, $temporary); // Retrieve existing attributes for the respective media type. $attributes = MediaAttribute::get()->innerJoin('MediaPage', 'MediaAttribute.MediaPageID = MediaPage.ID')->innerJoin('MediaType', 'MediaPage.MediaTypeID = MediaType.ID')->where(array('MediaType.Title = ?' => $type, 'MediaAttribute.LinkID = ?' => -1)); // Apply existing attributes to a new media page. if (!$this->MediaAttributes()->exists()) { if ($attributes->exists()) { foreach ($attributes as $attribute) { // Create a new attribute for each one found. $new = MediaAttribute::create(); $new->OriginalTitle = $attribute->OriginalTitle; $new->Title = $attribute->Title; $new->LinkID = $attribute->ID; $new->MediaPageID = $this->ID; $this->MediaAttributes()->add($new); $new->write(); } } else { if (isset($defaults[$type])) { foreach ($defaults[$type] as $attribute) { $new = MediaAttribute::create(); $new->Title = $attribute; $new->LinkID = -1; $new->MediaPageID = $this->ID; $this->MediaAttributes()->add($new); $new->write(); } } } } else { // Determine whether there are new attributes for this media page. if ($attributes->exists() && isset($defaults[$type])) { $defaults = $defaults[$type]; foreach ($attributes as $attribute) { $title = $attribute->OriginalTitle; foreach ($defaults as $index => $default) { if ($title === $default) { // This attribute already exists. unset($defaults[$index]); // Determine whether this media page requires the attribute. if (!$this->MediaAttributes()->filter('OriginalTitle', $title)->exists()) { // Create a new attribute. $new = MediaAttribute::create(); $new->OriginalTitle = $title; $new->Title = $attribute->Title; $new->LinkID = $attribute->ID; $new->MediaPageID = $this->ID; $this->MediaAttributes()->add($new); $new->write(); } break; } } } if (count($defaults)) { // Create a new attribute for the remaining defaults. foreach ($defaults as $attribute) { $new = MediaAttribute::create(); $new->Title = $attribute; $new->LinkID = -1; $new->MediaPageID = $this->ID; $this->MediaAttributes()->add($new); $new->write(); } } } } } }
function onBeforeWrite() { parent::onBeforeWrite(); $parentFolderID = $this->ParentFolderID; if ($parentFolderID) { $this->ParentID = $parentFolderID; } // FIXME $this->Dirty = true; }
public function onBeforeWrite() { // If the user has changed recursion types, we need to wipe out all // the empty fields that may result from resetting the TableField. if ($empties = DataObject::get($this->getDateTimeClass(), "StartDate IS NULL")) { foreach ($empties as $empty) { $empty->delete(); } } parent::onBeforeWrite(); }
/** * {@inheritdoc} */ protected function onBeforeWrite() { parent::onBeforeWrite(); if (!$this->exists() && ($member = Member::currentUser())) { $this->Authors()->add($member); } }
/** * {@inheritdoc} */ protected function onBeforeWrite() { parent::onBeforeWrite(); $this->assignGroup(); }
public function onBeforeWrite() { $normalise = function ($url) { return trim(str_replace(array('http://', 'https://'), null, $url), '/'); }; $this->Host = $normalise($this->Host); if ($aliases = $this->HostAliases->getValue()) { $this->HostAliases = array_map($normalise, $aliases); } if ($this->IsDefault) { $others = static::get()->where('"SiteTree"."ID" <> ' . $this->ID)->filter('IsDefault', true); foreach ($others as $other) { $other->IsDefault = false; $other->write(); } } //Set MenuTitle to NULL so that Title is used $this->MenuTitle = NULL; if ($this->ID && Multisites::inst()->assetsSubfolderPerSite() && !$this->Folder()->exists()) { $this->FolderID = $this->createAssetsSubfolder(); } parent::onBeforeWrite(); }
/** * onBeforeWrite **/ public function onBeforeWrite() { parent::onBeforeWrite(); // Set publish date to the created date, if publish date not set if (!$this->PublishDate) { $this->PublishDate = $this->Created; } // a bit hackey, but we need to set the parent ID somehow in GridField form... if ($currentPage = Controller::curr()->currentPage()) { if ($currentPage->ClassName == 'NewsHolder' || is_subclass_of($currentPage, 'NewsHolder')) { $this->ParentID = $currentPage->ID; } } }
function onBeforeWrite() { parent::onBeforeWrite(); // Prefix the URL with "http://" if no prefix is found if($this->ExternalURL && (strpos($this->ExternalURL, '://') === false)) { $this->ExternalURL = 'http://' . $this->ExternalURL; } }