Search

Dear Symphonians,

I'm trying to build a custom field and data source extension but I have to admit that my PHP knowledge is limited and I don't fully understand how to do things the Symphony way (using the classes und functions available by default).

This is what I try to achieve:

1. A Publish Checkbox

I'd like to created a publish checkbox that - after being checked for the first time - logs the saving date and a revision number in the database. So I would look like this when creating a new article:

[ ] Publish Entry (Revision 1)

After checking the field and saving the entry, it should look like this:

[*] Published Entry (Revision 1)

And after a few more changes and a few times of saving, it should look like this:

[*] Published Entry (Revision 7)

When the field is unchecked the logging process should be stopped until it is checked again.

2. A Revision Data Source

Based on a given entry id I like to set up a data source the outputs the revisions with their numbers, dates und times:

<revisions link-id="17" published="yes">
    <revision number="1" date="2008-05-23" time="23:56" />
    <revision number="2" date="2008-05-24" time="19:16" />
    <revision number="3" date="2008-05-25" time="22:24" />
    <revision number="4" date="2008-05-26" time="17:34" />
    <revision number="5" date="2008-05-27" time="19:38" />
    <revision number="6" date="2008-05-28" time="11:39" />
    <revision number="7" date="2008-05-29" time="12:40" />  
</revisions>

Getting Started

I think I know how to start: I create a new folder (e. g. revisions) in the extension folder. Inside I create the file extension.driver.php with a class extension_revisions. I think I can use the functions install() and uninstall to set up or delete all needed database fields.

After that I create two more folders. A fields and a data-source folder. I'm sure about the first one, I'm guessing the second one (I think it was done that way in Symphony 1.7).

Questions

So here I am. I know I have to set up a new file in the fields folder: field.revision.php with the class fieldRevision. But there are all these functions like __construct(), isSortable(), canFilter() and so on that seems to be important that I don't fully understand.

  • How do I set up the setting panel for the section configuration?
  • How do I create the markup for publish page?
  • Which is the easiest way to make database calls to see if there are preciding revision when loading the publish page?

I try to understand things and I'm eager to learn. But if someone with more PHP experience could lead me on to the right track I would be really thankful!

Nils

How do I set up the setting panel for the section configuration?

Should you require any custom settings for your field, then you will need to overload the displaySettingsPanel() function. However, by the look of it, you are not going to need that. The default panel includes the Label and Placement (sidebar or main) fields.

How do I create the markup for publish page?

displayPublishPanel() is what you need. Here is an example of the one for Checkboxes

function displayPublishPanel(&$wrapper, $data=NULL, $flagWithError=NULL, $fieldnamePrefix=NULL, $fieldnamePostfix=NULL){

    if(!$data){
        ## TODO: Don't rely on $_POST
        if(isset($_POST) && !empty($_POST)) $value = 'no';
        elseif($this->get('default_state') == 'on') $value = 'yes';
        else $value = 'no';
    }

    else $value = ($data['value'] == 'yes' ? 'yes' : 'no');

    $label = Widget::Label();
    $input = Widget::Input('fields'.$fieldnamePrefix.'['.$this->get('element_name').']'.$fieldnamePostfix, 'yes', 'checkbox', ($value == 'yes' ? array('checked' => 'checked') : NULL));

    $label->setValue($input->generate(false) . ' ' . ($this->get('description') != NULL ? $this->get('description') : $this->get('label')));

    $wrapper->appendChild($label);          
}

Your field is going to, more or less, function just like a normal checkbox however it will record additional information if it is checked. With that in mind, I would suggest you copy the field.checkbox.php file in /lib/toolkit/fields and tinker with it.

Which is the easiest way to make database calls to see if there are preciding revision when loading the publish page?

Since this is going to effect how your checkbox appears on the publish page, you should do it in the displayPublishPanel() function. Specifically the line:

$label->setValue($input->generate(false) . ' ' . ($this->get('description') != NULL ? $this->get('description') : $this->get('label')));

If set up like a multi-select (where each entry has multiple rows), all your revision information should be contained in $data. Using that, you could change the $label->setValue line with that instead. E.G.

$label->setValue($input->generate(false) . ' '. $this->get('label') . " (Revision $revision)");

The other option is to use a custom table for storing revision information and query that table separately.

Anyway, hopefully that will get you started. Let me know when you need some more help.

Thanks Alistair, I'll have a try over the next days.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details