[Solved] Plugin upgrade question

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
markS
Forum Members
Forum Members
Posts: 56
Joined: Wed Aug 20, 2008 3:04 pm

[Solved] Plugin upgrade question

Post by markS »

Hello,

I'm in the process of updating a site from 1.10.x to 1.11.7 and I've come across an issue with a plugin I've written for this site. I've got some, heavily edited, code like:

Code: Select all

$content = $node->getContent();
$pageData = $content->Properties();
$locations[] = $pageData->GetValue('profileloc');
Where 'profileloc' is a content block in a template and present in the page I'm trying to parse. In earlier versions this code would give me access to the content of that block, but it now fails with "PHP Fatal error: Call to a member function GetValue() on a non-object".

Is anyone able to assist me with the proper way to access this data programmatically in cms 1.11.7+?

Thanks in advance for any help.

Regards,

Mark.
Last edited by markS on Mon Jun 17, 2013 5:39 pm, edited 1 time in total.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Plugin upgrade question

Post by calguy1000 »

the data is in the $pageData array.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
markS
Forum Members
Forum Members
Posts: 56
Joined: Wed Aug 20, 2008 3:04 pm

Re: Plugin upgrade question

Post by markS »

Thanks for getting back to me, I appreciate your help.

So I no longer need to use an accessor function to get at the content block data?

When I try and access or dump the $pageData array from the above code snippet I get NULL or nothing useful.

If I dump the $content object, amongst others I see the following two items which appear to be relevant to my issue:

Code: Select all

["_contentBlocks:protected"]=> array(0) { } 
["_contentBlocksLoaded:protected"]=> bool(false)
So it appears that the content blocks are not loaded by default(the pages I'm referencing have approx 11 content blocks)? Should I be passing an argument to $content->Properties(); or $node->getContent(); in order to load that data?

Regards,

Mark.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Plugin upgrade question

Post by calguy1000 »

No, properties are not loaded by default (there are various ways to force the loading of properties though).

Once you have the content object. The proper way of retrieving a property value is using the $content_obj->GetPropertyValue('foo'); method. This 'will' load all the properties and return the requested one.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
markS
Forum Members
Forum Members
Posts: 56
Joined: Wed Aug 20, 2008 3:04 pm

Re: Plugin upgrade question

Post by markS »

Thank you Calguy.

I've resolved my problems with the cms upgrade now.
For future reference, should anyone else have a similar upgrade problem, the code snippet now looks like:

Code: Select all

$content = $node->getContent();
$locations[] = $content->GetPropertyValue('profileloc');
$pageData = $content->Properties();
Once I've got that first property, I can access the other content items by directly referencing the $pageData array, for example:

$mainBlock = $pageData['content_en'];

Thanks again.

Regards,


Mark.

[edit: typo in code]
Post Reply

Return to “Developers Discussion”