Is there a JCB way to set the values in the filter dropdown in the admin list view? I'd like to for batch editing. #693
-
I've done some research into this, and the closest I've seen is this tutorial, but it's focused more on JCB Fields. I want to set the values that are available in the filter dropdown that JCB generates when you select "Yes" for the Filter option when editing an admin view's linked fields. By default, JCB only lists values that are set in the current items. So for example, I have a Yes/No radio field, but all items are currently set to No, then the only filter option is No. This isn't that big of a deal when you just want to filter, but the reason I want to set the available values is because of the batch edit function. Batch edit seems to be linked to the filtered fields, but because of this the only values that you can change them to are ones that already exist. The filters for the baked-in fields do this, like Status, Access, and Categories. I'm wondering if there's a JCB way of doing this that I'm missing. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You are right, that the filter list is build from the data in the table, and therefore if a value is not there, it will not show as an option (we don't look at the field options at all). There is a way to add your own filters, but they will not show in the batch options at this point. Your batch options are currently build with filters in the interpretation class with the following method: /**
* build batch loading helper scripts
*
* @param string $nameSingleCode The single view name
* @param string $nameListCode The list view name
*
* @return string The php to place in view.html.php
*
*/
public function setBatchDisplayHelper(&$nameSingleCode, &$nameListCode)
{
// start the batch bucket
$fieldBatch = array();
// add the default batch
$this->setDefaultBatchHelper($fieldBatch, $nameSingleCode);
// add the category filter stuff
$this->setCategoryBatchHelper($fieldBatch, $nameListCode);
// check if we have other batch options to add
if (isset($this->filterBuilder[$nameListCode])
&& ComponentbuilderHelper::checkArray(
$this->filterBuilder[$nameListCode]
))
{
// check if we should add some help to get the values (2 = topbar)
$get_values = false;
if (isset($this->adminFilterType[$nameListCode])
&& $this->adminFilterType[$nameListCode] == 2)
{
// since the old path is not used, we need to add those values here
$get_values = true;
}
// get component name
$Component = $this->fileContentStatic[$this->hhh . 'Component'
. $this->hhh];
// load the rest of the batch options
foreach ($this->filterBuilder[$nameListCode] as $filter)
{
if ($filter['type'] != 'category'
&& ComponentbuilderHelper::checkArray($filter['custom'])
&& $filter['custom']['extends'] !== 'user')
{
$CodeName = ComponentbuilderHelper::safeString(
$filter['code'] . ' ' . $filter['custom']['text'], 'W'
);
$codeName = $filter['code']
. ComponentbuilderHelper::safeString(
$filter['custom']['text'], 'F'
);
$fieldBatch[] = PHP_EOL . $this->_t(2)
. "//" . $this->setLine(__LINE__)
. " Only load " . $CodeName
. " batch if create, edit, and batch is allowed";
$fieldBatch[] = $this->_t(2)
. "if (\$this->canBatch && \$this->canCreate && \$this->canEdit)";
$fieldBatch[] = $this->_t(2) . "{";
// add the get values here
if ($get_values)
{
$type = ComponentbuilderHelper::safeString(
$filter['custom']['type'], 'F'
);
$fieldBatch[] = $this->_t(3) . "//"
. $this->setLine(__LINE__) . " Set " . $CodeName
. " Selection";
$fieldBatch[] = $this->_t(3) . "\$this->" . $codeName
. "Options = JFormHelper::loadFieldType('" . $type
. "')->options;";
$fieldBatch[] = $this->_t(3) . "//" . $this->setLine(
__LINE__
) . " We do some sanitation for " . $CodeName
. " filter";
$fieldBatch[] = $this->_t(3) . "if (" . $Component
. "Helper::checkArray(\$this->" . $codeName
. "Options) &&";
$fieldBatch[] = $this->_t(4) . "isset(\$this->"
. $codeName
. "Options[0]->value) &&";
$fieldBatch[] = $this->_t(4) . "!" . $Component
. "Helper::checkString(\$this->" . $codeName
. "Options[0]->value))";
$fieldBatch[] = $this->_t(3) . "{";
$fieldBatch[] = $this->_t(4) . "unset(\$this->"
. $codeName
. "Options[0]);";
$fieldBatch[] = $this->_t(3) . "}";
}
$fieldBatch[] = $this->_t(3) . "//" . $this->setLine(
__LINE__
) . " " . $CodeName . " Batch Selection";
$fieldBatch[] = $this->_t(3)
. "JHtmlBatch_::addListSelection(";
$fieldBatch[] = $this->_t(4) . "'- Keep Original '.JText:"
. ":_('" . $filter['lang'] . "').' -',";
$fieldBatch[] = $this->_t(4) . "'batch[" . $filter['code']
. "]',";
$fieldBatch[] = $this->_t(4)
. "JHtml::_('select.options', \$this->" . $codeName
. "Options, 'value', 'text')";
$fieldBatch[] = $this->_t(3) . ");";
$fieldBatch[] = $this->_t(2) . "}";
}
elseif ($filter['type'] != 'category')
{
$CodeName = ComponentbuilderHelper::safeString(
$filter['code'], 'W'
);
$fieldBatch[] = PHP_EOL . $this->_t(2)
. "//" . $this->setLine(__LINE__)
. " Only load " . $CodeName
. " batch if create, edit, and batch is allowed";
$fieldBatch[] = $this->_t(2)
. "if (\$this->canBatch && \$this->canCreate && \$this->canEdit)";
$fieldBatch[] = $this->_t(2) . "{";
// add the get values here
if ($get_values)
{
$fieldBatch[] = $this->_t(3) . "//"
. $this->setLine(__LINE__) . " Set " . $CodeName
. " Selection";
$fieldBatch[] = $this->_t(3) . "\$this->"
. $filter['code']
. "Options = JFormHelper::loadFieldType('"
. $filter['filter_type']
. "')->options;";
$fieldBatch[] = $this->_t(3) . "//" . $this->setLine(
__LINE__
) . " We do some sanitation for " . $CodeName
. " filter";
$fieldBatch[] = $this->_t(3) . "if (" . $Component
. "Helper::checkArray(\$this->" . $filter['code']
. "Options) &&";
$fieldBatch[] = $this->_t(4) . "isset(\$this->"
. $filter['code'] . "Options[0]->value) &&";
$fieldBatch[] = $this->_t(4) . "!" . $Component
. "Helper::checkString(\$this->" . $filter['code']
. "Options[0]->value))";
$fieldBatch[] = $this->_t(3) . "{";
$fieldBatch[] = $this->_t(4) . "unset(\$this->"
. $filter['code'] . "Options[0]);";
$fieldBatch[] = $this->_t(3) . "}";
}
$fieldBatch[] = $this->_t(3) . "//" . $this->setLine(
__LINE__
) . " " . $CodeName . " Batch Selection";
$fieldBatch[] = $this->_t(3)
. "JHtmlBatch_::addListSelection(";
$fieldBatch[] = $this->_t(4) . "'- Keep Original '.JText:"
. ":_('" . $filter['lang'] . "').' -',";
$fieldBatch[] = $this->_t(4) . "'batch[" . $filter['code']
. "]',";
$fieldBatch[] = $this->_t(4)
. "JHtml::_('select.options', \$this->"
. $filter['code'] . "Options, 'value', 'text')";
$fieldBatch[] = $this->_t(3) . ");";
$fieldBatch[] = $this->_t(2) . "}";
}
}
}
// did we find batch options
if (ComponentbuilderHelper::checkArray($fieldBatch))
{
// return the batch
return PHP_EOL . implode(PHP_EOL, $fieldBatch);
}
return '';
} There are more place things are done for batch... but this is where the actual list are being build. So we can add an event here and then you can via a plugin change this code behavior for a field... there are a number of ways we can try and extend this. But know that this feature does not exist at this time, and should I build it, it will go towards pro members, which you can join of course... |
Beta Was this translation helpful? Give feedback.
You are right, that the filter list is build from the data in the table, and therefore if a value is not there, it will not show as an option (we don't look at the field options at all). There is a way to add your own filters, but they will not show in the batch options at this point.
Your batch options are currently build with filters in the interpretation class with the following method: