The values from ffp show up in the field_inspector module for the entity file fields that use ffp however when you try and recreate them from field_create_instance ( $instance ); it does not work.

I need to hard code all my settings so I setup this function for the time being. Ultimately integration with field_inspector or the features module would be preferred. Any plans or better ways to do this?


/**
 * Update a filefield_path field settings from an array programmatically
 * based on filefield_paths_form_submit
 *
 * @param $settings array of all the values
 *
 */
function apply_ffp_settings ( $settings ) {
    $cols = array (
        'type'            => $settings[ 'entity_type' ] . '::' . $settings[ 'bundle' ] ,
        'field'           => $settings[ 'field_name' ] ,
        'active_updating' => 0 ,
    );

    $cols[ 'filepath' ] = array (
        'value'         => $settings[ 'filepath' ] ,
        'tolower'       => $settings[ 'filepathtolower' ] ,
        'pathauto'      => $settings[ 'filepathpathauto' ] ,
        'transliterate' => $settings[ 'filepathtransliterate' ] ,
    );

    $cols[ 'filename' ] = array (
        'value'         => $settings[ 'filename' ] ,
        'tolower'       => $settings[ 'filenametolower' ] ,
        'pathauto'      => $settings[ 'filenamepathauto' ] ,
        'transliterate' => $settings[ 'filenametransliterate' ] ,
    );

    $results = db_select ( 'filefield_paths' , 'f' )
        ->fields ( 'f' )
        ->condition ( 'type' , $cols[ 'type' ] )
        ->condition ( 'field' , $cols[ 'field' ] )
        ->execute ()
        ->fetchAll ();

    // Update existing entry.
    if ( ! empty( $results ) ) {
        drupal_write_record ( 'filefield_paths' , $cols , array ( 'type' , 'field' ) );
    }
    // Create new entry.
    else {
        drupal_write_record ( 'filefield_paths' , $cols );
    }

}

Comments

deciphered’s picture

Status: Active » Fixed

They should already have been being exported when using Features, however I have just done a fairly sizeable re-write so that the settings are now correctly and only stored in the fields instance settings, and I can confirm that it works correctly with field_create_instance().

Dev build should be available in the next 12 hours.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.