Commit cdbea077 authored by moshe weitzman's avatar moshe weitzman

Use exceptions instead of drush_set_error().

parent a2efa15f
......@@ -14,6 +14,7 @@ use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Routing\UrlGeneratorInterface;
use Drupal\devel_generate\DevelGenerateBase;
use Drupal\field\Entity\FieldConfig;
use Drush\Utils\StringUtils;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -343,7 +344,7 @@ class ContentDevelGenerate extends DevelGenerateBase implements ContainerFactory
$operations[] = array('devel_generate_operation', array($this, 'batchContentAddNode', $values));
}
// Start the batch.
// Set the batch.
$batch = array(
'title' => $this->t('Generating Content'),
'operations' => $operations,
......@@ -386,27 +387,27 @@ class ContentDevelGenerate extends DevelGenerateBase implements ContainerFactory
$values['max_comments'] = array_shift($args);
$all_types = array_keys(node_type_get_names());
$default_types = array_intersect(array('page', 'article'), $all_types);
$selected_types = _convert_csv_to_array(drush_get_option('types', $default_types));
$selected_types = StringUtils::csvToArray(drush_get_option('types', $default_types));
// Validates the input format for content types option.
if (drush_get_option('types', $default_types) === TRUE) {
return drush_set_error('DEVEL_GENERATE_INVALID_INPUT', dt('Wrong syntax or no content type selected. The correct syntax uses "=", eg.: --types=page,article'));
throw new \Exception(dt('Wrong syntax or no content type selected. The correct syntax uses "=", eg.: --types=page,article'));
}
if (empty($selected_types)) {
return drush_set_error('DEVEL_GENERATE_NO_CONTENT_TYPES', dt('No content types available'));
throw new \Exception(dt('No content types available'));
}
$values['node_types'] = array_combine($selected_types, $selected_types);
$node_types = array_filter($values['node_types']);
if (!empty($values['kill']) && empty($node_types)) {
return drush_set_error('DEVEL_GENERATE_INVALID_INPUT', dt('Please provide content type (--types) in which you want to delete the content.'));
throw new \Exception(dt('Please provide content type (--types) in which you want to delete the content.'));
}
// Checks for any missing content types before generating nodes.
if (array_diff($node_types, $all_types)) {
return drush_set_error('DEVEL_GENERATE_INVALID_INPUT', dt('One or more content types have been entered that don\'t exist on this site'));
throw new \Exception(dt('One or more content types have been entered that don\'t exist on this site'));
}
return $values;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment