Hello,

I fixed the CCK allowed extension validate error. If I use the Asset Wizard, and I choose an mp3 file, using the mp3 formatter, Drupal shows the following error on Submit:
"The selected asset type is not allowed."

Here is the fix, please change to this in asset_content.inc:

function asset_field($op, &$node, $field, &$items, $teaser, $page) {
  switch ($op) {
    case 'validate':
      if ($field['allowed_extensions']) {
        $allowed_extensions = array_map('trim', explode(',', $field['allowed_extensions']));
      }
      
      foreach ($items as $delta => $item) {
        $error_field = $field['field_name'] .']['. $delta .'][aid';
        if (!$item['aid']) {
          continue;
        }
        //BEGIN FIX      
        //$asset = asset_load($item['aid']);
        if (is_numeric($item['aid'])) {
          $asset = asset_load($item['aid']);
        } else  {
          $macros = asset_get_macros($item['aid']);
          $macro = $macros[$item['aid']];        
          $aid = $macro['aid'];
          $asset = asset_load($aid);
        }
        //END FIX
        
        // make sure selected asset is allowed type
        if (is_array($field['allowed_types']) && !$field['allowed_types'][$asset->type]) {
          form_set_error($error_field, t('The selected asset type is not allowed.'));
        }
        
        // make sure selected asset is allowed extension
        if ($asset->type == 'file' && $allowed_extensions) {
          $info = pathinfo($asset->file['filename']);
          if (!in_array($info['extension'], $allowed_extensions)) {
            form_set_error($error_field, t('The selected asset is not one of the allowed extensions.'));
          }
        }
        
        // make sure asset supports one of the valid formatters
        if ($field['valid_formatters']) {
          $valid = FALSE;
          foreach ($field['valid_formatters'] as $format) {
            if ($asset->formatters[$format]) {
              $valid = TRUE;
              break;
            }
          }
          if (!$valid) {
            form_set_error($error_field, t('Asset does not support the specified formatters.'));
          }
        }
      }
      
      break;

    case 'view':
      break;
  }
}

Comments

zroger’s picture

Status: Needs review » Postponed (maintainer needs more info)

delykj, from this and some of your issues (#233390) it looks like you may be using some mix of the 1.0 and 2.0 versions. In the 2.0 version the asset cck field should only be using id's which explains the problem you are seeing here and in #233390.

please let me know more about the versions and evironment you are using.

delykj’s picture

Dear Roger,

I installed a fresh Drupal v5.7. I only installed Asset 5.x-2.0-beta1 (and the contrib bonus files), CCK and JQuery Update. I also fixed the 'mime_content_type ' bug in asset.types.inc. I'm using FireFox 2.0.0.13.
I added an Asset Wizard field to the Story content type. I configured the asset field to the following:
Allowed asset types:
- Directory option checked
- Files option checked

Allowed file extensions:
jpg,gif,png,mp3,flv

Valid formatters:
Selected all formatters.

The bugs are the following:
- The CCK Asset Wizard not shows the Assets if I click on the Browse link. The textarea (body) Asset Wizard shows the Assets.
- If I choose the MP3 Formatter in the Asset Wizards, the Preview step shows the following text: Audio placeholder. I fixed this bug in my previous issue.
- If I select a flv file, the "Select Format" step only allows to choose Link formatter. The flash video player not shows in the Preview step.

Thanks in advance,
Christopher

wmostrey’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

Asset 5.x-2 has been discontinued, please use 5.x-1.