Development

Changeset 1445

You must first sign up to be able to contribute.

Changeset 1445

Show
Ignore:
Timestamp:
06/14/06 04:32:58 (2 years ago)
Author:
slickrick
Message:

* Fixed bug where stylesheets with parameters (arrays) would not be removed via -stylesheet. (Fixes ticket #621)
* Added ability to remove all stylesheets at once via stylesheets: [-*].

Files:

Legend:

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

    r1338 r1445  
    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   
     265  // If '-*' is not found and there are items in the current view's stylesheet array 
     266  // loop through each one and see if there are any values that start with '-'. 
     267  // If so, we add store the actual stylesheet name to the $delete array to be used below 
     268  else 
     269  { 
     270    foreach ($stylesheets as $stylesheet) 
     271    { 
     272      if (!is_array($stylesheet)) 
     273      { 
     274        if (substr($stylesheet, 0, 1) == '-') 
     275        { 
     276        $delete[] = substr($stylesheet, 1); 
     277        } 
     278      } 
     279    } 
     280  } 
     281 
     282    // Merge the current view's stylesheets with the app's default stylesheets 
    243283    $stylesheets = $this->mergeConfigValue('stylesheets', $viewName); 
    244284    if (is_array($stylesheets)) 
    245     { 
    246       // remove javascripts marked with a beginning '-' 
    247       $delete = array(); 
    248       foreach ($stylesheets as $stylesheet) 
     285    {       
     286      // Loop through each stylesheet in the merged array      
     287      foreach ($stylesheets as $index => $stylesheet) 
    249288      { 
    250289        $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); 
     290         
     291        // If $delete_all is true, a '-*' was found above. 
     292        // We remove all stylesheets from the array EXCEPT those specified in the $omit array 
     293        if ($delete_all == true) 
     294        { 
     295          if (!in_array($key, $omit)) 
     296          { 
     297            unset($stylesheets[$index]); 
     298          } 
     299        } 
     300        else 
     301        { 
     302          // Loop through the $delete array and see if the stylesheet name is in the array 
     303          // We check for both the stylesheet and the -stylesheet. If found, we remove them. 
     304          foreach ($delete as $value) 
     305          { 
     306            if ($key == $value OR substr($key, 1) == $value) 
     307            { 
     308              unset($stylesheets[$index]); 
     309            } 
     310          } 
     311        } 
     312      } 
    258313 
    259314      foreach ($stylesheets as $css)