1

Updating a demobar component from J3 and the view will not get my demo items for the dropdown from my model. Hoping someone could help me with getting the proper parameters for the menu. I am getting the error at loadString.

UPDATE: $menu->getParams() takes away the error but the demo list is still not filling. Maybe it is somewhere else in my model so maybe someone will see what I don't. Posting the full model.

use Joomla\CMS\Factory;
use Joomla\Registry\Registry;
use Joomla\Utilities\ArrayHelper;
use Joomla\CMS\MVC\Model\ListModel;

class DlejdemoBarModelDlejdemoBar extends ListModel {

    /**
     * Constructor.
     *
     * @param   array   An optional associative array of configuration settings.
     * @see     JControllerLegacy
     */
    public function __construct($config = array()) {
        if (empty($config['filter_fields'])) {
            $config['filter_fields'] = array(
                'id', 'a.id',
                'title', 'a.title',
                'alias', 'a.alias',
                'checked_out', 'a.checked_out',
                'checked_out_time', 'a.checked_out_time',
                'cat_id', 'a.cat_id', 'category_title',
                'state', 'a.state',
                'access', 'a.access', 'access_level',
                'ordering', 'a.ordering',
                'language', 'a.language',
            );
        }
        parent::__construct($config);
    }

    /**
     * Method to auto-populate the model state.
     *
     * Note. Calling getState in this method will result in recursion.
     */
    protected function populateState($ordering = null, $direction = null) {
        $app = Factory::getApplication('site');
        $params = $app->getParams();
        $menuParams = new Registry();

        if ($menu = $app->getMenu()->getActive()) {
            $menuParams->loadString($menu->getParams());
        }

        $mergedParams = clone $menuParams;
        $mergedParams->merge($params);

        $this->setState('params', $mergedParams);

        // process show_noauth parameter
        if (!$params->get('show_noauth')) {
            $this->setState('filter.access', true);
        } else {
            $this->setState('filter.access', false);
        }

        $this->setState('filter.language', JLanguageMultilang::isEnabled());

        $this->setState('layout', $app->input->get('layout'));
    }

    /**
     * Method to get a store id based on model configuration state.
     *
     * This is necessary because the model is used by the component and different modules
     * that might need different sets of data or different ordering requirements.
     *
     * @param   string  $id A prefix for the store id.
     * @return  string  A store id.
     */
    protected function getStoreId($id = '') {
        // compile the store id.
        $id .= ':' . $this->getState('list.filter');
        $id .= ':' . $this->getState('filter.access');
        $id .= ':' . $this->getState('filter.state');
        $id .= ':' . $this->getState('filter.language');

        return parent::getStoreId($id);
    }

    /**
     * Build an SQL query to load the list data.
     *
     * @return  JDatabaseQuery
     */
    protected function getListQuery() {
        // Create a new query object.
        $db = $this->getDbo();
        $query = $db->getQuery(true);

        // Select the required fields from the table.
        $query->select(
            $this->getState(
                'list.select',
                'a.id, a.cat_id,
                a.state, a.access, a.ordering,
                a.language,
                a.title, a.alias, a.image, a.url, a.purchase_url, a.responsive, a.price, a.description'
            )
        );

        $query->from('#__dlejdemobar_products AS a');

        // Join over the Categories.
        $query->select('c.title AS category, c.code AS category_code');
        $query->join('LEFT', '#__dlejdemobar_categories AS c ON c.id = a.cat_id');

        // Filter by access level.
        if ($access = $this->getState('filter.access')) {
            $user = Factory::getUser();
            $groups = implode(', ', $user->getAuthorisedViewLevels());
            $query->where('a.access IN (' . $groups . ')');
            $query->where('c.access IN (' . $groups . ')');
        }

        // Filter by published state
        $published = $this->getState('filter.state', 1);

        if (is_numeric($published)) {
            $query->where('a.state = ' . $published);
        } else if (is_array($published)) {
            ArrayHelper::toInteger($published);
            $published = implode(', ', $published);
            $query->where('a.state IN (' . $published . ')');
        }

        // Filter on the language.
        if ($language = $this->getState('filter.language')) {
            $query->where('a.language in (' . $db->quote(Factory::getLanguage()->getTag()) . ',' . $db->quote('*') . ')');
        }

        // Add the list ordering clause.
        $query->order($this->getState('list.ordering', 'c.ordering, a.ordering'));

        return $query;
    }

}

Thank you in advance.

1 Answer 1

2

The $params instance variable of the MenuItem class is protected, so if you try and access it via

$menu->params

you will get a PHP exception - cannot access protected property.

Use instead:

$menu->getParams()
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.