Layout override for list filters - Solved

Status
Not open for further replies.

startpoint

Active Member
How to override layout for filters for database join element? Filters type is dropdown. I saw that have override for checkbox filter type, but I need override for dropdown type.
 
It seems that the layout override for dropdown filters hasn't been created, so you can create the override yourself (and add pull request in Github), hack the core code or find some other workaround depending on what exactly you want to achieve.
 
I tried in many ways to hack the filter elements to override it, but with no luck.
I found this file for checkboxes filter type: /components/com_fabrik/layouts/list/filter/fabrik-filter-checkbox.php
How to create jlayout for dropdown filter type?
 
How to create jlayout for dropdown filter type?

That's not probably a task that can be described in a few words :) It's always possible to check how the current layout overrides are done and start from there, or hire someone to do it, if there's no alternative way to solve your issue.
 
I think that I can do the code in layout override file, but how to set the right filename, where to put it and how to load the file from database join plugin?
 
Indeed, this is the most complicated part and my last post still stands also for that question.
 
The fabrik-filter-checkbox layout is called in components\com_fabrik\models\element.php in function checkboxFilter around line 3500 ff.
function checkboxFilter() is called for checkboxes in line 3382
where selectFilter() is called for dropdowns

So I think you must add a layout in function selectFilter() similar to how it is done in checkboxFilter
after $data ='data-filter-name

$layout = $this->getLayout('list-filter-dropdown');
$displayData = new stdClass;
$displayData->rows = $rows;
$displayData->class = $class;
... //at least all what it needs in JHTML
$res = $layout->render($displayData)

and a new file /components/com_fabrik/layouts/list/filter/fabrik-filter-dropdown.php similar to checkbox, something like (nothing tested)
Code:
<?php
defined('JPATH_BASE') or die;

$d    = $displayData;
echo JHTML::_('select.genericlist', $d->rows, $d->v, 'class="' . $d->class . '" ' . $d->size . ' ' . $d->data, 'value', 'text', $d->default, $d->id);
 
@troester thank you for suggestion.
This is modified function:
PHP:
    protected function selectFilter($rows, $default, $v)
    {
        $class   = $this->filterClass();
        $element = $this->getElement();
        $id      = $this->getHTMLId() . 'value';

        if ($element->filter_type === 'dropdown' || $element->filter_type === 'multiselect')
        {
            $advancedClass = $this->getAdvancedSelectClass();
            $class .= !empty($advancedClass) ? ' ' . $advancedClass : '';
        }

        $max  = count($rows) < 7 ? count($rows) : 7;
        $size = $element->filter_type === 'multiselect' ? 'multiple="multiple" size="' . $max . '"' : 'size="1"';
        $v    = $element->filter_type === 'multiselect' ? $v . '[]' : $v;
        $data = 'data-filter-name="' . $this->getFullName(true, false) . '"';
     
       $default                = (array) $default;
       $layout                = $this->getLayout('list-filter-dropdown');
       $displayData            = new stdClass;
       $displayData->rows        = $rows;
       $displayData->v        = $v;
       $displayData->size        = $size;
       $displayData->data        = $data;
       $displayData->default      = $default;
       $displayData->id        = $id;
       $displayData->class    = $class;
     
        $res = $layout->render($displayData);
        if($res == ''){
            $layout = $this->getListModel()->getLayout('list.filter.fabrik-filter-dropdown');
            $res       = $layout->render($displayData);
        }
     
        return $res;
    }
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top