-
- 322 Posts
getTVValue no longer returns the raw TV data. For multiselect fields, if I have two items selected, so that the TV in the database is this:
25||26
getTVValue returns this:
2526
The double pipes are gone, and I can't use explode('||',$tvvalue) to put them into an array. What gives?
-
- 24,544 Posts
The getTVValue() method never did return the raw output. It has always called renderOutput(). You might be thinking of $tv->getValue().
In any case, you can (and probably should) get the raw value in one of these ways:
$tvObj = $modx->getObject('modTemplateVar', $tvNameOrId);
if ($tvObj) {
$rawValue = $tvObj->getValue($resourceId);
}
$c = array(
'tmplvarid' => $tvId,
'contentid' => $resourceId,
}
$tvr = $modx->getObject('modTemplateVarResource', $c);
if ($tvr) {
$rawValue = $tvr->get('value');
}
The second method will be faster.
Note that any method that uses the raw values of TVs will only work if no TV is set to the TV's default value and no TV is set to @INHERIT, unless you add code to handle those conditions.
-
- 322 Posts
Well, I have a script that was running under 2.2.14 using getTVValue, and it was getting '25||26' as the returned value for a multiselect field. Here it is:
$sectionids=explode('||',$modx->resource->getTVValue('news_section'));
So, maybe it's renderOutput that is behaving differently in 2.3. Why would the rendered output be '2526' anyway? That doesn't make much sense.
And, what you're saying is that if I have a TV that is a multiselect field, and have resources set to inherit that value, or if the default value is a multiple selection, there is now no way at all to get an array of the selected values, right? That's what it sounds like.
Also, I tried your first script, and it is not working with the TV name ($tvNameOrId), only with the ID.
[ed. note: rainbowtiger last edited this post 9 years, 8 months ago.]
Are you sure that the TV wasn't using an Output option of "delimited", with the delimiter set to be "||"?
-
- 322 Posts
Output type is "default". What's the default for a Listbox(multiselect)?
-
- 322 Posts
Aha. If I change the TV output to delimited, with || as the delimiter, then the retrieved value returns to the way it was before.
SO . . .
Did the default output type for Listbox(multiselect) change in MODX 2.3??
-
- 24,544 Posts
It might have. I'm not sure if that would be a bug or a feature.