示例#1
0
 /**
  * {@inheritdoc}
  */
 public function validateFeedForm(array &$form, FormStateInterface $form_state, FeedInterface $feed)
 {
     if (!$this->configuration['auto_detect_feeds']) {
         return;
     }
     try {
         $response = $this->get($form_state->getValue('source'));
     } catch (\RuntimeException $e) {
         $form_state->setError($form['source'], $e->getMessage());
         return;
     }
     if ($url = Feed::getCommonSyndication($response->getEffectiveUrl(), (string) $response->getBody())) {
         $form_state->setValue('source', $url);
     } else {
         $form_state->setError($form['source'], $this->t('Invalid feed URL.'));
     }
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 public function validateFeedForm(array &$form, array &$form_state, FeedInterface $feed)
 {
     $values =& $form_state['values']['fetcher'];
     $values['source'] = trim($values['source']);
     if (!Feed::validUrl($values['source'], TRUE)) {
         $form_key = 'feeds][' . get_class($this) . '][source';
         form_set_error($form_key, $this->t('The URL %source is invalid.', array('%source' => $values['source'])));
     } elseif ($this->configuration['auto_detect_feeds']) {
         $response = $this->get($values['source'], FALSE);
         if ($url = Feed::getCommonSyndication($values['source'], $response->getBody(TRUE))) {
             $values['source'] = $url;
         }
     }
 }