Stack editing, facebook sdk

Permalink
Slowly but surely I've overcome the Facebook api and have begun pushing it to my FB package. As per issues loading the sdk multiple times (page list teasers for instance), I've moved that process to within a settings block, which is needed on any page any other package blocks reside to work, and then only gets loaded once, as needed. Next i ran into an error with putting sdk dependent blocks within a stack. error would render as per attached image (Stack Manager dialogue) and i would have to switch versions to regain control of the stack.

Next I added a modified version ofhttp://www.concrete5.org/documentation/how-tos/designers/check-if-b... to my block controller. Thanks mkly!

public function on_page_view() {
     $page = Page::getCurrentPage();
     $nh = Loader::helper('navigation');
     $URL = $nh->getCollectionURL($page);
     // Avoid errors in Core Stack and Stack Manager edit mode.
     // FB SDK is typically loaded on a page by the settings block.
     if (strpos($URL, '/dashboard/blocks/')) {
          Loader::library('fb-sdk/src/facebook', 'enlil_facebook_plugins');
          Loader::library('pull_fb.class', 'enlil_facebook_plugins');
     }
     //
}


Both the core stack editing interface and the Stack Manager will now display the block properly, but once you edit and save it the error appears again. Although, the block is now editable and the error has no effect on functionality. Is there an optimal block controller function to place it in? Load the sdk from my package controller?? Looking for some sound advice so I can take this in the right direction :)

1 Attachment

enlil
 
JohntheFish replied on at Permalink Reply
JohntheFish
If there are not many fb functions that you actually use, you could wrap all the calls up in a library class. The file for that class can precede the class declaration with an if(!class_exists())... test. You will have seen similar code in a lot of my files, such as all the Magic Data symbols. (I use it habitually to avoid problems when I copy classes between addons).