You are here

function assets_override_form in Asset 7

Page callback for asset override form in wysiwyg.

1 string reference to 'assets_override_form'
asset_menu in ./asset.module
Implements hook_menu().

File

includes/asset.admin.inc, line 408
Asset admin page callbacks.

Code

function assets_override_form($form, &$form_state) {
  $options = array();
  if (isset($_REQUEST['tag']) && !empty($_REQUEST['tag'])) {
    $tag = $_REQUEST['tag'];
    $matches = assets_filter_get_matches($tag);
    if (!empty($matches)) {
      $match = reset($matches);
      $aid = (int) $match[2];
      $params = $match[3];
      $asset = asset_load($aid);
      $form_state['asset'] = $asset;
      $form_state['entity_type'] = 'asset';
      $form_state['build_info']['base_form_id'] = 'asset_base_form';
      $params = '{' . $params . '}';
      $options = json_decode($params, TRUE);
      if (is_array($options)) {
        $values = array_diff_key($options, array(
          'mode' => 1,
          'align' => 1,
        ));
        _assets_set_field_value($asset, $values);
      }
      else {
        $options = array();
      }
    }
  }
  elseif (isset($form_state['asset'])) {
    $asset = $form_state['asset'];
    $options = array(
      'mode' => !empty($form_state['input']['mode']) ? $form_state['input']['mode'] : FALSE,
      'align' => !empty($form_state['input']['align']) ? $form_state['input']['align'] : FALSE,
    );
  }
  if (isset($asset)) {
    field_attach_form('asset', $asset, $form, $form_state);
    _assets_in_editor_form_remove_non_overridable_fields($form);
    _assets_in_editor_form_add_default_fields($form, $asset, $options);
    $form['actions'] = array(
      '#type' => 'actions',
    );
    $form['actions']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Override'),
      '#weight' => 5,
    );
    $form['#submit'][] = 'assets_override_form_submit';
  }

  // @todo: Add validation handlers.
  return $form;
}