Recovery of a Form in Module

For Joomla! 4.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Locked
Slushgood
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 140
Joined: Tue Sep 22, 2015 1:04 pm
Location: St palais sur mer, France

Recovery of a Form in Module

Post by Slushgood » Fri Jul 01, 2022 2:15 pm

I explain myself following a search I get a form on my page ($thid->items). I would like to retrieve the information in a module that I created.
I thought I could retrieve the info by the model but it does not work.
$model = $app->bootComponent('com_xxx')->getMVCFactory()->createModel('Books', 'Site', ['ignore_request' => true]);
$results = $model->getItems();
Thanks for your help

MarkRS
Joomla! Explorer
Joomla! Explorer
Posts: 329
Joined: Thu Oct 29, 2009 8:28 am
Location: UK

Re: Recovery of a Form in Module

Post by MarkRS » Fri Jul 01, 2022 3:57 pm

Presumably you're getting the full result without taking any notice of the search items the user entered?
"It doesn't work" doesn't give us much of a hint as to what exactly is going wrong.

Since you're coming at it from a module not the component you probably need to do the work to generate the user state (from the query) to recreate the the exact result you're looking for. I'm not certain you can do it the same way, you may need to get a little creative.

If you look at the model code ("getListQuery"?) you'll be able to find the things that need to be set.
It's a community, the more we all contribute, the better it will be.

Slushgood
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 140
Joined: Tue Sep 22, 2015 1:04 pm
Location: St palais sur mer, France

Re: Recovery of a Form in Module

Post by Slushgood » Tue Jul 05, 2022 12:15 pm

Thank you Mark for this piece of research. What I want exactly is to create a module capable of filtering the result of my search visible in the body of my site. To do this, I would already have to retrieve the search query for my component via the model. That's what I can't do

MarkRS
Joomla! Explorer
Joomla! Explorer
Posts: 329
Joined: Thu Oct 29, 2009 8:28 am
Location: UK

Re: Recovery of a Form in Module

Post by MarkRS » Tue Jul 05, 2022 1:05 pm

Indeed. You can't do it because you can't access the component's instance of the model.

So I'm suggesting looking at how the component fills the state (user or otherwise) from the screen form in the query, and then fill that state yourself (from the screen form) and then you'll be able to create the same result.
It's a community, the more we all contribute, the better it will be.

Slushgood
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 140
Joined: Tue Sep 22, 2015 1:04 pm
Location: St palais sur mer, France

Re: Recovery of a Form in Module

Post by Slushgood » Tue Jul 05, 2022 1:12 pm

https://joomdonationdemo.com/eshop/
the module "Eshop Products Filter" is what i want to do.

Slushgood
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 140
Joined: Tue Sep 22, 2015 1:04 pm
Location: St palais sur mer, France

Re: Recovery of a Form in Module

Post by Slushgood » Tue Jul 05, 2022 1:20 pm

oops! I don't know if I'm smart enough to do this. Could one of the functions of the model help you?
Model

Code: Select all

public function getForm($data = array(), $loadData = true)
    {
        // Get the form.
        $form = $this->loadForm('com_xxx', 'filter_books', array('control' => 'jform','load_data' => $loadData));
        
        if (empty($form))
        {
            return false;
        }
        
        return $form;
    }
	public function __construct($config = array())
	{

		if (empty($config['filter_fields']))
		{
			$config['filter_fields'] = array(				
				'title', 'b.title','book_title',		    
			);
		}

		parent::__construct($config);
	}
protected function populateState($ordering = null, $direction = null)
	{
	    $app = Factory::getApplication();

	    $input = $app->input;
	    $context = $this->context; //com_xxx.items
...
	
		// List state information.
		parent::populateState($ordering, $direction);

	}

	public function getItems()
	{
		$items = parent::getItems();

		return $items;
	}
Last edited by Per Yngve Berg on Tue Jul 12, 2022 9:25 am, edited 1 time in total.
Reason: Added code tags around code

MarkRS
Joomla! Explorer
Joomla! Explorer
Posts: 329
Joined: Thu Oct 29, 2009 8:28 am
Location: UK

Re: Recovery of a Form in Module

Post by MarkRS » Tue Jul 05, 2022 4:18 pm

Yes... ummm... no. These snippets don't help.

It's the code (should be in your getListQuery method) that sets up "where" clauses for your query.
I've got stuff like that in some of my code, for example

Code: Select all

		$language = $this->getState('filter.language');
		if ($language)
		{
			$query->where('a.language = ' . $db->quote($language));
		}
You must (surely?) have something like this if you're letting people put in search criteria.
It's a community, the more we all contribute, the better it will be.

Slushgood
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 140
Joined: Tue Sep 22, 2015 1:04 pm
Location: St palais sur mer, France

Re: Recovery of a Form in Module

Post by Slushgood » Thu Jul 07, 2022 1:34 pm

that's right. I have in the function getListQuery a lot of where with a return $query to finish. This is what I would like to retrieve in my module so that I can work on it
Last edited by Slushgood on Thu Jul 07, 2022 2:18 pm, edited 1 time in total.

Slushgood
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 140
Joined: Tue Sep 22, 2015 1:04 pm
Location: St palais sur mer, France

Re: Recovery of a Form in Module

Post by Slushgood » Thu Jul 07, 2022 1:37 pm

by associating the namespace I access the getListQuery() request but it returns an error

0 Call to protected method J4x\Component\xxx\Site\Model\BooksModel::getListQuery() from context 'Joomla\CMS\Dispatcher\ModuleDispatcher'

even if i made it public
0 Using $this when not in object context

Slushgood
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 140
Joined: Tue Sep 22, 2015 1:04 pm
Location: St palais sur mer, France

Re: Recovery of a Form in Module

Post by Slushgood » Tue Jul 12, 2022 8:53 am

Apparently I have to save the result in a session variable.
How and where to create this session variable?

MarkRS
Joomla! Explorer
Joomla! Explorer
Posts: 329
Joined: Thu Oct 29, 2009 8:28 am
Location: UK

Re: Recovery of a Form in Module

Post by MarkRS » Tue Jul 12, 2022 10:14 am

Let me Google that for you... :eek:

You could try viewtopic.php?t=605099, the first one that came up.

Notice it's very old, but it looks like it might work. You want "Session" not "JSession", but other than that it looks plausible.
It's a community, the more we all contribute, the better it will be.


Locked

Return to “Joomla! 4.x Coding”