/**
  * Setup appropriate response for activating a messenger and/or message types
  *
  * @param EE_messenger         $messenger
  * @param EE_message_type|null $message_type
  *
  * @return bool
  * @throws EE_Error
  */
 protected function _setup_response_message_for_activating_messenger_with_message_types($messenger, EE_Message_Type $message_type = null)
 {
     //if $messenger isn't a valid messenger object then get out.
     if (!$messenger instanceof EE_Messenger) {
         EE_Error::add_error(__('The messenger being activated is not a valid messenger', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
         return false;
     }
     //activated
     if ($this->_template_args['data']['active_mts']) {
         EE_Error::overwrite_success();
         //activated a message type with the messenger
         if ($message_type instanceof EE_message_type) {
             EE_Error::add_success(sprintf(__('%s message type has been successfully activated with the %s messenger', 'event_espresso'), ucwords($message_type->label['singular']), ucwords($messenger->label['singular'])));
             //if message type was invoice then let's make sure we activate the invoice payment method.
             if ($message_type->name == 'invoice') {
                 EE_Registry::instance()->load_lib('Payment_Method_Manager');
                 $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
                 if ($pm instanceof EE_Payment_Method) {
                     EE_Error::add_attention(__('Activating the invoice message type also automatically activates the invoice payment method.  If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.', 'event_espresso'));
                 }
             }
             //just toggles the entire messenger
         } else {
             EE_Error::add_success(sprintf(__('%s messenger has been successfully activated', 'event_espresso'), ucwords($messenger->label['singular'])));
         }
         return true;
         //possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
         //message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
         //in which case we just give a success message for the messenger being successfully activated.
     } else {
         if (!$messenger->get_default_message_types()) {
             //messenger doesn't have any default message types so still a success.
             EE_Error::add_success(sprintf(__('%s messenger was successfully activated.', 'event_espresso'), ucwords($messenger->label['singular'])));
             return true;
         } else {
             EE_Error::add_error($message_type instanceof EE_message_type ? sprintf(__('%s message type was not successfully activated with the %s messenger', 'event_espresso'), ucwords($message_type->label['singular']), ucwords($messenger->label['singular'])) : sprintf(__('%s messenger was not successfully activated', 'event_espresso'), ucwords($messenger->label['singular'])), __FILE__, __FUNCTION__, __LINE__);
             return false;
         }
     }
 }
 /**
  * Activates given message types for the given EE_messenger object.
  *
  * Note: (very important) This method does not persist the activation to the database.
  * See code implementing this method in this class for examples of how to persist.
  *
  * @param \EE_messenger $messenger
  * @param  array        $message_type_names
  *
  * @return array
  */
 protected function _activate_message_types(EE_messenger $messenger, $message_type_names = array())
 {
     //If $message_type_names is empty, AND $this->_active_message_types is empty, then that means
     //things have never been initialized (which should happen on EEH_Activation::generate_message_templates).
     //So ONLY then do we need to actually grab defaults and cycle through them.  Otherwise we
     //only override _active_message_types when an explicit array of $message_type_names has been provided.
     $message_type_names = empty($message_type_names) && !isset($this->_active_message_types[$messenger->name]) ? $messenger->get_default_message_types() : (array) $message_type_names;
     //now we ALWAYS need to make sure that the messenger is active for the message types we're activating!
     if (!isset($this->_active_message_types[$messenger->name])) {
         $this->_active_message_types[$messenger->name]['settings'] = array();
     }
     if ($message_type_names) {
         // cycle thru message types
         foreach ($message_type_names as $message_type_name) {
             //only register the message type as active IF it isn't already active
             //and if its actually installed.
             if (!$this->is_message_type_active_for_messenger($messenger->name, $message_type_name)) {
                 $this->add_settings_for_message_type($messenger->name, $message_type_name);
                 $this->_set_messenger_has_activated_message_type($messenger, $message_type_name);
             }
         }
     }
     return $message_type_names;
 }