/** * {@inheritdoc} */ public function onFeedSave(FeedInterface $feed, $update) { // We are only interested in continuing if we came from a form submit. if (!$this->feedConfig) { return; } // New file found. if ($this->feedConfig['new_fid'] != $this->feedConfig['fid']) { $this->deleteFile($this->feedConfig['fid'], $feed->id()); if ($this->feedConfig['new_fid']) { $file = $this->fileStorage->load($this->feedConfig['new_fid']); $this->fileUsage->add($file, 'feeds', $this->pluginType(), $feed->id()); $file->setPermanent(); $file->save(); $this->feedConfig['fid'] = $this->feedConfig['new_fid']; $this->feedConfig['source'] = $file->getFileUri(); $feed->setConfigurationFor($this, $this->feedConfig); } } }
/** * {@inheritdoc} */ public function submitFeedForm(array &$form, FormStateInterface $form_state, FeedInterface $feed) { // We need to store this for later so that we have the feed id. $new_fid = reset($form_state->getValue('source')); $feed_config = $feed->getConfigurationFor($this); // Generate a UUID that maps to this feed for file usage. We can't depend // on the feed id since this could be called before an id is assigned. $feed_config['usage_id'] = $feed_config['usage_id'] ?: $this->uuid->generate(); if ($new_fid == $feed_config['fid']) { return; } $this->deleteFile($feed_config['fid'], $feed_config['usage_id']); if ($new_fid) { $file = $this->fileStorage->load($new_fid); $this->fileUsage->add($file, 'feeds', $this->pluginType(), $feed_config['usage_id']); $file->setPermanent(); $file->save(); $feed_config['fid'] = $new_fid; $feed->setSource($file->getFileUri()); } $feed->setConfigurationFor($this, $feed_config); }
/** * Stub for plugins implementing FeedPluginFormInterface. * * Most all plugins should get automatic submit handlers from this. * * @see \Drupal\feeds\Plugin\Type\FeedPluginFormInterface */ public function submitFeedForm(array &$form, array &$form_state, FeedInterface $feed) { if (isset($form_state['values'][$this->pluginType()])) { $feed->setConfigurationFor($this, $form_state['values'][$this->pluginType()]); } }
/** * Stub for plugins implementing FeedPluginFormInterface. * * Most all plugins should get automatic submit handlers from this. * * @see \Drupal\feeds\Plugin\Type\FeedPluginFormInterface */ public function submitFeedForm(array &$form, FormStateInterface $form_state, FeedInterface $feed) { $feed->setConfigurationFor($this, $form_state->getValues()); }