first import
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Argument handler to accept a file type.
|
||||
*/
|
||||
class views_handler_argument_file_type extends views_handler_argument_string {
|
||||
|
||||
/**
|
||||
* Override the behavior of summary_name(). Get the user friendly version
|
||||
* of the file type.
|
||||
*/
|
||||
function summary_name($data) {
|
||||
return $this->file_type($data->{$this->name_alias});
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the behavior of title(). Get the user friendly version of the
|
||||
* file type.
|
||||
*/
|
||||
function title() {
|
||||
return $this->file_type($this->argument);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to return the human-readable type of the file.
|
||||
*/
|
||||
function file_type($type) {
|
||||
$output = file_type_get_name($type);
|
||||
if (empty($output)) {
|
||||
$output = t('Unknown file type');
|
||||
}
|
||||
return check_plain($output);
|
||||
}
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Field handler to translate a file type into its readable form.
|
||||
*/
|
||||
class views_handler_field_file_type extends views_handler_field_file {
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['machine_name'] = array('default' => FALSE);
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide machine_name option for to file type display.
|
||||
*/
|
||||
function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
$form['machine_name'] = array(
|
||||
'#title' => t('Output machine name'),
|
||||
'#description' => t('Display field as the file type machine name.'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => !empty($this->options['machine_name']),
|
||||
'#fieldset' => 'more',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render file type as human readable name, unless using machine_name option.
|
||||
*/
|
||||
function render_name($data, $values) {
|
||||
if ($this->options['machine_name'] != 1 && $data !== NULL && $data !== '') {
|
||||
return t($this->sanitize_value(file_type_get_name($data)));
|
||||
}
|
||||
return $this->sanitize_value($data);
|
||||
}
|
||||
|
||||
function render($values) {
|
||||
$value = $this->get_value($values);
|
||||
return $this->render_link($this->render_name($value, $values), $values);
|
||||
}
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Filter by file type
|
||||
*/
|
||||
class views_handler_filter_file_type extends views_handler_filter_in_operator {
|
||||
function get_value_options() {
|
||||
if (!isset($this->value_options)) {
|
||||
$this->value_title = t('File types');
|
||||
$options = array();
|
||||
foreach (file_type_get_names() as $type => $name) {
|
||||
$options[$type] = t($name);
|
||||
}
|
||||
asort($options);
|
||||
$this->value_options = $options;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains the file view row style plugin.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugin which performs a file_view on the resulting object.
|
||||
*
|
||||
* Most of the code on this object is in the theme function.
|
||||
*/
|
||||
class views_plugin_row_file_view extends views_plugin_row {
|
||||
// Basic properties that let the row style follow relationships.
|
||||
var $base_table = 'file_managed';
|
||||
var $base_field = 'fid';
|
||||
|
||||
// Stores the files loaded with pre_render.
|
||||
var $files = array();
|
||||
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['view_mode'] = array('default' => 'default');
|
||||
$options['links'] = array('default' => TRUE);
|
||||
return $options;
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
$form['view_mode'] = array(
|
||||
'#type' => 'select',
|
||||
'#options' => file_entity_view_mode_labels(),
|
||||
'#title' => t('View mode'),
|
||||
'#default_value' => $this->options['view_mode'],
|
||||
);
|
||||
$form['links'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Display links'),
|
||||
'#default_value' => $this->options['links'],
|
||||
);
|
||||
}
|
||||
|
||||
function summary_title() {
|
||||
$view_mode_label = file_entity_view_mode_label($this->options['view_mode'], t('Unknown'));
|
||||
return check_plain($view_mode_label);
|
||||
}
|
||||
|
||||
function pre_render($values) {
|
||||
$fids = array();
|
||||
foreach ($values as $row) {
|
||||
$fids[] = $row->{$this->field_alias};
|
||||
}
|
||||
$this->files = file_load_multiple($fids);
|
||||
}
|
||||
|
||||
function render($row) {
|
||||
$file = $this->files[$row->{$this->field_alias}];
|
||||
$file->view = $this->view;
|
||||
$build = file_view($file, $this->options['view_mode']);
|
||||
|
||||
return drupal_render($build);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user