Search

@robphilip - Thanks, but unfortunately, I’m having trouble on figuring out what else to use for the third parameter. Once again, my PHP lack of skills is showing forth here. Here’s the section of code in the filter.field.php extension file that is suspect…

// Check if publish data is valid
        public function checkPostFieldData($data, &$message, $entry_id=NULL){
            if (!($expression = trim($this->get('filter_publish')))) return self::__OK__;
// TODO: Get entry fields data (backtrace? POST?) and replace {entry/field} with field value.
//      We can't Use EntryPreCreate, EntryPreEdit and EventPreSaveFilter delegates
//      because Entry* are called AFTER check (checkPostFieldData) and set (processRawFieldData).
//      Only EventPreSaveFilter is called before them, but it's used only when publishing from frontend.
            $fields = array();
            if (preg_match_all('@{([^}]+)}@i', $expression, $matches, PREG_SET_ORDER)) {
                foreach ($matches as $m) {
                    if (isset($fields[$m[1]])) {
                        $v = $fields[$m[1]];
                        if (is_array($v)) {
                            $v = implode(', ', $v);
                        }
                        $expression = str_replace($m[0], $v);
                    }
                /*  else $expression = str_replace($m[0], ''); */
                }
            }

            $message = NULL;
            if (!$this->evaluateExpression($expression)) {
                $message = __("Contains invalid data.");
                return self::__INVALID_FIELDS__;
            }

            return self::__OK__;        
        }

It’s tripping on line 166, else $expression = str_replace($m[0], ''); And as robphilip pointed out above, the str_replace function, needs three parameters. Unfortunately, I don’t know what to put in that third parameter. alt text

I tried to put a third parameter, so I put, else $expression = str_replace($m[0],', ',''); and the Symphony Warning error goes away, but when I try to save the entry, I get another error, Some errors were encountered while attempting to save. Then, I tried commenting out that code altogether to see what happens, and again, the Symphony Warning error goes away, but I get the error, Some errors were encountered while attempting to save.

alt text

Does anyone know how to solve this? Again, I apologize for my lack of PHP knowledge, but I’m stuck. I WAS USING THE EXTENSION INCORRECTLY, please see the comment below.

I think the field is not meant to be used like that.

You’re probably trying to save your expression as an entry (which is not implemented, there is a big TODO in the code :D), while you should just use it to filter your datasources and nothing more.

@alpacaaa -

Thank you! I just was using the extension wrong. I was putting the expression in the Prevent publishing if expression below evaluates to false area of the field when I was adding it to my section. That was my problem. I left that field blank and checked Allow datasources to filter this section with expression. Then when I went to my datasource for that section, I filtered the datasource on that field.

That was my problem! Sorry for the wild goose chase! Thank you again!

I was putting the expression in the Prevent publishing if expression below evaluates to false area of the field when I was adding it to my section. That was my problem. I left that field blank and checked Allow datasources to filter this section with expression. Then when I went to my datasource for that section, I filtered the datasource on that field.

Had exactly the same problem, that part of the extension is totally un-intuitive; the publish box on the section editor should just be hidden if it’s not even used. Otherwise, love the extension though :)

Field: Filter updated to version 1.1 on 25th of April 2011

Fixed bugs (thanks for reports!), implemented long awaited feature of publish filtering (it is "Value filtering" now, as it does not have to block entry if expression evaluates to false - now it can simply store no instead of yes in database :).

It is now also possible to use field for filtering field's value when an entry is being saved, allowing or disallowing execution of data source and filtering the same data source by field's value (yes or no).

Conditionalizer updated to version 1.2 on 27th of June 2012

Because of the name change, it will convert existing "Filter" fields into "Conditionalizer" fields. You can uninstall and remove "Field: Filter" after that.

Conditionalizer updated to version 1.2.1 on 29th of June 2012

Conditionals for entry saving?! When was this added? Does it work for frontend events?

i.e. http://getsymphony.com/discuss/thread/89468/

Lewis, it was added (or finished, because it was planned from the beginning :) in v1.1.

I did not try it with events, but it may work (Event.section calls Entry->checkPostData() and handles errors, which means that a Conditionalizer field is called the same way as when saving from the administration area).

