Zend multiCheckbox default values bug - zend-framework

I don't know. Simply I don't know. Why does the second codeblock work and check the checkboxes by default, but the first block isn't?
I need to pre-check bitmask flags and I can't/don't want to append strings or something.
// THIS isn't working?!!
$test1 = array(
2 => 'tomato',
4 => 'bitmask problem'
);
$test2 = array(2, 4);
$form->addElement('multiCheckbox', 'flags', array(
'label' => 'Flags',
'value' => $test2,
'multiOptions' => $test1,
)
);
// THIS IS WORKING:
$form->addElement (
'multiCheckbox', 'servers2',
array (
'label' => 'test',
'value' => array('a', 'b'), // select these 2 values
'multiOptions' => array(
'a' => 'aaaaa',
'b' => 'aaaaa',
'c' => 'aaaa',
)
)
);

$form->addElement('multiCheckbox', 'flags', array(
This is causing the error. flags is kinda reserved word in Zend I guess. But I didn't get an error message and I have no other form elements or even variables called flags.
When I rename this, it works!
$form->addElement('multiCheckbox', 'matchingFlags', array(

Related

DisplayCond equation between two values

I am trying to figure it out how can I display field in TCA when two values of other fields are same?
My configuration is that I have two fields new and old and one field second. I would like to reach that field second is displayed when new and old are same or new=1 (this is working).
$fields[] = array(
'new' => array(
'label' => "New ID",
'exclude' => 1,
'config' => array(
'type' => 'input'
)
),
);
$fields[] = array(
'old' => array(
'label' => "old ID",
'exclude' => 1,
'config' => array(
'type' => 'input'
)
),
);
$fields[] = array(
'second' => array(
'exclude' => 1,
'displayCond' => array(
'OR' => array(
'FIELD:new:=:1',
'FIELD:new:=FIELD:old'
)
),
'config' => array(
'type' => 'input',
'size' => '255',
)
),
);
The syntax ''FIELD:new:=FIELD:old' is not allowed by the display condition parser (which i rewrote in core v8). Thus, you can not compare the values of two different fields directly, and you are not able to solve your issue on a display condition level.
You may solve your issue by adding a new data provider (probably after the EvaluateDisplayConditionDataProvider) that removes your column in your special case, see https://docs.typo3.org/typo3cms/CoreApiReference/ApiOverview/FormEngine/Index.html for more docs.

TYPO3 Realurl Configuration Category Page

I have TYPO3 7.6.10.
I have tx_news.
I want to configure my page with news by category.
Now i have:
'newsCategoryConfiguration' => array(
array(
'GETvar' => 'tx_news_pi1[overwriteDemand][categories]',
'lookUpTable' => array(
'table' => 'sys_category',
'id_field' => 'uid',
'alias_field' => 'title',
'addWhereClause' => ' AND NOT deleted',
'useUniqueCache' => 1,
'useUniqueCache_conf' => array(
'strtolower' => 1,
'spaceCharacter' => '-'
)
)
)
),
It works and the result is:
/domain/page-With-List-Of-News-By-Category/Category
If have a sub category the result is:
/domain/-page-With-List-Of-News-By-Category/Category
Ho can i get:
/domain/page-With-List-Of-News-By-Category/Parent-Category/Sub-Category
Maybe there's a faster or better way. But if you won't find, try this and build it yourself using userfunc in that way:
'useUniqueCache_conf' => [
'strtolower' => 1,
'spaceCharacter' => '-',
'encodeTitle_userProc' => 'My\Ext\Hooks\News\RealUrlCategories->buildCategoryPath'
];
and the class something like:
class RealUrlCategories {
function buildCategoryPath($parameters) {
$categoriesPath = '';
// find category rootline
// you can find the uid somewhere in $parameters, then iterate for parent categories and read db for the titles to build final string
...
// return generated string like "Parent-Category/Sub-Category"
return $categoriesPath;
}
}
The problem is, that realURL parses the result of the userFunc with rawurlencode. So Parent-Category/Sub-Category would be transformed to Parent-Category%252FSub-Category.
You could return Parent-Category-Sub-Category. This would also be stored in the cache.
Also your UserFunc could return Parent-Category~~~Sub-Category and you replace the ~~~ with a / in a $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']['encodeSpURL_postProc'] hook, but the ~~~ will be stored in the cache.
You could also add another parameter like parent_category, but this optional parameter doesn't work in the fixesPostVars section because here the parameter is required and so if it is empty, you have an double slash //category in your URL.
Could you find any other solution beside to use the format parent-category-sub-category?

WP_query category__in array only pulls from first category id

I am trying to get ALL post id's for posts in these categories (relation OR): 10,11,12,13,14 with certain extra attributes. My problem is with the categories however.
My args array for my wp_query is as follows:
$args = array(
'orderby' =>'ID',
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'category__in' => array('10','11','12','13','14'),
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'joke_type',
'value' => $type,
'type' => 'CHAR',
'compare' => '='
),
array(
'key' => 'joke_rating',
'value' => 3,
'type' => 'SIGNED',
'compare' => '>='
)
),
'fields' => 'ids'
);
This only gets me posts from category 10 (or whichever ID I place first in the array). I also tried: 'category__in' => '10,11,12,13,14' and 'category' => '10,11,12,13,14' and 'cat' => '10,11,12,13,14' All act the same.
Any idea why this could be happening?
Category IDs inside your category__in array should be integers rather than strings.
Change:
'category__in' => array('10','11','12','13','14'),
To:
'category__in' => array( 10, 11, 12, 13, 14 ),

CakePHP Form Dropdown

I've got this table in my database that outputs this:
array(
(int) 0 => array(
'Price' => array(
'id' => '1',
'amount' => '20',
'price' => '180.00',
'type_id' => '1',
'active' => 'a'
)
),
(int) 1 => array(
'Price' => array(
'id' => '2',
'amount' => '30',
'price' => '232.50',
'type_id' => '1',
'active' => 'a'
)
),
...And so on.
I need a drop down in my form that displays the amount and price together (ie. "20 # 180.00"), but when selected, gets the "id" field.
I reworked a new array called $prices so it outputs like so...
array(
(int) 0 => array(
'id' => '1',
'amount' => '20',
'price' => '180.00',
'type_id' => '1',
'active' => 'a',
'display' => '20 # 180.00'
),
(int) 1 => array(
'id' => '2',
'amount' => '30',
'price' => '232.50',
'type_id' => '1',
'active' => 'a',
'display' => '30 # 232.50'
However, I'm not sure if that array is necessary.
But the main problem is that I don't know what to put in the Form options to make it select the "display" field.
echo $this->Form->input('Project.quantity', array(
'options' => $prices[?????]['display']
));
Simply adding the
'options' => $prices
displays a lot of stuff in the drop down (http://f.cl.ly/items/1e0X0m0D1f1c2o3K1n3h/Screen%20Shot%202013-05-08%20at%201.13.48%20PM.png).
Is there a better way of doing this?
You can use virtual fields.
In your model:
public $virtualFields = array(
'display' => 'CONCAT(amount, " # ", price)'
);
In the controller:
$prices = $this->Price->find('list', array(
'fields' => array('id', 'display')
));
Two ways to do this.
You said you reworked you array to $prices. Then, change that rework so the $prices array looks like this
array('1' => '4 # 6',
/*id*/ => /*price*/
/*etc*/);
and then pass it to the form
echo $this->Form->input('Project.quantity', array(
'options' => $prices
));
For a simple dropdown, retrieve the data with a find('list'). That will give you an array like the one you need to make a dropdown. To change the display field, create a virtual field like this in the model
public $virtualFields = array("display_price"=>"CONCAT(amount, ' # ' ,price)");
public $displayField = 'display_price';
And that way you don't have to rework your array.
If you have other drowpdowns of the same model in other forms, note that those will also change. That's the advantage of doing that in the model... Or disadvantage, if you only want to do it in one part... Like almost everything, it depends on what your need are :)

How to customize Zend_Form_Element_Select

How to put space in between option value of Zend_Form_Element_Select
Expected result as follows,
http://jsfiddle.net/HLbQE/
Tried as follows,
$this->addElement('Select', 'parent_id', array(
'label' => 'Select Category',
'multiOptions' => array('0'=>'Gents','1'=>' Jeans','2'=>' Sunglass','3'=>'Ladies','4'=>' Jeans','5'=>' Sunglass')
));
but fails,
Any help please
Why not just use optgroups? ZF handles this natively by using a nested array for the multi-options, eg
$options = array(
'Gents' => array(
1 => 'Jeans',
2 => 'Sunglass'
),
'Ladies' => array(
3 => 'Jeans',
4 => 'Sunglass'
)
);
Updated demo here - http://jsfiddle.net/HLbQE/1/
Try this:
$this->addElement('Select', 'parent_id', array(
'label' => 'Select Category',
'multiOptions' => array('0'=>'Gents','1'=>' Jeans','2'=>' Sunglass','3'=>'Ladies','4'=>' Jeans','5'=>' Sunglass'),
'escape' => false // <-- added
));
I seems this will not work indeed, as reported in this, still unresolved, issue:
http://framework.zend.com/issues/browse/ZF-5351