Skip to content

Instantly share code, notes, and snippets.

@zviryatko
Last active August 29, 2015 14:26
Show Gist options
  • Save zviryatko/1aacdc72d53b9fa2870c to your computer and use it in GitHub Desktop.
Save zviryatko/1aacdc72d53b9fa2870c to your computer and use it in GitHub Desktop.
Drupal: filefield_sources + visual_select_file + multiupload_imagefield_widget = ❤️, see https://makeyoulivebetter.org.ua/node/625
.filefield-source.filefield-source-reference {
float: right;
overflow: hidden;
}
.filefield-source.filefield-source-reference > .form-item {
padding: 0;
}
name = Fix Image Uploader
description = This module make possible using of filefield_sources + visual_select_file + multiupload_image_widget.
core = 7.x
package = MakeYouLiveBetter
<?php
/**
* @file
* fix_image_uploader module file.
*/
/**
* Implements hook_block_list_alter().
*
* Hide all blocks and drupalchat popup from visual file select pop-up.
*/
function fix_image_uploader_block_list_alter(&$blocks) {
if (current_path() === 'admin/visual_select_file') {
foreach ($blocks as $block) {
if (!($block->module === 'system' && $block->delta === 'main')) {
unset($blocks[$block->bid]);
}
}
}
elseif (module_exists('drupalchat') && function_exists('drupalchat_init')) {
drupalchat_init();
}
}
/**
* Implements hook_module_implements_alter().
*
* Remove drupalchat init hook to prevent it run from all pages.
*/
function fix_image_uploader_module_implements_alter(&$implementations, $hook) {
if ($hook == 'init' && module_exists('drupalchat')) {
unset($implementations['drupalchat']);
}
}
/**
* Implements hook_preprocess_HOOK().
*
* Hide admin toolbar from visual file select pop-up.
*/
function fix_image_uploader_preprocess_html(&$variables) {
if (current_path() === 'admin/visual_select_file' && isset($variables['page']['page_top']['toolbar'])) {
$variables['page']['page_top']['toolbar']['#access'] = FALSE;
}
}
/**
* Implements hook_element_info_alter().
*
* Process multi-upload file widget with filefield_sources module.
*/
function fix_image_uploader_element_info_alter(&$type) {
$type['mfw_managed_file']['#process'][] = 'filefield_sources_field_process';
$type['mfw_managed_file']['#process'][] = 'visual_select_file_pre_render_filefield_sources_element';
$type['mfw_managed_file']['#process'][] = 'fix_image_uploader_filefield_sources_process';
$type['mfw_managed_file']['#pre_render'][] = 'filefield_sources_field_pre_render';
$type['mfw_managed_file']['#element_validate'][] = 'filefield_sources_field_validate';
$type['mfw_managed_file']['#file_value_callbacks'][] = 'filefield_sources_field_value';
}
/**
* Implements hook_filefield_sources_widgets().
*/
function fix_image_uploader_filefield_sources_widgets() {
return array('image_miw');
}
/**
* A #process callback to extend the filefield_widget element type.
*/
function fix_image_uploader_filefield_sources_process($element) {
// Hide filefield_sources tabs.
if (isset($element['filefield_sources_list'])) {
$element['filefield_sources_list']['#access'] = FALSE;
}
$element['#attached']['css'][] = drupal_get_path('module', 'fix_image_uploader') . '/fix_image_uploader.css';
return $element;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment