Skip to content

Use getState instead of direct property read#10435

Merged
roland-d merged 3 commits intojoomla:stagingfrom
izharaazmi:patch-11
May 16, 2016
Merged

Use getState instead of direct property read#10435
roland-d merged 3 commits intojoomla:stagingfrom
izharaazmi:patch-11

Conversation

@izharaazmi
Copy link
Copy Markdown
Contributor

@izharaazmi izharaazmi commented May 12, 2016

Pull Request for Issue #10416.

Summary of Changes

Use getState instead of direct property read in JModelList to avoid any undefined property warnings.
Using $this->getState against $this->state->get ensures the model state is populated appropriately.

Testing Instructions

  • Enable error reporting from global configuration.
  • In any list view class such as ContentViewArticles at administrator/components/com_content/views/articles/view.html.php in the display method call $this->get('FilterForm'); before $this->get('State') or $this->get('Items') etc.

Expected: Everything should work correctly.
Actual: You see 4 php notices such as Notice: Undefined property: JObject::$list....

Fixes #10416

Use getState instead of direct property read to avoid any undefined property warnings.
@andrepereiradasilva
Copy link
Copy Markdown
Contributor

@izharaazmi you have unit test errors.

@izharaazmi
Copy link
Copy Markdown
Contributor Author

@andrepereiradasilva yeah, I'm looking at that. Apparently that is the issue with the test definition. But can't say it yet.

We're setting state manually for this test case. But since the flag is not set the populateState will be called and it will overwrite them.
@andrepereiradasilva
Copy link
Copy Markdown
Contributor

@Devportobello you have to mark as tested in the issue tracker (https://issues.joomla.org/tracker/joomla-cms/10435 login with github and mark test as success).

@andrepereiradasilva
Copy link
Copy Markdown
Contributor

I have tested this item ✅ successfully on 45a6d09

The notices dissapear after this PR so i will make as success.
I think if you used $this->state->get('list.xxxx') you would get the same result.

But for what is worth, if you exchange the order the filters/ordering/search (aka searchtols) will not work properly. With or without this PR.


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/10435.

@Devportobello
Copy link
Copy Markdown
Contributor

I have tested this item ✅ successfully on 45a6d09


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/10435.

@brianteeman
Copy link
Copy Markdown
Contributor

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/10435.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label May 12, 2016
@brianteeman brianteeman added this to the Joomla 3.6.0 milestone May 12, 2016
@izharaazmi
Copy link
Copy Markdown
Contributor Author

But for what is worth, if you exchange the order the filters/ordering/search (aka searchtols) will not work properly. With or without this PR.

@andrepereiradasilva Can you please explain this.

@andrepereiradasilva
Copy link
Copy Markdown
Contributor

andrepereiradasilva commented May 12, 2016

Note this happens with or without your PR.

For instance, change the order of the $this->get('FilterForm') in the articles view.html.php file.

$this->filterForm    = $this->get('FilterForm'); // PUT THIS ONE ON TOP
$this->items         = $this->get('Items');
$this->pagination    = $this->get('Pagination');
$this->state         = $this->get('State');
$this->authors       = $this->get('Authors');
$this->activeFilters = $this->get('ActiveFilters');

Now try to use the searchtools in articles view. search for something, order or filter by something.
You will notice the table will be modified accordly but the searchtools filters pre selected values won't.

@izharaazmi
Copy link
Copy Markdown
Contributor Author

@andrepereiradasilva The solution is straightforward. Use $this->get('State') in the view before you call any method on the model.
OR
Change the JModelList::loadFormData() to call $this->getState(); before calling $app->getUserSate()

But that is not all. Therefore instead of a placing a PR, I'd prefer a little discussion regarding loadFormData behavior in JModelList vs JModelForm, preferably on a separate thread.

@andrepereiradasilva
Copy link
Copy Markdown
Contributor

ok then create a issue / RFC

@roland-d
Copy link
Copy Markdown
Contributor

Thanks everybody

@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label May 16, 2016
@izharaazmi izharaazmi deleted the patch-11 branch May 17, 2016 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants