Jump to content

FrontendContentManager: add and edit pages as frontend user


pwFoo
 Share

Recommended Posts

Hello,

is there a recommend  way how to add / save new pages via frontend?

Could I use/ integrate some core modules to do it (field sanitizing and saving)?

With my FormHelper module I can create forms from pages and templates. That works fine for edit a page.

To add a new page is tricky...

Before I execute my save function I have to do some preSave actions (save the fake page! Set parent and name!).

Now also add and save pages works... until there is a file / image field...

Error: Exception: Invalid image (in /volume1/web/pwdev/wire/modules/Inputfield/InputfieldFile/InputfieldFile.module line 273)

#0 [internal function]: InputfieldFile->___processInputAddFile('tk_passbild_and...')
#1 /volume1/web/pwdev/wire/core/Wire.php(359): call_user_func_array(Array, Array)
#2 /volume1/web/pwdev/wire/core/Wire.php(317): Wire->runHooks('processInputAdd...', Array)
#3 /volume1/web/pwdev/wire/modules/Inputfield/InputfieldFile/InputfieldFile.module(360): Wire->__call('processInputAdd...', Array)
#4 /volume1/web/pwdev/wire/modules/Inputfield/InputfieldFile/InputfieldFile.module(360): InputfieldImage->processInputAddFile('tk_passbild_and...')
#5 [internal function]: InputfieldFile->___processInput(Object(WireInputData))
#6 /volume1/web/pwdev/wire/core/Wire.php(359): call_user_func_array(Array, Array)
#7 /volume1/web/pwdev/wire/core/Wire.php(317): Wire->runHooks('processInput', Array)
#8 /volume1/web/pwdev/wire/core/InputfieldWrapper.php(436): Wire->__call('processInput', Array)
#9 /volume1/web/pwdev/wir

Here the page add method which basically works without file / image fields.

 public function add($parent, $options = null) {
        // ignore admin pages and check permissions!
        if ($this->input->urlSegment1 != 'add' || $page->template == 'admin' || !$parent->addable()) return false; 
        
        $tpl = ($options['tpl'] ? $options['tpl'] : $parent->template);
        
        $fh = $this->modules->get('FormHelper');
        $fh->createForm($parent, array('clearValues' => true));
        
        // process form
        $processedForm = $fh->formProcess();
        
        if ($sanitizedForm = $this->checkFormValues($processedForm)) {  // sanitizing is skipped with always true!
            
            $title = $sanitizedForm->get('title')->value;
            
            $page = new Page();
            $page->template = $tpl
            $page->parent = $parent;
            $page->name = $this->sanitizer->pageName($title);
            $page->title = $title;
            $page->save(); 
            
            $this->pageSave($page, $processedForm, true);
        }
        else {
            return $fh->render();
        }
    }

    // Set page values and save it...
    private function pageSave($page, $processedForm, $changed = false) {
        foreach ($processedForm->children as $field) {
            if ($field->value != $page->get($field->name)) {    
                $page->set($field->name, $field->value);
                $changed = true;
            }
        }
        
        if ($changed) {
            // Save and reload to show changed page... 
            $page->of(false);
            $page->save();
            $page->of(true);
        }
    }

Would like to reuse backend page save function (validate and sanitize form values before save the new page).

Link to comment
Share on other sites

After loading jquery and set "jsconfig" WYSIWYG editor works fine, but there are some more modules needed to get a full styled form.

For example image field?

How can I determine and load needed modules to get a full styled form (like backend forms) with autocomplete page reference for example (JqueryCore, JqueryUI,...)?

But first problem to solve should be file / image field handling from post above...

Error: Exception: Invalid image (in /volume1/web/pwdev/wire/modules/Inputfield/InputfieldFile/InputfieldFile.module line 273)

#0 [internal function]: InputfieldFile->___processInputAddFile('tk_passbild_and...')
#1 /volume1/web/pwdev/wire/core/Wire.php(359): call_user_func_array(Array, Array)
#2 /volume1/web/pwdev/wire/core/Wire.php(317): Wire->runHooks('processInputAdd...', Array)
#3 /volume1/web/pwdev/wire/modules/Inputfield/InputfieldFile/InputfieldFile.module(360): Wire->__call('processInputAdd...', Array)
#4 /volume1/web/pwdev/wire/modules/Inputfield/InputfieldFile/InputfieldFile.module(360): InputfieldImage->processInputAddFile('tk_passbild_and...')
#5 [internal function]: InputfieldFile->___processInput(Object(WireInputData))
#6 /volume1/web/pwdev/wire/core/Wire.php(359): call_user_func_array(Array, Array)
#7 /volume1/web/pwdev/wire/core/Wire.php(317): Wire->runHooks('processInput', Array)
#8 /volume1/web/pwdev/wire/core/InputfieldWrapper.php(436): Wire->__call('processInput', Array)
#9 /volume1/web/pwdev/wir

No problem with images during frontend page edit, only during page add... So I think I have to set some more values or change my page presave / save method...

Link to comment
Share on other sites

  • 2 weeks later...

At the moment FrontendContentManager module (dev, unstable) used to edit and add pages as frontend user. Also add and delete images works.

CKeditor doesn't work in regular mode. Inline mode ckeditor is loaded, but text isn't saved (save works fine with simple text field without wysiwyg ?!)
jsconfig is set and JqueryCore loaded first.

Two questions:

  1. How should such a module named? (add, edit and optional delete pages as frontend user)? Any better suggestion than FrontendContentManager (short: FCM)?
  2. Form (created via form api with own FormHelper module) is unstyled. Inputfield scripts and styles are loaded, but form / fields still unstyled.
    Are there some more styles and scripts which be used in the admin section to style forms / edit page?
Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...