Jump to content

FrontendContentManager


pwFoo
 Share

Recommended Posts

FrontendContentManager

(unstable / testing)

FrontendContentManager is a module based on FormHelper to generate needed page edit / add form via form api. 

NO sanitizing of form values at the moment!!!

  • edit pages
  • create / add new pages
  • add, replace and remove images

Download

ProcessWire module page: http://modules.processwire.com/modules/frontend-content-manager

Bitbucket Repo: https://bitbucket.org/pwFoo/frontendcontentmanager

Version

0.2.0

Required

FormHelper (0.7.1+)

Usage

Example template file

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta http-equiv="content-type" content="text/html; charset=utf-8" />
		<title><?php echo $page->title; ?></title>
<?php

// Load FormHelper module and also set wire('fh') variable
$fcm = $modules->get('FrontendContentManager');

// edit existing page
//$form = $fcm->edit($pages->get('1108'));

// add a new page based on a template and a parent object
$parent = $pages->get('name=test');
$form = $fcm->add($parent, $parent->template);

// jsConfig needed by ckeditor
echo $fcm->JsConfig(); 

// outpunt needed scripts for inputfield modules, ...
foreach ($config->styles as $file) { echo "<link type='text/css' href='$file' rel='stylesheet' />\n"; } 
foreach ($config->scripts as $file) { echo "<script type='text/javascript' src='$file'></script>\n"; }

?>
	</head>
	<body>
		<h1><?php echo $page->title; ?></h1>
<?php 

// output the forom
echo $form;

?>
	</body>
</html>

*UPDATED TO 0.1.0*

At the moment I have no usage for FCM module, but after FormHelper 0.5.2 is finished I've done a quick FCM rewrite. Only few tests done yet!

*UPDATED TO 0.2.0*

Updated to work with redesigned FormHelper 0.7

Edited by pwFoo
  • Like 5
Link to comment
Share on other sites

Hey pwFoo,

Just a couple of things - it isn't possible to install your module directly from the modules directory because the bitbucket link doesn't work properly. FormHelper did download and install automatically though, so maybe you just need to tweak something with the url to your module.

Next thing - I installed and put:

$fcm = $modules->get('FrontendContentManager');

// edit page (editable permission needed)
echo $fcm->edit($page);

in a template file, but nothing was output and I was logged in as a superuser. Am I missing something obvious?

Link to comment
Share on other sites

Hi Adrian,

is it a problem with the link or because the module isn't approved yet?

Sorry my bad! I have to update the documentation.

At current version I use url segments! But maybe I change this.

Module checks permissions, template isn't an admin template AND url segment /add or /edit.

What do you think. Should I remove the url segment check from module and move it to the template (in developers hand)?

Link to comment
Share on other sites

You're right - probably just because it isn't approved yet.

Adding edit to the url - with url segments enabled did the trick, but I am concerned that there will be issues with your module relying on segments if the dev also wants to use segments for controlling output on the frontend. It might be better to just go with: /?edit=1

Link to comment
Share on other sites

Hi Marty,

Fredi use the backend interface in an overlay. So you should get a styled edit page (like backend admin).

FCM is based on FormHelper module (generate and process forms). You can use it inside the frontend page without an overlay and with your own styles.

At the moment it's tested with simple pages/ templates. 

  • create pages
  • edit page fields (it's also possible to skip fields and so remove from edit form)
  • upload, replace and remove images)

It's untested with multi language or repeater fields for example.

Link to comment
Share on other sites

I redesigned FCM to be more flexible.

New testing branch working like this (inside a demo module "conversation").

    public function add ($parent, $redirect = null, $options = array('clearValues' => true)) {
        $fcm = $this->modules->get('FrontendContentManager');
        
        $form = $fcm->createForm($parent, $options);
        
        if ($fcm->formProcess()) {
            $page = $fcm->add($parent);
            
            // Manipulate page object from outside...
            $page->name = $page->id . '-' . $this->sanitizer->pageName($page->title);
            
            $fcm->save();
            
            if ($redirect === null) $redirect = $page->url;
            $this->session->redirect($redirect);
        }
        return $form->render();
    }
    
    public function edit ($topic, $options = null) {
        $fcm = $this->modules->get('FrontendContentManager');
        
        $form = $fcm->createForm($topic, $options);
        
        if ($fcm->formProcess()) {
            $page = $fcm->edit($topic);
            
            // Manipulate page object outside...
            $page->name = $page->id . '-' . $this->sanitizer->pageName($page->title);
            
            $fcm->save();
            $this->session->redirect($topic->url);
        }
        return $form->render();
    }
  • Like 2
Link to comment
Share on other sites

  • 5 weeks later...

After some changes and improvements to FormHelper I'll start to update FCM too.

Most work to realize a page add / edit is done by FormHelper (create, modify, render, process form and also care about file / image upload). FCM brings FormHelper together with a create / save page functionality. 

Page save vs. field save 

Current version of FCM update all the fields and finally save the hole page. That's fine to save the all the changes done before.

But I think about a rewrite to a field save instead of a page save, because a "fieldSave" process module could be used stand alone to handle frontend page edit and also ajax based updates (an optional submodule...)? 

