Exemplo n.º 1
0
 /**
  * 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();
 }
Exemplo n.º 2
0
 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();
 }