I am working with files in a drupal module. I added this form
$form['Background_image'] = array(
'#type' => 'managed_file',
'#title' => t('Image'),
'#progress_message' => t('Please wait...'),
'#progress_indicator' => 'bar',
'#description' => t('Click "Browse..." to select an image to upload.'),
'#required' => TRUE,
'#upload_validators' => array('file_validate_extensions' => array('jpeg jpg png gif')),
'#upload_location' => 'public://backgroundimage/',
'#default_value' => $this->options['Background_image'],
);
the file is added properly, once the file is uploaded a remove button appears allwoing to remove the file and upload a new one.The problem is that this button is not working so I looked into file module and I found that the hook of removing a file is not implemented yet.
function file_file_delete($file) {
// TODO: Remove references to a file that is in-use.
}
How can I remove an uploade file?
you should use file_delete()
more description here: https://api.drupal.org/api/drupal/includes%21file.inc/function/file_delete/7
I will be able to help you more if you post here module version,
maybe it will start working after update :-)
Related
How can i disable the processing of images while element is being saved? when i edit the html of a text-element and add an image with a relative path, the editor creates an absolute path and furthermore processes the image. the image is copied to a new folder and the src-path is adjusted. i want to get rid of this behaviour. it this possible, so i can just set the src-attribute of the image and it will stay like that?
I'm using the extension "TinyMCE".
In the TCA of your extension, remove the configuration parameter 'uploadfolder'. This will lead to the behaviour that the file is referenced to the original location instead of being copied. See the TCA reference for more information.
The configuration might look like this:
'image' => array(
'exclude' => 0,
'label' => 'LLL:EXT:yourextension/Resources/Private/Language/locallang_db.xml:tx_yourextension_domain_model_yourmodel.image',
'config' => array(
'type' => 'group',
'internal_type' => 'file',
'show_thumbs' => 1,
'size' => 1,
'allowed' => $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'],
'disallowed' => '',
// removing/commentingthe next line will create a reference instead of copying the file
// 'uploadfolder' => 'uploads/tx_yourextension', //
),
),
I have a field in TCA with type group->file and I need to save the files in different directories depending on the year.
Usually when I need to pos-process any field I use the processDatamap_afterDatabaseOperations hook but it is not working properly with files.
This is what I'm doing.
function processDatamap_afterDatabaseOperations ($status, $table, $id, &$fieldArray, &$reference) {
if ($table=='tx_students' && isset($fieldArray['documents'])){
$path = $_SERVER['DOCUMENT_ROOT'].'/folder/';
$folder = date('Y').'/';
$filename = date('Y-m-d').' '.$student['first_name'].' '.$student['last_name'].'.zip';
$filename = str_replace(' ','_',$filename);
if (!file_exists($path.$folder)) {
mkdir($path.$folder, 0755, true);
$fh = fopen($path.$folder.'index.html','w+');
fclose($fh);
}
rename($path.$fieldArray['documents'],$path.$folder.$filename);
$GLOBALS['TYPO3_DB']->exec_UPDATEquery($table,'uid='.$student['uid'],array('documents'=>$folder.$filename));
}
}
I'm trying to store the filename in the DB with the folder path and that works well the first time I save the form. But the following times I get an error because TYPO3 can't find the file. It happens when I try to delete the file as well clicking in the x.
This is the TCA for that field:
'documents' => array(
'exclude' => 1,
'label' => '',
'config' => array(
'type' => 'group',
'internal_type' => 'file',
'allowed' => 'zip',
'max_size' => $GLOBALS['TYPO3_CONF_VARS']['BE']['maxFileSize'],
'uploadfolder' => 'uploads/incoming',
'show_thumbs' => 1,
'size' => 1,
'minitems' => 0,
'maxitems' => 1,
),
),
I want to have those files organized by year but I don't know how to do this in TYPO3. Is it another hook for doing this? It seems like TYPO3 was removing the part of the path before the slash for certain operations.
I'm working with TYPO3 4.5 LTS. Any suggestions?
upgrade to 6.2 beta
use fal
use the categories to sort / categorize your files.
The directories you are using are not intended to be used this way ;)
I'm using druapl 7 form to allow users to upload images for a slideshow. The managed file is working great to upload and save the files and I can see the entries in the database. All is good when nothing is there. But when the form is reloaded, I cannot get the the default value working for the uploaded image.
$form['slideshow_0_slide_0_fieldset']['slideshow_0_slide_0_image'] = array(
'#name' => "files[slideshow_0_slide_0_image]",
'#type' => 'managed_file',
'#size' => '25',
'#title' => t('Image 0'),
'#upload_location' => 'public://',
'#default_value' => variable_get( $managed_file_fid, '' )
);
I've also tried this without success:
'#default_value' => file_load( $managed_file_fid, '' )
What am I missing here to get the default value working?
There is a description by Robert Lausegger (iscon group) which made it possible to show prospect list in a subpanel in other modules. But since SugarCRM 6.3 this wasn't working anymore.
How to fix this?
The site referenced in the above link was in German, so, courtesy of the author of that site, Robert Laussegger of the iscon group (www.iscongroup.net) in Germany, here is the english language version of the method. I used this on SugarCRM CE v 6.5 running on a LAMP stack with CentOS 6.4 base and it worked fine. Adjust to your install as appropriate.
The example given shows how to add a Target List (called Prospect List internally with SugarCRM) to a Contact DetailView; adjust the settings for Leads, ...
If the directories shown do not exist, create them, being careful to match not only spelling but capitalization. You will be adding 3 files in 3 separate directories.
Remember to set the file permissions and owner/group to allow the server to access the files created.
When finished adding the files and setting the permissions, as a CRM administrator, run:
Admin -> Repair -> Rebuild Relationships (to flush cache)
Admin -> Repair -> Quick Repair and Rebuild
Create the following files in the directories shown:
In /var/www/html//custom/Extension/modules/Contacts/Ext/Language
-Create file en_us.prospectlist_in_contacts_language.php
and into the file put
(the part of the filename " prospectlist_in_contacts_language" can be whatever you want, as long as you use the prefix "en_us." (for US English language) and the suffix ".php")
<?php
$mod_strings['LBL_PROSPECTLISTS_CONTACTS_FROM_PROSPECTLISTS_TITLE'] = 'Target Lists';
?>
In /var/www/html//custom/Extension/modules/Contacts/Ext/Layoutdefs
Create file prospectlist_in_contacts_layoutdef.php
and into the file put
(the part of the filename " prospectlist_in_contacts_layoutdef" can be whatever you want, as long as you use the suffix ".php")
<?php
$layout_defs["Contacts"]["subpanel_setup"]["prospect_list_contacts"] = array (
'order' => 100,
'module' => 'ProspectLists',
'subpanel_name' => 'default',
'sort_order' => 'asc',
'sort_by' => 'id',
'title_key' => 'LBL_PROSPECTLISTS_CONTACTS_FROM_PROSPECTLISTS_TITLE',
'get_subpanel_data' => 'prospect_list_contacts',
'top_buttons' =>
array (
0 =>
array (
'widget_class' => 'SubPanelTopButtonQuickCreate',
),
1 =>
array (
'widget_class' => 'SubPanelTopSelectButton',
'mode' => 'MultiSelect',
),
),
);
?>
In /var/www/html//custom/Extension/modules/Contacts/Ext/Vardefs
Create file prospectlist_in_contacts_vardef.php
and into the file put
(the part of the filename " prospectlist_in_contacts_vardef" can be whatever you want, as long as you use the suffix ".php")
<?php
$dictionary["Contact"]["fields"]["prospect_list_contacts"] = array (
'name' => 'prospect_list_contacts',
'type' => 'link',
'relationship' => 'prospect_list_contacts',
'source' => 'non-db',
'vname' => 'LBL_PROSPECTLISTS_CONTACTS_FROM_PROSPECTLISTS_TITLE',
);
$dictionary["Contact"]["fields"]["prospect_list_name"] = array (
'name' => 'prospect_list_name',
'rname' => 'name',
'id_name' => 'prospect_list_id',
'vname' => 'LBL_PROSPECTLISTS_CONTACTS_FROM_PROSPECTLISTS_TITLE',
'type' => 'relate',
'link' => 'prospect_lists',
'table' => 'prospect_lists',
'isnull' => 'true',
'module' => 'ProspectLists',
'dbType' => 'char',
'len' => '255',
'source' => 'non-db',
);
?>
Reset owner/permissions
Run, as CRM administrator
Admin -> Repair -> Rebuild Relationships (to flush cache)
Admin -> Repair -> Quick Repair and Rebuild
The vardefs have to be changed to:
$dictionary["Lead"]["fields"]["prospect_lists"] = array(
'name' => 'prospect_lists',
and the layoutdefs
'get_subpanel_data' => 'prospect_lists',
This solves the problem.
I have a custom module with a content field (WYSIWYG editor)
When I select the insert image button, the following popup appears. For some reason the 'browse' button at the side of the Image URL has disappeared. Can someone point me in the right direction to get the image icon back? (what block/controller etc)
What is required when adding the full featured WYSIWYG editor to a custom magento module?
This is my form field element within Form.php (block)
$fieldset->addField('post_content', 'editor', array(
'name' => 'post_content',
'label' => Mage::helper('faqs')->__('Answer'),
'title' => Mage::helper('faqs')->__('Answer'),
'style' => 'width:700px; height:500px;',
'wysiwyg' => true,
));
Thank you.
Jonny
Had to find out the hard way, but the solution is quite simple:
Please check the permissions of your Role your Admin is in unser System=>Permissions=>Roles
There you can find in the Tab "Role Resources" the Checkbox "Media Gallery". Make sure this checkbox is ticked!
Then, clean cache, log out and in again and it should work.
Cheers!
I managed to sort this by adding some configuration options to the field,
Add the following code above the addField() of your WYSIWYG,
$configSettings = Mage::getSingleton('cms/wysiwyg_config')->getConfig(
array( 'add_widgets' => false, 'add_variables' => false, 'add_images' => false, 'files_browser_window_url'=> $this->getBaseUrl().'admin/cms_wysiwyg_images/index/'));
Once you've added the code, you need to add another param to the addField called 'config' calling your $configSettings variable.
$fieldset->addField('post_content', 'editor', array(
'name' => 'post_content',
'label' => Mage::helper('faqs')->__('Answer'),
'title' => Mage::helper('faqs')->__('Answer'),
'style' => 'width:700px; height:500px;',
'wysiwyg' => true,
'config' => $configSettings
));