Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $config = $this->config('disqus.settings');
     $config->set('disqus_domain', $form_state->getValue('disqus_domain'))->set('behavior.disqus_localization', $form_state->getValue('disqus_localization'))->set('behavior.disqus_inherit_login', $form_state->getValue('disqus_inherit_login'))->set('behavior.disqus_disable_mobile', $form_state->getValue('disqus_disable_mobile'))->set('behavior.disqus_track_newcomment_ga', $form_state->getValue('disqus_track_newcomment_ga'))->set('advanced.disqus_useraccesstoken', $form_state->getValue('disqus_useraccesstoken'))->set('advanced.disqus_publickey', $form_state->getValue('disqus_publickey'))->set('advanced.disqus_secretkey', $form_state->getValue('disqus_secretkey'))->set('advanced.sso.disqus_sso', $form_state->getValue('disqus_sso'))->set('advanced.sso.disqus_use_site_logo', $form_state->getValue('disqus_use_site_logo'))->save();
     if ($form_state->hasValue('disqus_api_update')) {
         $config->set('advanced.api.disqus_api_update', $form_state->getValue('disqus_api_update'))->save();
     }
     if ($form_state->hasValue('disqus_api_delete')) {
         $config->set('advanced.api.disqus_api_delete', $form_state->getValue('disqus_api_delete'))->save();
     }
     $old_logo = $config->get('advanced.sso.disqus_logo');
     $new_logo = !$form_state->isValueEmpty('disqus_logo') ? $form_state->getValue(array('disqus_logo', 0)) : '';
     // Ignore if the file hasn't changed.
     if ($new_logo != $old_logo) {
         // Remove the old file and usage if previously set.
         if (!empty($old_logo)) {
             $file = $this->entityTypeManager->getStorage('file')->load($old_logo);
             $this->fileUsage->delete($file, 'disqus', 'disqus');
         }
         // Update the new file and usage.
         if (!empty($new_logo)) {
             $file = $this->entityTypeManager->getStorage('file')->load($new_logo);
             $this->fileUsage->add($file, 'disqus', 'disqus', 1);
         }
     }
     $config->set('advanced.sso.disqus_logo', $new_logo)->save();
     parent::submitForm($form, $form_state);
 }
Пример #2
0
 /**
  * {@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);
         }
     }
 }
Пример #3
0
 /**
  * {@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);
 }