/** * {@inheritdoc} */ public function buildFeedForm(array $form, FormStateInterface $form_state, FeedInterface $feed) { $feed_config = $feed->getConfigurationFor($this); $form['parser']['#tree'] = TRUE; $form['parser']['#weight'] = -10; $form['parser']['delimiter'] = ['#type' => 'select', '#title' => $this->t('Delimiter'), '#description' => $this->t('The character that delimits fields in the CSV file.'), '#options' => [',' => ',', ';' => ';', 'TAB' => 'TAB', '|' => '|', '+' => '+'], '#default_value' => $feed_config['delimiter']]; $form['parser']['no_headers'] = ['#type' => 'checkbox', '#title' => $this->t('No Headers'), '#description' => $this->t("Check if the imported CSV file does not start with a header row. If checked, mapping sources must be named '0', '1', '2' etc."), '#default_value' => $feed_config['no_headers']]; return $form; }
/** * {@inheritdoc} */ public function buildFeedForm(array $form, array &$form_state, FeedInterface $feed) { $this->feedConfig = $feed->getConfigurationFor($this); $form['fetcher']['#tree'] = TRUE; $form['fetcher']['upload'] = array('#type' => 'managed_file', '#title' => $this->t('File'), '#description' => $this->t('Select a file from your local system.'), '#default_value' => array($this->feedConfig['fid']), '#upload_validators' => array('file_validate_extensions' => array($this->configuration['allowed_extensions'])), '#upload_location' => $this->configuration['directory'], '#required' => TRUE); return $form; }
/** * {@inheritdoc} * * @todo Refactor this like woah. */ public function onFeedSave(FeedInterface $feed, $update) { if (!$this->configuration['use_pubsubhubbub']) { return; } $feed_config = $feed->getConfigurationFor($this); $item = array('type' => $this->getPluginId(), 'id' => $feed->id()); // Subscription does not exist yet. if (!($subscription = $this->subscription->getSubscription($feed->id()))) { $sub = array('id' => $feed->id(), 'state' => 'unsubscribed', 'hub' => '', 'topic' => $feed_config['source']); $this->subscription->setSubscription($sub); // Subscribe to new topic. $this->subscribeQueue->createItem($item); } elseif ($subscription['topic'] !== $feed_config['source']) { // Subscribe to new topic. $this->subscribeQueue->createItem($item); // Unsubscribe from old topic. $item['data'] = $subscription['topic']; $this->unsubscribeQueue->createItem($item); // Save new topic to subscription. $subscription['topic'] = $feed_config['source']; $this->subscription->setSubscription($subscription); } elseif ($subscription['hub']) { switch ($subscription['state']) { // Don't do anything if we are in the process of subscribing. case 'subscribe': case 'subscribed': break; default: $this->subscribeQueue->createItem($item); break; } } }
/** * {@inheritdoc} */ public function buildFeedForm(array $form, array &$form_state, FeedInterface $feed) { $feed_config = $feed->getConfigurationFor($this); $form['parser']['#tree'] = TRUE; $form['parser']['#weight'] = -10; $mappings = $this->importer->getMappings(); // $feeds = $uniques = array(); // foreach ($mappings as $mapping) { // $feeds[] = check_plain($mapping['source']); // if (!empty($mapping['unique'])) { // $uniques[] = check_plain($mapping['source']); // } // } // $output = $this->t('Import !csv_files with one or more of these columns: !columns.', array( // '!csv_files' => l($this->t('CSV files'), 'http://en.wikipedia.org/wiki/Comma-separated_values'), // '!columns' => implode(', ', $feeds), // )); // $items = array(); // $items[] = format_plural(count($uniques), $this->t('Column <strong>!column</strong> is mandatory and considered unique: only one item per !column value will be created.', array('!column' => implode(', ', $uniques))), $this->t('Columns <strong>!columns</strong> are mandatory and values in these columns are considered unique: only one entry per value in one of these column will be created.', array('!columns' => implode(', ', $uniques)))); // $items[] = l($this->t('Download a template'), 'import/' . $this->importer->id() . '/template'); // $form['parser']['help'] = array( // '#prefix' => '<div class="help">', // '#suffix' => '</div>', // 'description' => array( // '#prefix' => '<p>', // '#markup' => $output, // '#suffix' => '</p>', // ), // 'list' => array( // '#theme' => 'item_list', // '#items' => $items, // ), // ); $form['parser']['delimiter'] = array('#type' => 'select', '#title' => $this->t('Delimiter'), '#description' => $this->t('The character that delimits fields in the CSV file.'), '#options' => array(',' => ',', ';' => ';', 'TAB' => 'TAB', '|' => '|', '+' => '+'), '#default_value' => isset($feed_config['delimiter']) ? $feed_config['delimiter'] : ','); $form['parser']['no_headers'] = array('#type' => 'checkbox', '#title' => $this->t('No Headers'), '#description' => $this->t('Check if the imported CSV file does not start with a header row. If checked, mapping sources must be named \'0\', \'1\', \'2\' etc.'), '#default_value' => isset($feed_config['no_headers']) ? $feed_config['no_headers'] : 0); return $form; }
/** * {@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); }