Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function getCacheTags()
 {
     $cache_tags = parent::getCacheTags();
     $feed = $this->feedStorage->load($this->configuration['feed']);
     $cache_tags = NestedArray::mergeDeep($cache_tags, $feed->getCacheTag());
     return $cache_tags;
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 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());
     } else {
         // @todo Move this to a fetcher implementation.
         try {
             $response = $this->httpClient->get($form_state->getValue('remote'));
             $data = (string) $response->getBody();
         } catch (RequestException $e) {
             $this->logger('aggregator')->warning('Failed to download OPML file due to "%error".', array('%error' => $e->getMessage()));
             drupal_set_message($this->t('Failed to download OPML file due to "%error".', array('%error' => $e->getMessage())));
             return;
         }
     }
     $feeds = $this->parseOpml($data);
     if (empty($feeds)) {
         drupal_set_message($this->t('No new feed has been added.'));
         return;
     }
     // @todo Move this functionality to a processor.
     foreach ($feeds as $feed) {
         // Ensure URL is valid.
         if (!UrlHelper::isValid($feed['url'], TRUE)) {
             drupal_set_message($this->t('The URL %url is invalid.', array('%url' => $feed['url'])), 'warning');
             continue;
         }
         // Check for duplicate titles or URLs.
         $query = $this->feedStorage->getQuery();
         $condition = $query->orConditionGroup()->condition('title', $feed['title'])->condition('url', $feed['url']);
         $ids = $query->condition($condition)->execute();
         $result = $this->feedStorage->loadMultiple($ids);
         foreach ($result as $old) {
             if (strcasecmp($old->label(), $feed['title']) == 0) {
                 drupal_set_message($this->t('A feed named %title already exists.', array('%title' => $old->label())), 'warning');
                 continue 2;
             }
             if (strcasecmp($old->getUrl(), $feed['url']) == 0) {
                 drupal_set_message($this->t('A feed with the URL %url already exists.', array('%url' => $old->getUrl())), 'warning');
                 continue 2;
             }
         }
         $new_feed = $this->feedStorage->create(array('title' => $feed['title'], 'url' => $feed['url'], 'refresh' => $form_state->getValue('refresh')));
         $new_feed->save();
     }
     $form_state->setRedirect('aggregator.admin_overview');
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function getCacheTags()
 {
     $cache_tags = parent::getCacheTags();
     $feed = $this->feedStorage->load($this->configuration['feed']);
     return Cache::mergeTags($cache_tags, $feed->getCacheTags());
 }