Note the upgraded forum! If you are experiencing issues logging in, you may need to reset your password which should send an email. If the email doesn't arrive, be sure to check your spam folder just in case.

Page Custom Field Post-processing

edited October 2011 in Installation
I have a custom field that is a file upload for a specific page. The image will be the header image for the page. When the file is stored to the assets folder, it stores the name of the file as lowercase. However, when it stores the name of the file to the page variables, it stores it in its original state, which is camel case. I'm trying to add a strtolower() to the function that stores the image to the assets folder and saves it as a page variable record so they match, but I can't seem to locate the code for "fuel/pages/edit/5". Can you tell me how to locate this file so I can add the strtolower functionality? Also, this may be a bug that should be addressed. Thanks!


  • edited October 2011
    It's in the fuel/modules/fuel/controllers/pages.php controller. Let me know how it goes.
  • edited March 2012
    Definitely a bug -- I'm finding the same issue. BTW -- I am editing from the dashboard and uploading a pdf file. The file gets save with a lowercase name. The record containing the file name keeps the original name. I am not fining it in the controller you reference above. I'm not seeing how I would know what the field with the file name is.
    Nor am I seeing where the code is in the controller that would handle this.

    Can you give me any guidance?

    Alternatively, is there any "before save" hook that I might be able to use to clean it up? Is it all case changes, or are other changes (such as forcing uniqueness) possible?

  • edited 10:10PM
    I have a recent pull request with a fix for that I think... check this out and let me know if it works fuel/modules/fuel/controllers/module.php:

    Full file
  • edited 10:10PM
    Also, there is an on_after_post hook you can use on your model along with the models uploaded_data property which holds all the info for uploaded files.
  • edited 10:10PM
    I'll try it. Thanks.
  • edited 10:10PM
    It works! Thanks!
  • edited March 2012
    Related question....(I'm now using the module.php referenced above). I have allowed multiple file types in the assets/pdf directory and set the allowable asset types both for the directory and again explicitly in the model...I'm using a field name ending in _pdf which I'm assuming could potentially be relevant to the behavior.

    The file gets saved correctly...for example test.xls

    But if the file does not have the extension "pdf" it gets appended onto the name to be stored anyway. What gets stored in the database is test.xls.pdf

    Any idea how I would avoid that or undo it? I'd obviously prefer to avoid, but getting rid of would work. I'm assuming that this might be in an on_after_post hook?

    On hooks, I'm pretty unclear how I get the data or return it. I desperately need a simple example -- my ignorance biting again.

  • edited 10:10PM
    Hope others may find this useful ...

    Code to get rid of potential extra periods that someone might have in names of files being uploaded (like file_v2.2.pdf) -- browsers get unhappy with those extra periods

    Near the end of _process (around line 710)
    // set both values for the namespaced and non-namespaced... make them underscored and lower cased $tmp_field_name = end(explode('--', $field_name)); // code to make sure no extra periods get into the name $path_parts = pathinfo($field_value); $ext = $path_parts['extension']; $filename_no_ext = $path_parts['filename']; //replace excess periods with underscores and put it back together $filename_no_ext = str_replace('.','_',$filename_no_ext); $field_value = $filename_no_ext.'.'.$ext; // Now clean up everything else $posted[$tmp_field_name] = url_title($field_value, 'underscore', TRUE); $posted[$field_name] = url_title($field_value, 'underscore', TRUE);

    and in _process_uploads around line 1370 (note that I also commented out original code)

    // continue processing $filename = $file_info['name']; #$filename_arr = explode('.', $filename); #$filename_no_ext = $filename_arr[0]; #$ext = end($filename_arr); // find the parts of the file name, get rid of any excess periods, and put it back together $path_parts = pathinfo($filename); $ext = $path_parts['extension']; $filename_no_ext = $path_parts['filename']; //replace excess periods with underscores and put it back together $filename_no_ext = str_replace('.','_',$filename_no_ext); $filename = $filename_no_ext.'.'.$ext;
  • edited March 2012
    # quote
    EcotypeS: On hooks, I'm pretty unclear how I get the data or return it. I desperately need a simple example -- my ignorance biting again.
    # quote

    Maybe irrelevant now, but the hooks are defined MY_model which your models extend.

    MY_Model::on_after_post() is defined around #2154.

    If in your model you have a:

    public function on_after_post($values) { # Do work return $values; }

    That'll get run and return whatever you did to values. You should also have access to $_POST and $_FILES (Files I've not had to use so test).

    Another example would be form_fields() where you commonly run the parent method, then your own and maybe change up some labels or whatever and return those changes.

    Does that help at all?
Sign In or Register to comment.