public function beforeSave() { $this->defaultText = $this->modx->lexicon('modxtalks.default'); $properties = $this->getProperties(); if (isset($properties['modxtalks'])) { $settings = $this->cleanArray($properties['modxtalks']); $this->object->setProperties($settings, 'modxtalks', false); } return parent::beforeSave(); }
/** * Do any processing before the save of the Resource but after fields are set. * @return boolean */ public function beforeSave() { $beforeSave = parent::beforeSave(); // Get all translated data as arrays $translations = $this->getTranslatedFields(); $resId = $this->getProperty('id'); foreach ($translations as $lang => $fields) { if ($row = $this->modx->getObject('Translation', array('articleID' => $resId, 'language' => $lang))) { $row->set('pagetitle', $fields['pagetitle']); $row->set('longtitle', $fields['longtitle']); $row->set('menutitle', $fields['menutitle']); $row->set('introtext', $fields['introtext']); $row->set('description', $fields['description']); $row->set('content', $fields['content']); $row->save(); } } return $beforeSave; }
public function beforeSave() { $afterSave = parent::beforeSave(); // Make sure this is not saved anywhere it shouldn't be /* $parent = $this->modx->getObject('modResource',$this->object->get('parent')); if ($parent) { $this->modx->log(1, print_r($parent->toArray(),true)); } else { $this->modx->log(1, 'No Parent!'); } */ }
/** {inheritDoc} */ public function beforeSave() { $this->object->set('isfolder', 0); return parent::beforeSave(); }
public function beforeSave() { $this->object->set('class_key', 'GridContainer'); $this->object->set('hide_children_in_tree', true); $this->object->set('cacheable', true); $this->object->set('isfolder', true); $properties = $this->getProperties(); $settings = $this->object->getProperties('gridclasskey'); foreach ($properties as $k => $v) { if (substr($k, 0, 22) == 'gridclasskey-property-') { $key = substr($k, 22); if ($v === 'false') { $v = 0; } elseif ($v === 'true') { $v = 1; } if ($key === 'fields') { $v = json_decode($v, TRUE); } $settings[$key] = $v; } } $this->object->setProperties($settings, 'gridclasskey'); return parent::beforeSave(); }
/** * Override modResourceUpdateProcessor::beforeSave to provide archiving * * {@inheritDoc} * @return boolean */ public function beforeSave() { $afterSave = parent::beforeSave(); if ($this->object->get('published') && ($this->object->isDirty('alias') || $this->object->isDirty('published'))) { if (!$this->setArchiveUri()) { $this->modx->log(modX::LOG_LEVEL_ERROR, 'Failed to set date URI.'); } } /** @var ArticlesContainer $container */ $container = $this->modx->getObject('ArticlesContainer', $this->object->get('parent')); if ($container) { $this->object->setProperties($container->getProperties('articles'), 'articles'); } $this->isPublishing = $this->object->isDirty('published') && $this->object->get('published'); return $afterSave; }
/** * Override modResourceUpdateProcessor::beforeSave to provide archiving * * {@inheritDoc} * @return boolean */ public function beforeSave() { $afterSave = parent::beforeSave(); $container = $this->modx->getObject('ArticlesContainer', $this->object->get('parent')); if ($this->object->get('published') && ($this->object->isDirty('alias') || $this->object->isDirty('published'))) { if (!$this->setArchiveUri()) { $this->modx->log(modX::LOG_LEVEL_ERROR, 'Failed to set date URI.'); } } else { if ($this->object->get('pub_date') && $this->object->isDirty('pub_date') || $this->object->isDirty('pub_date')) { if (!$this->setArchiveUri()) { $this->modx->log(modX::LOG_LEVEL_ERROR, 'Failed to set date URI pub_date.'); } } else { if (!$this->object->get('published') && !$this->object->get('pub_date')) { // we need to always do this because the url may have been set previously by pub_date /*$containerUri = $container->get('uri'); if (empty($containerUri)) { $containerUri = $container->get('alias'); }*/ $uri = rtrim($this->object->get('alias')); $this->object->set('uri', $uri); $this->object->set('uri_override', true); } } } /** @var ArticlesContainer $container */ if ($container) { $this->object->setProperties($container->getProperties('articles'), 'articles'); } $this->isPublishing = $this->object->isDirty('published') && $this->object->get('published'); return $afterSave; }
/** * Override modResourceUpdateProcessor::beforeSave to provide custom functionality, saving settings for the container * to a custom field in the DB * {@inheritDoc} * @return boolean */ public function beforeSave() { $properties = $this->getProperties(); $settings = $this->object->getProperties('articles'); $notificationServices = array(); foreach ($properties as $k => $v) { if (substr($k, 0, 8) == 'setting_') { $key = substr($k, 8); if ($v === 'false') { $v = 0; } if ($v === 'true') { $v = 1; } switch ($key) { case 'notifyTwitter': if ($v) { $notificationServices[] = 'twitter'; } break; case 'notifyTwitterConsumerKey': if (!empty($v)) { $v = $this->object->encrypt($v); } break; case 'notifyTwitterConsumerKeySecret': if (!empty($v)) { $v = $this->object->encrypt($v); } break; case 'notifyFacebook': if ($v) { $notificationServices[] = 'facebook'; } break; } $settings[$key] = $v; } } $settings['notificationServices'] = implode(',', $notificationServices); $this->object->setProperties($settings, 'articles'); return parent::beforeSave(); }
/** * Override modResourceUpdateProcessor::beforeSave to provide custom functionality, saving settings for the container * to a custom field in the DB. * * The Post data comes thru flattened (boo) * [specs_4] => on [specs_12] => on [taxonomies_3] => on [taxonomies_4] => on [variations_1] => Option Only [variations_2] => Variant [variations_3] * On the flip side, it should be available in JS via this path: MODx.activePage.config.record.properties.moxycart * * {@inheritDoc} * @return boolean */ public function beforeSave() { $raw = $this->getProperties(); // <-- this will have raw values $properties = $this->object->getProperties('moxycart'); //<-- we need to update these values $this->object->set('class_key', 'Store'); //$this->modx->log(1,'beforeSave raw values: '.print_r($raw,true)); //$this->modx->log(1,'existing values: '.print_r($properties,true)); //$this->modx->log(1,'beforeSave raw POST values: '.print_r($_POST,true)); $properties['product_type'] = $this->modx->getOption('product_type', $raw); $properties['product_template'] = $this->modx->getOption('product_template', $raw); $properties['track_inventory'] = $this->modx->getOption('track_inventory', $raw) == 'Yes' ? 1 : 0; $properties['sort_order'] = $this->modx->getOption('sort_order', $raw); $properties['qty_alert'] = $this->modx->getOption('qty_alert', $raw); // Fresh start... $properties['specs'] = array(); $properties['taxonomies'] = array(); $properties['variations'] = array(); foreach ($raw as $k => $v) { $len = strlen($k); if ($this->starts_with($k, 'specs')) { $properties['specs'][substr($k, 6 - $len)] = true; } if ($this->starts_with($k, 'taxonomies')) { $properties['taxonomies'][substr($k, 11 - $len)] = true; } if ($this->starts_with($k, 'variations')) { $properties['variations'][substr($k, 11 - $len)] = $v; } } $this->object->setProperties($properties, 'moxycart'); return parent::beforeSave(); }