public function SampleDataLoader::loadSample in YAML Content 8.2
Load sample data based on type and additional parameters.
Parameters
string $data_type: The type of sample data to be loaded. This is used to determine functions and/or plugins to be loaded and used.
array $params: Configuration parameters to be passed through to the content plugin.
Return value
mixed|false The loaded sample data item or FALSE if unable to load.
File
- modules/
sample_data/ src/ SampleDataLoader.php, line 72
Class
- SampleDataLoader
- Provides methods for retrieving sample data to be used in demo content.
Namespace
Drupal\sample_dataCode
public function loadSample($data_type, array $params = []) {
$sample = FALSE;
$plugin = $this
->loadPluginByDataType($data_type, $params);
if ($plugin) {
return $plugin
->execute();
}
switch ($data_type) {
case 'term':
$sample = $this
->getTerm($params['name'], $params['vocabulary']);
break;
case 'short_text':
$sample = $this
->getLipsum(20);
break;
case 'rich_text':
// @todo Support addition of markup.
$sample = $this
->getLipsum(200);
break;
case 'image':
// @todo Handle missing width and height parameters.
$sample = $this
->getImage($params['width'], $params['height']);
break;
case 'file':
$sample = $this
->getFile($params['path'], $params['src']);
break;
default:
}
return $sample;
}