Skip to content

Make icon file permanent #16

@RAFA3L

Description

@RAFA3L

Hello, I'm using the module with the paragraph module and for a few days I notice that the icon file disappears suddenly, then I can see that the file disappears from the database too because was saved with status = 0.

I fix it using this code

`
/**

  • Implements hook_form_FORM_ID_alter().
    */
    function view_mode_selector_form_field_ui_field_edit_form_alter(&$form, &$form_state, $form_id) {
    if ($form['#field']['type'] == 'view_mode_selector') {
    array_unshift($form['#submit'], 'view_mode_selector_settings_form_submit'); // <---- added
    // Don't allow more than one value for a view mode selector field.
    $form['field']['cardinality']['#access'] = FALSE;
    $form['field']['cardinality']['#value'] = 1;
    }
    }
    `

and

`
/**

  • Custom form submit handler
    */
    function view_mode_selector_settings_form_submit($form, &$form_state) {
    foreach ($form_state['values']['instance']['settings']['view_modes'] as $view_mode => $element) {
    if (!empty($element['icon'])) {
    $icon = file_load($element['icon']);
    if ($icon) {
    // make image file permanent
    $icon->status = FILE_STATUS_PERMANENT;
    file_save($icon);
    }
    }
    }
    }
    `

More information here

https://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7.x/#managed_file

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions