function feed_import_feed_import_reader_info in Feed Import 8
Same name and namespace in other branches
- 7.3 feed_import.module \feed_import_feed_import_reader_info()
Implements hook_feed_import_reader_info().
File
- ./
feed_import.module, line 39 - User interface, cron functions for feed_import module.
Code
function feed_import_feed_import_reader_info() {
$items = array();
$stream = array(
'#type' => 'textarea',
'#title' => t('Stream context options'),
'#description' => t('You can set string context options in JSON format.') . ' ' . t('For more info check %link', array(
'%link' => \Drupal::l('stream_context_create()', \Drupal\Core\Url::fromUri('http://www.php.net/manual/en/function.stream-context-create.php')),
)),
'#element_validate' => array(
'feed_import_element_validate_json',
),
);
$sxeclass = array(
'#type' => 'textfield',
'#title' => t('SimpleXMLElement class'),
'#default_value' => 'SimpleXMLElement',
'#required' => TRUE,
'#element_validate' => array(
'feed_import_element_validate_simplexmlclass',
),
);
if (!defined('LIBXML_PARSEHUGE')) {
define('LIBXML_PARSEHUGE', 524288);
}
$parent_xpath = array(
'#type' => 'textfield',
'#title' => t('Parent XPATH, this is the context for desired items'),
'#description' => t('All field paths must be relative to parent.'),
'#maxlength' => 1024,
'#required' => TRUE,
);
$libxml = array(
'#type' => 'select',
'#multiple' => TRUE,
'#title' => t('LibXml options'),
'#description' => t('Select desired libxml options.') . ' ' . t('For more info check %link', array(
'%link' => \Drupal::l('libxml options', Url::fromUri('http://www.php.net/manual/en/libxml.constants.php')),
)),
'#default_value' => array(
LIBXML_NOBLANKS,
LIBXML_NOCDATA,
),
'#size' => 6,
'#options' => array(
LIBXML_NOBLANKS => t('Remove blank nodes'),
LIBXML_NOCDATA => t('Merge CDATA as text nodes'),
LIBXML_NOENT => t('Substitute entities'),
LIBXML_PARSEHUGE => t('Parse huge'),
LIBXML_XINCLUDE => t('Implement XInclude substitution'),
LIBXML_NOERROR => t('No error reports'),
LIBXML_NOWARNING => t('No warning reports'),
),
);
$raw = array(
'#type' => 'textarea',
'#title' => t('Raw source string'),
'#description' => t('You can use this source for tests if you remove the URL.'),
'#default_value' => '',
);
$items['xml'] = array(
'name' => t('XML Document'),
'description' => t('Use this reader when the XML file is not huge.') . ' ' . t('Paths must be in XPATH 1.0 format.'),
'inherit_options' => FALSE,
'class' => 'Drupal\\feed_import_base\\SimpleXMLFIReader',
'options' => array(
'url' => array(
'#type' => 'textfield',
'#title' => t('URL to a valid XML resource'),
'#description' => t('You can also use local filesystem paths.'),
'#maxlength' => 1024,
),
'parent' => $parent_xpath,
'class' => $sxeclass,
'options' => $libxml,
'namespaces' => array(
'#type' => 'textarea',
'#title' => t('Register namespaces for XML (only for XMLs having namespaces)'),
'#description' => t('Each namespace must be on a line in the following format: name=URI'),
),
'stream' => $stream,
'raw' => $raw,
),
);
$items['xml-chunked'] = array(
'name' => t('XML Chunked'),
'description' => t('Use this reader when the XML file is huge.') . ' ' . t('Paths must be in XPATH 1.0 format.'),
'inherit_options' => FALSE,
'class' => 'Drupal\\feed_import_base\\ChunkedXMLFIReader',
'options' => array(
'url' => array(
'#type' => 'textfield',
'#title' => t('URL to a valid XML resource'),
'#description' => t('You can also use local filesystem paths.'),
'#required' => TRUE,
'#maxlength' => 1024,
),
'parent' => $parent_xpath,
'size' => array(
'#type' => 'textfield',
'#title' => t('Chunk size in bytes'),
'#description' => t('How many bytes to read in each chunk.'),
'#default_value' => 8192,
'#size' => 10,
'#required' => TRUE,
'#element_validate' => array(
'element_validate_integer_positive',
),
),
'substr' => array(
'#type' => 'select',
'#title' => t('Substring function'),
'#description' => t('Which substring function to use.'),
'#options' => array(
'substr' => t('Default PHP substring'),
'mb_substr' => t('Multibyte PHP substring'),
'drupal_substr' => t('Drupal substring'),
),
'#default_value' => 'substr',
'#required' => TRUE,
),
'properties' => array(
'#type' => 'textfield',
'#title' => t('XML properties'),
'#description' => t('Change XML properties (like encoding).'),
'#default_value' => '<?xml version="1.0" encoding="utf-8"?>',
'#maxlength' => 1024,
'#element_validate' => array(
'feed_import_element_validate_xmldec',
),
),
'stream' => $stream,
'class' => $sxeclass,
),
);
$items['dom'] = array(
'name' => t('DomDocument XML/HTML'),
'description' => t('Use this reader for XML or HTML files.') . ' ' . t('Path must be in XPATH 1.0 format, but you can register PHP functions for XPATH.'),
'class' => 'Drupal\\feed_import_base\\DomXMLFIReader',
'inherit_options' => FALSE,
'options' => array(
'format' => array(
'#type' => 'select',
'#title' => t('Document format'),
'#options' => array(
'xml' => 'XML',
'html' => 'HTML',
),
'#default_value' => 'xml',
'#required' => TRUE,
),
'url' => array(
'#type' => 'textfield',
'#title' => t('URL to a valid XML/HTML resource'),
'#description' => t('You can also use local filesystem paths.'),
'#maxlength' => 1024,
),
'parent' => $parent_xpath,
'php_func' => array(
'#type' => 'textarea',
'#title' => t('Register php functions for XPATHs'),
'#description' => t('Use one function per line. You may use them in xpaths like this @xpath', array(
'@xpath' => '//book[php:functionString("substr", title, 0, 3) = "PHP"]',
)),
'#default_value' => '',
),
'namespaces' => array(
'#type' => 'textarea',
'#title' => t('Register namespaces for XML (only for XMLs having namespaces)'),
'#description' => t('Each namespace must be on a line in the following format: name=URI'),
),
'options' => $libxml,
'silence_load_errors' => array(
'#type' => 'checkbox',
'#title' => t('Silence load errors'),
'#description' => t('This will not report errors on document load.'),
'#default_value' => FALSE,
),
'strictErrorChecking' => array(
'#type' => 'checkbox',
'#title' => t('Strict error checking'),
'#description' => t('Throws DOM errors.'),
'#default_value' => FALSE,
),
'preserveWhiteSpace' => array(
'#type' => 'checkbox',
'#title' => t('Preserve whitespace'),
'#description' => t('Do not remove redundant white space.'),
'#default_value' => FALSE,
),
'resolveExternals' => array(
'#type' => 'checkbox',
'#title' => t('Resolve externals'),
'#description' => t('Load external entities from a doctype declaration.'),
'#default_value' => FALSE,
),
'recover' => array(
'#type' => 'checkbox',
'#title' => t('Recover'),
'#description' => t('Try to parse non-well formed documents.'),
'#default_value' => FALSE,
),
'normalizeDocument' => array(
'#type' => 'checkbox',
'#title' => t('Normalize document'),
'#description' => t('Putting the document in a "normal" form by simulating save and load.'),
'#default_value' => FALSE,
),
'stream' => $stream,
'raw' => $raw,
),
);
$items['sql'] = array(
'name' => t('SQL resultset'),
'description' => t('Use this reader for SQL resultset.') . ' ' . t('Paths must be column names.') . ' ' . t('You can group multiple paths using | (pipe).'),
'class' => 'Drupal\\feed_import_base\\SQLFIReader',
'inherit_options' => FALSE,
'options' => array(
'dsn' => array(
'#type' => 'textfield',
'#title' => t('Data Source Name'),
'#maxlength' => 1024,
'#description' => t('Required info to connect to the database.') . ' ' . t('For more info check %link', array(
'%link' => \Drupal::l('PDO', \Drupal\Core\Url::fromUri('http://www.php.net/manual/en/pdo.construct.php')),
)),
'#required' => TRUE,
),
'user' => array(
'#type' => 'textfield',
'#title' => t('Username'),
'#description' => t('Database username.'),
'#required' => TRUE,
),
'pass' => array(
'#type' => 'textfield',
'#title' => t('Password'),
'#description' => t('Database password.'),
),
'query' => array(
'#type' => 'textarea',
'#title' => t('SQL Query'),
'#description' => t('This SQL query must extract desired information for import. Use ? or :param_name as placeholder for params.'),
'#required' => TRUE,
),
'params' => array(
'#type' => 'textarea',
'#title' => t('Query params'),
'#description' => t('Params will be binded to query. Use one param per line.') . ' ' . t('Param format is :name=value (where :name is the placeholder) or simply value if you want to replace the ? placeholder.'),
),
),
);
$items['csv'] = array(
'name' => t('CSV file'),
'description' => t('Use this reader for CSV files.') . ' ' . t('Paths must be indexes or column names.') . ' ' . t('You can group multiple paths using | (pipe).'),
'inherit_options' => FALSE,
'class' => 'Drupal\\feed_import_base\\CSVFIReader',
'options' => array(
'url' => array(
'#type' => 'textfield',
'#title' => t('URL to a valid CSV resource'),
'#description' => t('You can also use local filesystem paths.'),
'#maxlength' => 1024,
'#required' => TRUE,
),
'use_column_names' => array(
'#type' => 'checkbox',
'#title' => t('Use column names for paths'),
'#description' => t('Use this only when the CSV have on the first line the column names.'),
'#default_value' => FALSE,
),
'length' => array(
'#type' => 'textfield',
'#title' => t('Line length'),
'#description' => t('This is only a hint.'),
'#required' => TRUE,
'#default_value' => 0,
'#element_validate' => array(
'element_validate_integer',
),
),
'delimiter' => array(
'#type' => 'textfield',
'#title' => t('Delimiter'),
'#description' => t('CSV delimiter char.'),
'#default_value' => ',',
'#maxlength' => 1,
'#size' => 1,
'#element_validate' => 'feed_import_element_validate_not_empty',
),
'enclosure' => array(
'#type' => 'textfield',
'#title' => t('Enclosure'),
'#description' => t('CSV enclosure char.'),
'#default_value' => '"',
'#maxlength' => 1,
'#size' => 1,
'#required' => TRUE,
),
'escape' => array(
'#type' => 'textfield',
'#title' => t('Escape'),
'#description' => t('CSV escape char.'),
'#default_value' => '\\',
'#maxlength' => 1,
'#size' => 1,
'#required' => TRUE,
),
'stream' => $stream,
),
);
$items['json'] = array(
'name' => t('JSON file'),
'description' => t('Use this reader for JSON files.') . ' ' . t('Path format is a/b/c.') . ' ' . t('You can group multiple paths using | (pipe).'),
'class' => 'Drupal\\feed_import_base\\JSONFIReader',
'inherit_options' => FALSE,
'options' => array(
'url' => array(
'#type' => 'textfield',
'#title' => t('URL to a valid JSON resource'),
'#description' => t('You can also use local filesystem paths.'),
'#maxlength' => 1024,
),
'parent' => array(
'#type' => 'textfield',
'#title' => t('Parent path, this is the context for desired items'),
'#description' => t('All field paths must be relative to parent.'),
'#maxlength' => 1024,
),
'stream' => $stream,
'raw' => $raw + array(
'#element_validate' => array(
'feed_import_element_validate_json',
),
),
),
);
return $items;
}