Search

With my extension, I need to embed some js in the head of the admin area. I couldn’t figure out how to do it without being really redundant. Does anyone have some quick pointers on how to do this.

What I have is this in the admin area:

Individual entry pages

  • CSS link
  • jQuery link
  • js link
  • js link

Section entry list page

  • jQuery link
  • js link

My field.php function looks like this:

 function displayPublishPanel(&$wrapper, $data=NULL, $flagWithError=NULL, $fieldnamePrefix=NULL, $fieldnamePostfix=NULL){

$this->_engine->Page->addScriptToHead(URL . '/extensions/color_chooser_field/assets/jquery.js', 52);

    $this->_engine->Page->addScriptToHead(URL . '/extensions/color_chooser_field/assets/farbtastic.js', 53);

    $this->_engine->Page->addScriptToHead(URL . '/extensions/color_chooser_field/assets/color-chooser.js', 54);

    $this->_engine->Page->addStylesheetToHead(URL . '/extensions/color_chooser_field/assets/farbtastic.css', 'screen', 55);

My extension.driver.php function looks like this:

public function initaliseAdminPageHead($context) {
        $page = $context['parent']->Page;

        $page->addScriptToHead(URL . '/extensions/color_chooser_field/assets/jquery.js', 50);
        $page->addScriptToHead(URL . '/extensions/color_chooser_field/assets/color-list.js', 51);
    }

}

My problem is that the extension.driver.php function adds the links to every page in the admin area. I need it to only embed where needed: just on the Section entry list page. I haven’t found another extension that does this, so I’m a little lost.

Rowan’s Publish Filtering ext. might be worth checking out. It’s limited to the same page you’re after.

I noticed that the multiselect_to_checkboxes extension is more specific when embedding links in the head. I think it only adds the links to a new and edit entry pages.

Here’s the extension.driver.php of that extension:

public function __appendAssets($context){
    if(isset(Administration::instance()->Page->_context['section_handle']) && in_array(Administration::instance()->Page->_context['page'], array('new', 'edit'))){  
      Administration::instance()->Page->addStylesheetToHead(URL . '/extensions/multiselect_to_checkboxes/assets/mtoc.css', 'screen', 221);
      Administration::instance()->Page->addScriptToHead(URL . '/extensions/multiselect_to_checkboxes/assets/jquery.symphony.mtoc.js', 222);      
   }
  }
}

I want to restrict mine to just the section’s entry list page.

@Makenosound: The Publish Filtering ext was the right extension to check out. Thank you! My extension is now working correctly.

Well, it still shows up on indexes that don’t use my custom field.

Is there any way to have it only embed the scripts if the custom field is being displayed in the column view?

Thanks for the help. :-)

 public function initaliseAdminPageHead($context) {
          $page = $context['parent']->Page;

          if ($page instanceof ContentPublish and $page->_context['page'] == 'index') {
            $page->addScriptToHead(URL . '/extensions/color_chooser_field/assets/jquery.js', 50);
            $page->addScriptToHead(URL . '/extensions/color_chooser_field/assets/color-list.js', 51);
          }

        }

I think in my Order Entries field I perform an additional check to see whether the current section index view contains an Order Entry field. But I’m tired, and might be wrong!

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details