/** * {@inheritdoc} */ public function validateDrushParams($args) { $add_language = drush_get_option('languages'); if (!empty($add_language)) { $add_language = explode(',', str_replace(' ', '', $add_language)); // Intersect with the enabled languages to make sure the language args // passed are actually enabled. $values['values']['add_language'] = array_intersect($add_language, array_keys(locale_language_list())); } $values['kill'] = drush_get_option('kill'); $values['title_length'] = 6; $values['num'] = array_shift($args); $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)); if (empty($selected_types)) { return drush_set_error('DEVEL_GENERATE_NO_CONTENT_TYPES', 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.')); } return $values; }
/** * {@inheritdoc} */ public function validateDrushParams($args) { $add_language = drush_get_option('languages'); if (!empty($add_language)) { $add_language = explode(',', str_replace(' ', '', $add_language)); // Intersect with the enabled languages to make sure the language args // passed are actually enabled. $values['values']['add_language'] = array_intersect($add_language, array_keys($this->languageManager->getLanguages(LanguageInterface::STATE_ALL))); } $values['kill'] = drush_get_option('kill'); $values['title_length'] = drush_get_option('title_length', 6); $values['num'] = array_shift($args); $selected_bundles = _convert_csv_to_array(drush_get_option('bundles', [])); if (empty($selected_bundles)) { return drush_set_error('DEVEL_GENERATE_NO_MEDIA_BUNDLES', dt('No media bundles available')); } $values['media_bundles'] = array_combine($selected_bundles, $selected_bundles); return $values; }
/** * Given a comma-separated list of inputs, return accounts * for users that match by uid,name or email address. * * @param string $inputs * A comma delimited string (or array) of arguments, specifying user account(s). * * @throws UserListException * If any input is unmatched, an exception is thrown. * * @return \Drush\User\UserSingleBase[] * An associative array of UserSingleBase objects, keyed by user id. */ public static function getFromParameters($inputs) { $accounts = array(); $userversion = drush_user_get_class(); if ($inputs && $userversion) { $inputs = _convert_csv_to_array($inputs); foreach ($inputs as $input) { if (is_numeric($input) && ($account = $userversion->load_by_uid($input))) { } elseif ($account = $userversion->load_by_name($input)) { } elseif ($account = $userversion->load_by_mail($input)) { } else { // Unable to load an account for the input. throw new UserListException('Unable to find a matching user for ' . $input . '.'); } // Populate $accounts with a UserSingle object. Will go into $this->accounts. $single = drush_usersingle_get_class($account); $accounts[$single->id()] = $single; } } return $accounts; }
/** * Validate that passed View names are valid. * * @hook validate @validate-entity-load * @param \Consolidation\AnnotatedCommand\CommandData $commandData * @return \Consolidation\AnnotatedCommand\CommandError|null */ public function validate_entity_load(CommandData $commandData) { list($entity_type, $arg_name) = explode(' ', $commandData->annotationData()->get('validate-entity-load', NULL)); $names = _convert_csv_to_array($commandData->input()->getArgument($arg_name)); $loaded = \Drupal::entityTypeManager()->getStorage($entity_type)->loadMultiple($names); if ($missing = array_diff($names, array_keys($loaded))) { $msg = dt('Unable to load Views: !str', ['!str' => implode(', ', $missing)]); return new CommandError($msg); } }