Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I found this bad practice in the OpmlFeedAdd.php
public function submitForm(array &$form, FormStateInterface $form_state) {
$validators = array('file_validate_extensions' => array('opml xml'));
if ($file = file_save_upload('upload', $validators, FALSE, 0)) {
$data = file_get_contents($file->getFileUri());
}
## Proposed change
Add in the field the validator and check it in the validateForm
Comment | File | Size | Author |
---|---|---|---|
#8 | 2702475-8.patch | 1.17 KB | Saphyel |
#7 | interdiff_2702475_5-7.patch | 770 bytes | Saphyel |
#5 | 2702475-5.patch | 538 bytes | felribeiro |
Comments
Comment #2
felribeiro CreditAttribution: felribeiro at CI&T commentedComment #3
felribeiro CreditAttribution: felribeiro at CI&T commentedI added the field validator, but I don't know about the validador.
@Saphyel, your suggestion is to bring all this code to the form validation?
Comment #4
joshi.rohit100white space
Comment #5
felribeiro CreditAttribution: felribeiro at CI&T commentedComment #6
Saphyel CreditAttribution: Saphyel as a volunteer commentedfelribeiro well done! I'm gonna complete it
Comment #7
Saphyel CreditAttribution: Saphyel as a volunteer commentedAlso this can be cherry-pick to 8.0.x or 8.2.x
Comment #8
Saphyel CreditAttribution: Saphyel as a volunteer commentedwrong file
Comment #12
dpacassiRemoving the
Novice
tag as the code changes seem to be quite advanced.There's someone with experience needed to review this patch.
Comment #13
dpacassiUpdating the issue title to something more specific.
Comment #14
mmrares CreditAttribution: mmrares commentedPlease provide a better summary on why this is a bad practice.
Comment #23
quietone CreditAttribution: quietone at PreviousNext commentedThe
aggregator
module has been removed from Core in10.0.x-dev
and now lives on as a contrib module. Issues in the Core queue about theaggregator
module, like this one, have been moved to the contrib module queue.Comment #24
larowlanWe're in 'keep the lights on mode' now this is out of core.
You probably don't want to upload a file in a validation handler, in case another handler indicates it was invalid.
I think validating file uploads in submit handlers is a pretty wide-spread practice.