Any hints or suggestions about pro and cons?

Permission check

Access control was removed in the second dev version, but should be added optional to FCM again. It won't have it's one permission handling, but will use PW 

$page->editable() and $page->addable(). 

Your ideas and suggestions are welcome to improve the module ;)

Link to comment
Share on other sites

  • 2 months later...
  • 2 weeks later...
  • 2 weeks later...
  • 1 month later...
  • 2 months later...

FCM release 0.5.0 (no documentation at the moment... sorry!)

  • requires FormHelper
  • add / edit pages
  • default sanitizer based on field type (textarea or text) if no sanitizer is set to the field
  • skip fields
  • optional use admin form styles
  • file / image upload during page add (check input, page pre-save, set field values and add files and again save the page...)

usage / example

// load FCM
$fcm = $modules->get('FrontendContentManager');

// ADD a page to given parent with parent template
$output = $fcm->renderAdd($parentPage);

// or EDIT given page
$output = $fcm->renderEdit($pageToEdit);

// echo jsConfig inside the html head element
echo $fcm->JsConfig(); 

// outpunt needed scripts for inputfield modules, ... inside your html head element
foreach ($config->styles as $file) { echo "<link type='text/css' href='$file' rel='stylesheet' />\n"; } 
foreach ($config->scripts as $file) { echo "<script type='text/javascript' src='$file'></script>\n"; }

// echo $output inside your template / html body element
echo $output;

PW module repo: http://modules.processwire.com/modules/frontend-content-manager

GIT repo: https://bitbucket.org/pwFoo/frontendcontentmanager/src/

  • Like 4
Link to comment
Share on other sites

  • 5 months later...

Just had a look at this module and tried to make it work. The only thing I see is a submit button. If i click it a new page will be created or (if i uncommented that for edit) the given page will be edited (or u get redirected to the page 1015 for example). But there are no fields at all to change anything. What did I do wrong?

Installed formhelper and this is my template:

<?php // load FCM
$fcm = $modules->get('FrontendContentManager');

// ADD a page to given parent with parent template
//$output = $fcm->renderAdd($pages->get('1015'));

// or EDIT given page
$output = $fcm->renderEdit($pages->get('1015'));

// echo jsConfig inside the html head element
echo $fcm->JsConfig(); 

// outpunt needed scripts for inputfield modules, ... inside your html head element
foreach ($config->styles as $file) { echo "<link type='text/css' href='$file' rel='stylesheet' />\n"; } 
foreach ($config->scripts as $file) { echo "<script type='text/javascript' src='$file'></script>\n"; }

// echo $output inside your template / html body element
echo $output; ?>

As you can see, I am trying to edit the page number 1015, which has a different template only with title and textarea field. And I was expecting to see those fields on the edit page, with the template written above.

Appreciate your help!

Link to comment
Share on other sites

Could you post your complete template file, please?

With this simple line I get a form with all fields of the template.

$fcm->add($pages->get('title=my-page-title'));

// OR
//renderAdd is a shortcut for add() + process() + render()
$fcm->renderAdd($pages->get('title=gfh'));

Get page by ID should also work (it needs a page object). The other params are optional.

Short edit / add tests with my dev setup show all the form fields.

Form should be processed and rendered before you output the results.

Link to comment
Share on other sites

  • 3 months later...

I made a template for add new page. Page is added under home page.

<?php include('./_header.php'); ?>
<?php

// Load FormHelper module and also set wire('fh') variable
$fcm = $modules->get('FrontendContentManager');

// add a new page based on a template and a parent object
$parent = $pages->get('name=home');
$form = $fcm->add($parent, $parent->template);

// jsConfig needed by ckeditor
echo $fcm->JsConfig();

// outpunt needed scripts for inputfield modules, ...
foreach ($config->styles as $file) { echo "<link type='text/css' href='$file' rel='stylesheet' />\n"; }
foreach ($config->scripts as $file) { echo "<script type='text/javascript' src='$file'></script>\n"; }

?>
    <div class="uk-container uk-container-center">
        <h1><?php echo $page->title; ?></h1>
        <?php

        // output the forom
        echo $form;

        ?>
    </div>

<?php include('./_footer.php'); ?>

and only result I get is this. Any help?

https://www.dropbox.com/s/2mwtksa20qxs5bk/Screen%20Shot%202016-03-10%20at%2011.52.48.png?dl=0

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

Thanks for posting this. I don't use it. Dependency seems missing, but FormHelperExtra is needed here...

  • create a form object with fields based on Template, Page, Form objects or field data array
  • form file upload handling (temp page uploads, creation of a hidden storage page)
Link to comment
Share on other sites

The only other problem for now are the textarea sanitizer.

Its like the sanitize do not recognize the good type and put a text sanitize on a textarea and pass only 255 characters and not the 16384 for the textarea.

*****EDIT******

I finally found the problem... the class type in the module are "FieldTypeTextarea" but with multi-language the class type are "FieldTypeTextareaLanguage".

I will add the other Field type in the condition and all work fine.

Link to comment
Share on other sites

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

×
×
  • Create New...