public function bind(array $taintedValues = null, array $taintedFiles = null) { $taintedValues['url'] = transliteration_clean_filename($taintedValues['title'], 'hun'); $taintedValues['displayHomeworkForm'] = isset($taintedValues['displayHomeworkForm']); parent::bind($taintedValues, $taintedFiles); }
/** * Returns a Drupal file object of the enclosed resource. * * @param string $destination * The path or uri specifying the target directory in which the file is * expected. Don't use trailing slashes unless it's a streamwrapper scheme. * @param int $replace * (optional) Replace behavior when the destination file already exists: * - FILE_EXISTS_REPLACE - Replace the existing file. If a managed file with * the destination name exists then its database entry will be updated. * If no database entry is found then a new one will be created. * - FILE_EXISTS_RENAME - Append _{incrementing number} until the filename * is unique. * - FILE_EXISTS_ERROR - Do nothing and return FALSE. * Defaults to FILE_EXISTS_RENAME. * * @return \Drupal\file\Entity\FileInterface * A Drupal temporary file object of the enclosed resource. * * @throws \RuntimeException * If file object could not be created. * * @todo Refactor this */ public function getFile($destination, $replace = FILE_EXISTS_RENAME) { $file = FALSE; if (!$this->uri) { return $file; } // Prepare destination directory. file_prepare_directory($destination, FILE_MODIFY_PERMISSIONS | FILE_CREATE_DIRECTORY); // Copy or save file depending on whether it is remote or local. if (drupal_realpath($this->uri)) { $file = entity_create('file', ['uid' => 0, 'uri' => $this->uri, 'filemime' => $this->mimeType, 'filename' => basename($this->uri)]); if (drupal_dirname($file->getFileUri()) != $destination) { $file = file_copy($file, $destination, $replace); } else { // If file is not to be copied, check whether file already exists, // as file_save() won't do that for us (compare file_copy() and // file_save()) $existing_files = file_load_multiple([], ['uri' => $file->getFileUri()]); if ($existing_files) { return reset($existing_files); } $file->save(); } } else { $filename = drupal_basename($this->uri); if (\Drupal::moduleHandler()->moduleExists('transliteration')) { require_once drupal_get_path('module', 'transliteration') . '/transliteration.inc'; $filename = transliteration_clean_filename($filename); } if (file_uri_target($destination)) { $destination = trim($destination, '/') . '/'; } try { $file = file_save_data($this->getContent(), $destination . $filename, $replace); } catch (\Exception $e) { watchdog_exception('Feeds', $e, nl2br(SafeMarkup::checkPlain($e))); } } // We couldn't make sense of this enclosure, throw an exception. if (!$file) { throw new \RuntimeException(SafeMarkup::format('Invalid enclosure %enclosure', ['%enclosure' => $this->uri])); } return $file; }
public function bind(array $taintedValues = null, array $taintedFiles = null) { $taintedValues['url'] = transliteration_clean_filename($taintedValues['title'], 'hun'); parent::bind($taintedValues, $taintedFiles); }