Marcin, I'm trying your extension for the first time (it seems to be really helpful) and I have two questions:

  • Wouldn't it make sense to replace the core Required URL Parameter field with the Conditionalizer input instead of leaving the first in the interface and additionally adding the latter?
  • Would it be possible to build the condition using a Duplicator interface? While the conditions are quite powerful there is only a limited range of options and having predefined filter templates in the interface would make filtering easier to read for non-programmers and would also remove a source of syntax errors.

Nils,

Wouldn't it make sense to replace the core Required URL Parameter field [...]

That's a good idea to keep interface clean and tidy, but i am not sure if it's OK to remove core features from user. Required URL Parameter is a lot simpler to setup and it is handled before the delegate is called (so, before Conditionalizer is called), so it is faster when one wants to just check for existance of a single parameter.

edit: maybe there could be optional "switch", so only one of them would be visible at a time?

Would it be possible to build the condition using a Duplicator interface?

I was thinking about building some kind of "visual editor" in the future. Possibly using something similar to "jigsaw puzzles" from Scratch (probably less colorful, to keep it in a style used elsewhere in Symphony administration area :). But if someone could write JS (hint :), that would build interface on top of current textarea (so it would be optional, and user could switch between visual and textual editing), that would be awesome and appreciated :)!

Can Duplicator interface have sub-fields and sub-sub-fields? Because Conditionalizer syntax allows multi-level conditions.

Nils, one more thing: Conditionalizer can be used on any type of data-source, not just on section data-sources. Required URL Parameter is used only with section data-sources (at least in the interface... i think that functionality is there, for other types to use, but it's not visible in the interface).

Can Duplicator interface have sub-fields and sub-sub-fields? Because Conditionalizer syntax allows multi-level conditions.

I think an UI for Conditionalizer should only try to help with the most common cases and should still offer a plain textbox for the advanced stuff. Two filter layers can be represented with a Duplicator easily:

  • single conditions: (if value of ({$name}) is (symphony))
  • two level conditions: (if any of ((if value of ({$ds-type}) is (mytype)), {$ds-true-or-false}) is (yes))

That's a good idea to keep interface clean and tidy, but i am not sure if it's OK to remove core features from user.

I would just hide the UI elements but would not remove the functionality: if the user enters a condition like (if ({$param}) is not ()), $param could be set to the Required URL Parameter variable automatically. If he enters multiple of these conditions the first one could be used.

But if someone could write JS (hint :), that would build interface on top of current textarea (so it would be optional, and user could switch between visual and textual editing), that would be awesome and appreciated :)!

Well, there would be two additional things needed to build the interface:

  • a regular expression to parse a given condition into an array that could be used to populate the interface
  • a list of all parameters available for filtering (best added to the textarea as a comma-separated list in a data-param attribute)

If you could provide me with this, I could have a look at building the interface.

Awesome.

Nils, thanks!

Two filter layers can be represented with a Duplicator easily: [...]

Good idea. Maybe it could also include checkbox somewhere, that would change "any of" to "all of"?

if the user enters a condition like (if ({$param}) is not ()), $param could be set to the Required URL Parameter variable automatically.

Nice. It probably should check for both:

(if value of ({$param}) is not ())
(if all of ({$param},{$otherparam}) is not ())

But it would probably have to parse whole thing anyway, to check if final comparison is for "yes" or "no". Because any of those lines above could be used as a parts of other conditions, that actually do not want parameters to be set at all.

a regular expression to parse a given condition into an array that could be used to populate the interface

I've added tokenizer.js to the repository. It's generated with help of PEG.js and returns array of conditions (look for more information inside the tokenizer file).

a list of all parameters available for filtering (best added to the textarea as a comma-separated list in a data-param attribute)

I've added tags under Conditionalizer's textarea. That should help, and it can be used for "advanced" editing at the same time :).

Right, I'll have a look at this over the next weeks.

Thanks.

Conditionalizer updated to version 1.2.2 on 12th of July 2012

Fixed crashing error reported by bzerangue, thanks :)!

I started working on a UI for this extension:

Conditionalizer UI

Now I just need to understand how the tokenizing works.
Anyone around who would like to help with this?

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