Development

Changeset 1451

You must first sign up to be able to contribute.

Changeset 1451

Show
Ignore:
Timestamp:
06/16/06 10:30:42 (2 years ago)
Author:
fabien
Message:
  • Fixed bug where stylesheets with parameters (arrays) would not be removed via -stylesheet.
  • Added ability to remove all stylesheets at once via stylesheets: [-*].
  • Added the ability to remove all javaScripts at once via [-*]

(closes #621 - patch from slickrick)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/config/sfViewConfigHandler.class.php

    r1415 r1451  
    240240  { 
    241241    $data = array(); 
    242  
     242    $omit = array(); 
     243    $delete = array(); 
     244    $delete_all = false; 
     245 
     246    // Populate $stylesheets with the values from ONLY the current view 
     247    $stylesheets = $this->getConfigValue('stylesheets', $viewName); 
     248 
     249    // If we find results from the view, check to see if there is a '-*' 
     250    // This indicates that we will remove ALL stylesheets EXCEPT for those passed in the current view 
     251    if (is_array($stylesheets) AND in_array('-*', $stylesheets)) 
     252    { 
     253      $delete_all = true; 
     254      foreach ($stylesheets as $stylesheet) 
     255      { 
     256        $key = is_array($stylesheet) ? key($stylesheet) : $stylesheet; 
     257 
     258        if ($key != '-*') 
     259        { 
     260          $omit[] = $key; 
     261        } 
     262      } 
     263    } 
     264    else 
     265    { 
     266      // If '-*' is not found and there are items in the current view's stylesheet array 
     267      // loop through each one and see if there are any values that start with '-'. 
     268      // If so, we add store the actual stylesheet name to the $delete array to be used below 
     269      foreach ($stylesheets as $stylesheet) 
     270      { 
     271        if (!is_array($stylesheet)) 
     272        { 
     273          if (substr($stylesheet, 0, 1) == '-') 
     274          { 
     275          $delete[] = substr($stylesheet, 1); 
     276          } 
     277        } 
     278      } 
     279    } 
     280 
     281    // Merge the current view's stylesheets with the app's default stylesheets 
    243282    $stylesheets = $this->mergeConfigValue('stylesheets', $viewName); 
    244283    if (is_array($stylesheets)) 
    245284    { 
    246       // remove javascripts marked with a beginning '-' 
    247       $delete = array(); 
    248       foreach ($stylesheets as $stylesheet) 
     285      // Loop through each stylesheet in the merged array 
     286      foreach ($stylesheets as $index => $stylesheet) 
    249287      { 
    250288        $key = is_array($stylesheet) ? key($stylesheet) : $stylesheet; 
    251         if (substr($key, 0, 1) == '-') 
    252         { 
    253           $delete[] = $key; 
    254           $delete[] = substr($key, 1); 
    255         } 
    256       } 
    257       $stylesheets = array_diff($stylesheets, $delete); 
     289 
     290        // If $delete_all is true, a '-*' was found above. 
     291        // We remove all stylesheets from the array EXCEPT those specified in the $omit array 
     292        if ($delete_all == true) 
     293        { 
     294          if (!in_array($key, $omit)) 
     295          { 
     296            unset($stylesheets[$index]); 
     297          } 
     298        } 
     299        else 
     300        { 
     301          // Loop through the $delete array and see if the stylesheet name is in the array 
     302          // We check for both the stylesheet and the -stylesheet. If found, we remove them. 
     303          foreach ($delete as $value) 
     304          { 
     305            if ($key == $value OR substr($key, 1) == $value) 
     306            { 
     307              unset($stylesheets[$index]); 
     308            } 
     309          } 
     310        } 
     311      } 
    258312 
    259313      foreach ($stylesheets as $css) 
     
    283337    } 
    284338 
     339    $omit = array(); 
     340    $delete_all = false; 
     341 
     342    // Populate $javascripts with the values from ONLY the current view 
     343    $javascripts = $this->getConfigValue('javascripts', $viewName); 
     344 
     345    // If we find results from the view, check to see if there is a '-*' 
     346    // This indicates that we will remove ALL javascripts EXCEPT for those passed in the current view 
     347    if (is_array($javascripts) AND in_array('-*', $javascripts)) 
     348    { 
     349      $delete_all = true; 
     350      foreach ($javascripts as $javascript) 
     351      {      
     352        if (substr($javascript, 0, 1) != '-') 
     353        { 
     354          $omit[] = $javascript; 
     355        } 
     356      } 
     357    } 
     358 
    285359    $javascripts = $this->mergeConfigValue('javascripts', $viewName); 
    286360    if (is_array($javascripts)) 
    287361    { 
    288362      // remove javascripts marked with a beginning '-' 
     363      // We exclude any javascripts that were omitted above 
    289364      $delete = array(); 
     365 
    290366      foreach ($javascripts as $javascript) 
    291367      { 
    292         if (substr($javascript, 0, 1) == '-'
     368        if (!in_array($javascript, $omit) && (substr($javascript, 0, 1) == '-' || $delete_all == true)
    293369        { 
    294370          $delete[] = $javascript;