/** * Validate the form * @return boolean */ public function beforeSave() { $name = $this->getProperty('name'); /* verify element with that name does not already exist */ if ($this->alreadyExists($name)) { $this->addFieldError('name', $this->modx->lexicon($this->objectType . '_err_exists_name', array('name' => $name))); } $category = $this->getProperty('category', 0); if (!empty($category)) { /** @var modCategory $category */ $category = $this->modx->getObject('modCategory', array('id' => $category)); if (empty($category)) { $this->addFieldError('category', $this->modx->lexicon('category_err_nf')); } if (!$category->checkPolicy('add_children')) { $this->addFieldError('category', $this->modx->lexicon('access_denied')); } } $locked = (bool) $this->getProperty('locked', false); $this->object->set('locked', $locked); $this->setElementProperties(); $this->validateElement(); if ($this->object->staticContentChanged()) { if ($this->object->get('content') !== '' && !$this->object->isStaticSourceMutable()) { $this->addFieldError('static_file', $this->modx->lexicon('element_static_source_immutable')); } else { if (!$this->object->isStaticSourceValidPath()) { $this->addFieldError('static_file', $this->modx->lexicon('element_static_source_protected_invalid')); } } } return !$this->hasErrors(); }
public function beforeSave() { $locked = $this->getProperty('locked'); if (!is_null($locked)) { $this->object->set('locked', (bool) $locked); } /* make sure a name was specified */ $nameField = $this->classKey == 'modTemplate' ? 'templatename' : 'name'; $name = $this->getProperty($nameField, ''); if (empty($name)) { $this->addFieldError($nameField, $this->modx->lexicon($this->objectType . '_err_ns_name')); } else { if ($this->alreadyExists($name)) { /* if changing name, but new one already exists */ $this->modx->error->addField($nameField, $this->modx->lexicon($this->objectType . '_err_exists_name', array('name' => $name))); } } /* if element is locked */ if ($this->object->get('locked') && $this->modx->hasPermission('edit_locked') == false) { $this->addFieldError($nameField, $this->modx->lexicon($this->objectType . '_err_locked')); } /* category */ $category = $this->object->get('category'); $this->previousCategory = $category; if (!empty($category)) { $category = $this->modx->getObject('modCategory', array('id' => $category)); if (empty($category)) { $this->addFieldError('category', $this->modx->lexicon('category_err_nf')); } } /* can't change content if static source is not writable */ if ($this->object->staticContentChanged()) { if (!$this->object->isStaticSourceMutable()) { $this->addFieldError('static_file', $this->modx->lexicon('element_static_source_immutable')); } else { if (!$this->object->isStaticSourceValidPath()) { $this->addFieldError('static_file', $this->modx->lexicon('element_static_source_protected_invalid')); } } } return !$this->hasErrors(); }
/** * Override set to properly strip invalid tags from script code * * {@inheritdoc} */ public function set($k, $v= null, $vType= '') { if (in_array($k,array('snippet','plugincode'))) { $v= trim($v); if (strncmp($v, '<?', 2) == 0) { $v= substr($v, 2); if (strncmp($v, 'php', 3) == 0) $v= substr($v, 3); } if (substr($v, -2, 2) == '?>') $v= substr($v, 0, -2); $v= trim($v, " \n\r\0\x0B"); } $set= parent :: set($k, $v, $vType); return $set; }
/** * Validate the form * @return boolean */ public function beforeSave() { $name = $this->getProperty('name'); /* verify element with that name does not already exist */ if ($this->alreadyExists($name)) { $this->addFieldError('name', $this->modx->lexicon($this->objectType . '_err_exists_name', array('name' => $name))); } $category = $this->getProperty('category', 0); if (!empty($category)) { /** @var modCategory $category */ $category = $this->modx->getObject('modCategory', array('id' => $category)); if (empty($category)) { $this->addFieldError('category', $this->modx->lexicon('category_err_nf')); } if (!$category->checkPolicy('add_children')) { $this->addFieldError('category', $this->modx->lexicon('access_denied')); } } $locked = (bool) $this->getProperty('locked', false); $this->object->set('locked', $locked); $this->setElementProperties(); $this->validateElement(); return !$this->hasErrors(); }
/** * Hook before save, returning false will abandon save * * @param \modElement $modElement * @return boolean */ public function onBeforeSave(\modElement &$modElement) { $modElement->set('type', $this->getType()); $modElement->set('caption', $this->getCaption()); $modElement->set('source', $this->getSource()); $modElement->set('locked', intval($this->_locked)); $modElement->set('rank', intval($this->_rank)); $modElement->set('display', $this->_display); $modElement->set('display_params', $this->_display_params); $modElement->set('default_text', $this->_default_text); $modElement->set('elements', $this->_elements); $modElement->set('input_properties', $this->_input_properties); $modElement->set('output_properties', $this->_output_properties); $modElement->setProperties($this->_properties, true); return true; }