You are here

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

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

Callback for the onlyone-new-menu-entry command.

File

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

Code

function drush_onlyone_new_menu_entry() {
  $args = func_get_args();

  // Getting the values from the config.
  $onlyone_new_menu_entry = variable_get('onlyone_new_menu_entry');

  // Giving colors to the messages.
  $activated = sprintf(ONLYONE_GREEN_OUTPUT, dt('Activated'));
  $disabled = sprintf(ONLYONE_RED_OUTPUT, dt('Disabled'));
  if (isset($args[0])) {

    // Assigning values to $value and $status.
    list($value, $status) = $args[0] == 'on' ? array(
      1,
      strtolower($activated),
    ) : array(
      0,
      strtolower($disabled),
    );

    // Is already configured?
    if ($onlyone_new_menu_entry == $value) {

      // If is configured stop the command execution with a warning message.
      $message = dt('The option for shown the configured content type in a new menu entry is already @status.', array(
        '@status' => $status,
      ));
      drush_log($message, 'warning');
      return;
    }

    // Saving the values in the config.
    variable_set('onlyone_new_menu_entry', $value);
    $message = dt('You have @status the option the show the configured content types in a new menu entry.', array(
      '@status' => $status,
    ));
    drush_log($message, 'success');

    // Rebuilding the menu.
    menu_rebuild();
  }
  else {

    // Defining the status.
    $status = $onlyone_new_menu_entry ? $activated : $disabled;
    $message = dt('The option to show the configured content types in a new menu entry is: @status', array(
      '@status' => $status,
    ));
    drush_print($message);
  }
}