Page 1 of 1

[Solved] Plugin upgrade question

Posted: Mon Jun 17, 2013 1:58 pm
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.

Re: Plugin upgrade question

Posted: Mon Jun 17, 2013 4:02 pm
by calguy1000
the data is in the $pageData array.

Re: Plugin upgrade question

Posted: Mon Jun 17, 2013 4:39 pm
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.

Re: Plugin upgrade question

Posted: Mon Jun 17, 2013 4:56 pm
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.

Re: Plugin upgrade question

Posted: Mon Jun 17, 2013 5:37 pm
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]