first import
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
name = "File Entity Test"
|
||||
description = "Support module for File Entity tests."
|
||||
package = Testing
|
||||
core = 7.x
|
||||
dependencies[] = file_entity
|
||||
hidden = TRUE
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-03-23
|
||||
version = "7.x-1.0"
|
||||
core = "7.x"
|
||||
project = "media"
|
||||
datestamp = "1332537952"
|
||||
|
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* File Entity Test
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_menu().
|
||||
*/
|
||||
function file_entity_test_menu() {
|
||||
$items = array();
|
||||
|
||||
$items['file-entity-test/file/add'] = array(
|
||||
'title' => 'Add file',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('file_entity_test_add_form'),
|
||||
'access arguments' => array('administer site configuration'),
|
||||
'file' => 'file_entity_test.pages.inc',
|
||||
);
|
||||
$items['file-entity-test/file/%file'] = array(
|
||||
'title' => 'View file',
|
||||
'page callback' => 'file_entity_test_view_page',
|
||||
'page arguments' => array(2),
|
||||
'access arguments' => array('administer site configuration'),
|
||||
'file' => 'file_entity_test.pages.inc',
|
||||
);
|
||||
$items['file-entity-test/file/%file/view'] = array(
|
||||
'title' => 'View',
|
||||
'type' => MENU_DEFAULT_LOCAL_TASK,
|
||||
'weight' => -10,
|
||||
);
|
||||
$items['file-entity-test/file/%file/preview'] = array(
|
||||
'title' => 'Preview',
|
||||
'page callback' => 'file_entity_test_preview_page',
|
||||
'page arguments' => array(2),
|
||||
'access arguments' => array('administer site configuration'),
|
||||
'weight' => 0,
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
'file' => 'file_entity_test.pages.inc',
|
||||
);
|
||||
$items['file-entity-test/file/%file/edit'] = array(
|
||||
'title' => 'Edit',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('file_entity_test_edit_form', 2),
|
||||
'access arguments' => array('administer site configuration'),
|
||||
'weight' => 1,
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
'file' => 'file_entity_test.pages.inc',
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_file_type_info().
|
||||
*/
|
||||
function file_entity_test_file_type_info() {
|
||||
return array(
|
||||
'file_entity_test' => array(
|
||||
'label' => t('Test'),
|
||||
'description' => t('A file type defined by the File Entity Test module. Used for testing only.'),
|
||||
'claim callback' => 'file_entity_test_file_type_file_entity_test_claim',
|
||||
'default view callback' => 'file_entity_test_file_type_file_entity_test_default_view',
|
||||
'weight' => 100,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_file_type_TYPE_claim().
|
||||
*
|
||||
* Returns TRUE if the passed in file should be assigned the 'file_entity_test'
|
||||
* file type.
|
||||
*/
|
||||
function file_entity_test_file_type_file_entity_test_claim($file) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_file_type_TYPE_default_view().
|
||||
*/
|
||||
function file_entity_test_file_type_file_entity_test_default_view($file, $view_mode, $langcode) {
|
||||
return array(
|
||||
'#type' => 'link',
|
||||
'#title' => $file->filename,
|
||||
'#href' => file_create_url($file->uri),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_info_alter().
|
||||
*/
|
||||
function file_entity_test_entity_info_alter(&$entity_info) {
|
||||
$entity_info['file']['view modes']['file_entity_test_preview'] = array(
|
||||
'label' => t('Test Preview'),
|
||||
'custom settings' => TRUE,
|
||||
);
|
||||
}
|
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Test pages for the File Entity Test module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form callback; upload a file.
|
||||
*/
|
||||
function file_entity_test_add_form($form, &$form_state) {
|
||||
$form['file'] = array(
|
||||
'#type' => 'managed_file',
|
||||
'#required' => TRUE,
|
||||
'#title' => 'File',
|
||||
'#upload_location' => 'public://',
|
||||
);
|
||||
$form['actions'] = array('#type' => 'actions');
|
||||
$form['actions']['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Save'),
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form submit callback; save the uploaded file.
|
||||
*/
|
||||
function file_entity_test_add_form_submit($form, &$form_state) {
|
||||
$file = file_load($form_state['values']['file']);
|
||||
if (!$file->status) {
|
||||
$file->status = FILE_STATUS_PERMANENT;
|
||||
file_save($file);
|
||||
}
|
||||
drupal_set_message(t('Your file has been saved.'));
|
||||
$form_state['redirect'] = 'file-entity-test/file/' . $file->fid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Page callback; view a file.
|
||||
*/
|
||||
function file_entity_test_view_page($file) {
|
||||
return file_view($file, 'default');
|
||||
}
|
||||
|
||||
/**
|
||||
* Page callback; preview a file.
|
||||
*/
|
||||
function file_entity_test_preview_page($file) {
|
||||
return file_view($file, 'file_entity_test_preview');
|
||||
}
|
||||
|
||||
/**
|
||||
* Form callback; edit a file.
|
||||
*/
|
||||
function file_entity_test_edit_form($form, &$form_state, $file) {
|
||||
$form_state['file'] = $file;
|
||||
field_attach_form('file', $file, $form, $form_state);
|
||||
$form['file'] = file_view($file, 'file_entity_test_preview');
|
||||
|
||||
// Add internal file properties needed by
|
||||
// file_entity_test_edit_form_validate().
|
||||
foreach (array('fid', 'type') as $key) {
|
||||
$form[$key] = array('#type' => 'value', '#value' => $file->$key);
|
||||
}
|
||||
|
||||
$form['actions'] = array('#type' => 'actions');
|
||||
$form['actions']['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Save'),
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form validation handler for the file edit form.
|
||||
*/
|
||||
function file_entity_test_edit_form_validate($form, &$form_state) {
|
||||
entity_form_field_validate('file', $form, $form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Form submit handler for the file edit form
|
||||
*/
|
||||
function file_entity_test_edit_form_submit($form, &$form_state) {
|
||||
$file = $form_state['file'];
|
||||
entity_form_submit_build_entity('file', $file, $form, $form_state);
|
||||
file_save($file);
|
||||
drupal_set_message(t('Your changes to the file have been saved.'));
|
||||
$form_state['redirect'] = 'file-entity-test/file/' . $file->fid;
|
||||
}
|
Reference in New Issue
Block a user