You are here

function drush_onlyone_enable_validate in Allow a content type only once (Only One) 7

Same name and namespace in other branches
  1. 8 onlyone.drush.inc \drush_onlyone_enable_validate()

Implements drush_hook_COMMAND_validate().

File

./onlyone.drush.inc, line 190
Drush commands related to the Only One module.

Code

function drush_onlyone_enable_validate() {
  $args = func_get_args();
  if (!_drush_onlyone_validate_content_type($args)) {
    return;
  }

  // Loading the helper functions file.
  module_load_include('inc', 'onlyone', 'onlyone.helpers');
  $availables_content_types = array_keys(_onlyone_available_content_types());
  $not_available_content_types = array_diff($args, $availables_content_types);
  if (count($not_available_content_types)) {
    $names = implode(', ', $not_available_content_types);
    $singular = "The following content type can't be configured in 'Only One content' mode: @names";
    $plural = "The following content types can't be configured in 'Only One content' mode: @names";
    $message = _onlyone_drush_plural(count($not_available_content_types), $singular, $plural, array(
      '@names' => $names,
    ));
    return drush_set_error('ONLYONE_NON_AVAILABLE_CONTENT_TYPE', $message);
  }
}