We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 47633
    • 11 Posts
    I'm working on making a password protected gallery http://forums.modx.com/thread/91175/protecting-a-gallery-album-with-a-password. I've written some code which creates a resource and populates it with an appropriate [[!Gallery]] call.

    The problem is I'm struggling to find a way to get it to run when Gallery creates an album. I've looked in /core/components/gallery/processors/mgr/album/create.class.php and found a method that runs before an album is saved. But putting any of my own code in there stops the album being created.
    Below is the method where I tried to put code.
    I tried listing all the code inline,
    $modx->runSnippet('Testing');
    and saving it to a snippet, neither worked. Even putting one line in, to make a log entry, stops the gallery being created.

    public function beforeSave() {
           	$name = $this->getProperty('name');
            if (empty($name)) $this->addFieldError('name',$this->modx->lexicon('gallery.album_err_ns_name'));
    
    	$modx->log(modX::LOG_LEVEL_INFO, '[Gallery] WHEN I AM HERE THE GALLERY DOESN'T SAVE');
    		
            $this->object->set('createdby',$this->modx->user->get('id'));
            $total = $this->modx->getCount('galAlbum');
            $this->object->set('rank',(int)$total);
    
    
    		
    		return parent::beforeSave();
        }
    


    Does anyone know any 'way in' to gallery so I can run my own code when a gallery is created?
    Any help would be much appreciated.