Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Hi
Thanks alot this great module. I have a content type with a filefield and I would like to have that content type being saved immediately whenever a file has been uploaded. I tried with rules module and I couldn't get it worked. If possible can somebody please help me out to create that kind of rule.
Thanks
Hlan
Comment | File | Size | Author |
---|---|---|---|
#42 | file_events-826986-42.patch | 6.08 KB | Andras_Szilagyi |
| |||
#40 | file_events-826986-40.patch | 6.04 KB | Andras_Szilagyi |
| |||
#31 | file_events-826986-31.patch | 4.34 KB | Ace Cooper |
#30 | rules.rules_.inc_.rej_.txt | 580 bytes | melonangie |
#22 | file_events-826986-22.patch | 4.34 KB | paulihuhtiniemi |
Comments
Comment #1
mitchell CreditAttribution: mitchell commentedTo have this type of functionality in Drupal 7, there would need to be events, such as 'when file is uploaded' or 'when file is saved'. This would probably be part of a larger set of integrations, but if you would like to start, I believe the function you're looking for is file_save_upload().
For more information and a list of functions and methods in FIle API, see http://api.drupal.org/api/drupal/includes--file.inc/7
Comment #2
fagoIndeed, we should events just as for any other entity type too. Patch welcome.
Comment #3
stevectorHere is a starter patch in this direction.
It adds _insert, _presave, and _update events. There are plenty of other file related hooks that could also have events which I document in a @todo in this patch.
I also put a @todo in the comments for ules_file_integration_access(). I don't know what it does exactly. I copied and modified from node.rules.inc
fago, how much do you want done before a patch like this could go in? I'm sure there are also plenty of file related conditions that could go in a hook_file_rules_conditions_info()
Comment #5
stevectorI'm unsure if those test results mean that mailing breaks or that mailing for those events breaks.
Coincidentally I did my testing for those events with mail actions and a dsm() inside of drupal_mail() and they worked.
Here are the Rules I used:
Presave:
Insert:
Update:
Comment #6
mitchell CreditAttribution: mitchell commentedIssue to fix the broken test: #1540266: Fix broken simpletests.
Comment #7
Dave ReidThis hook should definitely be covered in the patch but isn't currently.
Comment #8
mitchell CreditAttribution: mitchell commentedMarked #1343788: Set a data value: add file to a node as a duplicate of this issue.
Comment #9
griz CreditAttribution: griz commentedFile Entity and Rules. I'm so excited that I'm going to apply the patch without backing anything up.
Comment #10
griz CreditAttribution: griz commentedIt's all good.
Needs work --> RTBMe
Comment #11
semei CreditAttribution: semei commentedIs this issue taken care of in 7.x-2.x-dev?
Comment #12
rlmumfordIs there any progress on this patch?
Comment #13
rodrigoaguileraI think this issue is about files in core and not about file entities (fieldable files), am I right?
Comment #14
Dave ReidCorrect, this is about the core file entity and not related to the file entity module in contrib that extends the core file entities.
Comment #15
rodrigoaguileraOk, I was confused because I don't quite understand the arquitecture of file_entity but this patch allowed me to trigger the event for when a file_entity is created and set values.
I understand that next thing to do to get this patch in stable is to solve issue #1540266 but another RTBMe here
Comment #16
rlmumford#3: file_events-826986-3.patch queued for re-testing.
Comment #17
fagoAs #7 said, file delete sounds reasonable to include with this patch. Let's add that before committing this.
It's used to check for non-super-admins whether they are allowed to use this events.
I think we could start with just the events and have more in follow-up issues. Unfortunately we do not have test-coverage for events yet, so we have to rely on manual tests only here :(
Comment #18
semei CreditAttribution: semei commentedAre there any news concerning this issue? I think thank file API events would be a great improvement of this module.
Comment #19
rogerpfaffThis patch fails in my installation of 7.x-2.x-dev
Comment #20
SocialNicheGuru CreditAttribution: SocialNicheGuru commentedthe patch no longer applies to the march 18, 2014 dev version
Comment #21
SocialNicheGuru CreditAttribution: SocialNicheGuru commenteddeleted comment. found out how to add fields: add the fields you want to the conditional area.
Comment #22
paulihuhtiniemi CreditAttribution: paulihuhtiniemi commentedHere's an updated version of the patch that should work with latest dev version. Didn't add any new events.
Comment #23
AjitSComment #24
AjitSThank you for the patch! I have confirmed the patch works for me without any issues. It's been long time on hold on a review; so being bold and marking it RTBC.
Comment #25
fagoIs file type there if file entity is not used? I don't think so?
Missing trailing point.
Let's open an issue for that but remove the comment. We do not have todos for adding new features else.
Missing trailing point.
It's called from the ui. should be fine, but comment nees to go.
Comment #26
mtoscano CreditAttribution: mtoscano commentedI tried the patch and actually it works, I can now receive an email notification when a new file is uploaded, thanks!
Anyway the event is triggered as soon as the file is uploaded and not once the file is saved. So for example using it in combination with Media module 2.x and File Entity, you cannot use tokens coming from file fields, as they are filled once the file has been uploaded and before saving the file.
Trigger the Action once the file entity is saved it will be a better option.
Comment #27
spgd01 CreditAttribution: spgd01 commentedany news on a commit?
Comment #28
drupalevangelist CreditAttribution: drupalevangelist commentedCould you commit the patch #22 to the latest dev release?
Comment #29
melonangie CreditAttribution: melonangie commentedApplied patch #22 to rules-7.x-2.x-dev, got this message.
Comment #30
melonangie CreditAttribution: melonangie commentedComment #31
Ace Cooper CreditAttribution: Ace Cooper as a volunteer commentedI needed this feature as well and I ran into the same problem with applying the patch. Here is quick fix for patch #22 to apply cleanly to latest rules-7.x-2.10, though without any new features. I will look into all fago's suggestions and include them in the next patch.
P.S. For anyone like me looking to attach the uploaded file to the entity image field via Rules with Set Data Value (which only accepts
field_item_image
) - try the wonderful module File System Rules. It provides a new action "Add file to the list" which is exactly what I needed. Don't forget to add another action to save your entity after you added the file to the list.Comment #32
NWOM CreditAttribution: NWOM commented#31 worked perfectly. Thank you!
Comment #33
TokiI am using the patch #31 and it's working great (see here details) Many thanks for that.
Now, I would really need a "When removing file from content" event.
Is it available somewhere or anyone knows how to fire a Rule when an image (file) is removed from an Image field (with multiple values)?
Another question here if you have any tip.
Thanks.
Comment #34
NWOM CreditAttribution: NWOM commented@Toki: You can compare the field value before/after as a condition. So have two conditions: "before: has value" and "after: empty" with each using the "compare" condition.
Comment #35
Toki@NWOM, do you mind elaborating your answer here or on Drupal Answers? I have tried to follow your suggestion but it is really tricky to build condition with File/Image fields. Thanks in advance.
Comment #36
TR CreditAttribution: TR commentedPatch in #31 still applies. BUT @fago's concerns from #25 were not addressed in the patch, so this is still "Needs work".
Likewise, testbot shows that the patch introduces 9 new coding standards violations. These should be fixed.
While the testbot shows that all the tests pass, that's not surprising because this patch doesn't test any of the new added features. There really should be tests to accompany these new features, especially this late in the D7 development cycle.
Comment #37
TokiI'm afraid the patch in #31 is broken since the last Drupal Core update. Could it be fixed @Ace Cooper? Thanks in advance
EDIT : my bad, it works, sorry for that...
Comment #38
Toki[SOLVED] Finally, it seems broken since the last Rules update (march 19). I have built a simple Rule based on After updating existing file and I can not access the file updated values anymore, only file_unchanged. To reproduce, simply create a Rule with event After updating existing file, add an action (for me Execute custom PHP code) and browse the replacement patterns or variables available, you should find only site and file_unchanged. I have tried with a Fetch entity by ID, using file_unchanged:ID but it did not work either. Any idea here?
EDIT : The Rules evaluation log displays : Unable to load variable file_unchanged, aborting
EDIT2 : after several tries, actually, I can not access the file values at all (type Image with custom fields) using the event After updating existing file. The variable file_unchanged (and I guess it should be possible with another variable called file as updated file) is not accessible and can not be loaded?
EDIT3 : finally, I found a mistake in my patch (probably entirely my fault), in file.rules.inc (line 64), $args += array was $args = array, in the section returning parameters (the famous file_unchanged).
Comment #39
shevgenyIs there any news in this area?
Comment #40
Andras_Szilagyi CreditAttribution: Andras_Szilagyi at Randstad Digital for European Commission and European Union Institutions, Agencies and Bodies commentedAttached patch that fixes issues mentioned in #25 and adds a test that asserts the new file events under class RulesTestCase.
Also fixed
Comment #41
TR CreditAttribution: TR commentedThank you. I will try to review this entire issue and take a look at the patch in detail over the next few days.
In regards to "Implements hook_rules_event_info() on behalf of the file module." ...
These hooks, in modules/*.rules.inc, are not exactly Drupal standard. For example, you can see that
rules_file_event_info()
does NOT implementhook_rules_event_info()
, because if it did the name would have to befile_rules_event_info()
instead. What is happening is that Rules is implementing that hook for the file module (because an implementation of a Rules hook cannot be put into a core Drupal module) and is using a different naming convention to distinguish this from a "true" hook and to prevent namespace conflict in the case where some other module wanted to add more file events.phpcs doesn't know about this - it thinks that this is a standard hook implementation and demands a standard hook comment. But this is not a standard hook implementation, and we've chosen to consistently document these hooks with a comment in the form "Implements hook_rules_event_info() on behalf of the file module." to point out this difference. I would like to keep it that way.
I don't want to change the documentation comment just to please phpcs. I guess we could just put in @codingStandardsIgnoreStart/@codingStandardsIgnoreEnd tags on all these, but I don't think it's worth the trouble.
My focus is on preventing NEW coding standards violations when committing patches. This patch adds 4:
Comment #42
Andras_Szilagyi CreditAttribution: Andras_Szilagyi at Randstad Digital for European Commission and European Union Institutions, Agencies and Bodies commentedThank you @TR for the explanation and the feedback, I fixed the mentioned issues.