protected function ImportForm::importFromJson in Feed Import 8
Import a feed from a json file.
Parameters
string $json The JSON encoded feed configuration:
array $options An array of options to add to $json configuration:
bool $cleanup TRUE to reset import information:
Return value
mixed A feed configuration object on success or false on error
1 call to ImportForm::importFromJson()
- ImportForm::submitForm in src/
Form/ ImportForm.php - Form submission handler.
File
- src/
Form/ ImportForm.php, line 110 - Contains \Drupal\feed_import\Form\ImportForm
Class
Namespace
Drupal\feed_import\FormCode
protected function importFromJson($json, array $options = array(), $cleanup = TRUE, $keep_id = FALSE) {
if ($code = @json_decode($json, TRUE)) {
// Get an empty feed configuration.
$ef = FeedImport::getEmptyFeed();
// Add options.
$code = $options + $code;
// Add empty feed items.
$code += $ef;
// Add settings options if any.
if (!empty($options['settings'])) {
$code['settings'] = $options['settings'] + $code['settings'];
}
// Add empty feed settings.
$code['settings'] += $ef['settings'];
// Not needed anymore.
unset($json, $ef, $options);
if (!$keep_id) {
unset($code['id']);
}
// Convert to object.
$code = (object) $code;
// Cleanup import info.
if ($cleanup) {
$code->cron_import = 0;
$code->last_run = 0;
$code->last_run_duration = 0;
$code->last_run_items = 0;
}
// Check for group, if no group then use machine_name as group.
if (empty($code->settings['hashes']['options']['group'])) {
$code->settings['hashes']['options']['group'] = $code->machine_name;
}
// Save feed.
if (FeedImport::saveFeed($code)) {
return $code;
}
}
return FALSE;
}