diff --git a/module/VuFind/src/VuFind/Controller/AbstractBase.php b/module/VuFind/src/VuFind/Controller/AbstractBase.php index a8ca2e452df9bd72f1de480dab182b7455e721da..c2bbdee859949567744d030bdc1d88adfe5ac77f 100644 --- a/module/VuFind/src/VuFind/Controller/AbstractBase.php +++ b/module/VuFind/src/VuFind/Controller/AbstractBase.php @@ -121,11 +121,12 @@ class AbstractBase extends AbstractActionController /** * Create a new ViewModel to use as an email form. * - * @param array $params Parameters to pass to ViewModel constructor. + * @param array $params Parameters to pass to ViewModel constructor. + * @param string $defaultSubject Default subject line to use. * * @return ViewModel */ - protected function createEmailViewModel($params = null) + protected function createEmailViewModel($params = null, $defaultSubject = null) { // Build view: $view = $this->createViewModel($params); @@ -164,6 +165,9 @@ class AbstractBase extends AbstractActionController $view->from = $config->Mail->default_from; } } + if (!isset($view->subject) || empty($view->subject)) { + $view->subject = $defaultSubject; + } // Fail if we're missing a from and the form element is disabled: if ($view->disableFrom) { diff --git a/module/VuFind/src/VuFind/Controller/AbstractRecord.php b/module/VuFind/src/VuFind/Controller/AbstractRecord.php index 745709238dd116f44df39717b58bf84b2498b75b..eac655053467975d18e04e37927f073fd0f53ea8 100644 --- a/module/VuFind/src/VuFind/Controller/AbstractRecord.php +++ b/module/VuFind/src/VuFind/Controller/AbstractRecord.php @@ -358,24 +358,27 @@ class AbstractRecord extends AbstractBase $driver = $this->loadRecord(); // Create view - $view = $this->createEmailViewModel(); + $mailer = $this->getServiceLocator()->get('VuFind\Mailer'); + $view = $this->createEmailViewModel( + null, $mailer->getDefaultRecordSubject($driver) + ); + // Set up reCaptcha $view->useRecaptcha = $this->recaptcha()->active('email'); // Process form submission: if ($this->formWasSubmitted('submit', $view->useRecaptcha)) { // Attempt to send the email and show an appropriate flash message: try { - $mailer = $this->getServiceLocator()->get('VuFind\Mailer'); $mailer->sendRecord( $view->to, $view->from, $view->message, $driver, - $this->getViewRenderer() + $this->getViewRenderer(), $view->subject ); if ($this->params()->fromPost('ccself') && $view->from != $view->to ) { $mailer->sendRecord( $view->from, $view->from, $view->message, $driver, - $this->getViewRenderer() + $this->getViewRenderer(), $view->subject ); } $this->flashMessenger()->setNamespace('info') diff --git a/module/VuFind/src/VuFind/Controller/AjaxController.php b/module/VuFind/src/VuFind/Controller/AjaxController.php index 52a59ea26e85b0e8897d0cca67eccec29503bb51..7640968ba4435c5add86f62a4f25433d12a034fb 100644 --- a/module/VuFind/src/VuFind/Controller/AjaxController.php +++ b/module/VuFind/src/VuFind/Controller/AjaxController.php @@ -1031,18 +1031,20 @@ class AjaxController extends AbstractBase $this->params()->fromPost('id'), $this->params()->fromPost('source', 'VuFind') ); - $view = $this->createEmailViewModel(); $mailer = $this->getServiceLocator()->get('VuFind\Mailer'); + $view = $this->createEmailViewModel( + null, $mailer->getDefaultRecordSubject($record) + ); $mailer->sendRecord( $view->to, $view->from, $view->message, $record, - $this->getViewRenderer() + $this->getViewRenderer(), $view->subject ); if ($this->params()->fromPost('ccself') && $view->from != $view->to ) { $mailer->sendRecord( $view->from, $view->from, $view->message, $record, - $this->getViewRenderer() + $this->getViewRenderer(), $view->subject ); } return $this->output( @@ -1093,18 +1095,21 @@ class AjaxController extends AbstractBase throw new \Exception('recaptcha_not_passed'); } - $view = $this->createEmailViewModel(); $mailer = $this->getServiceLocator()->get('VuFind\Mailer'); + $defaultSubject = $this->params()->fromQuery('cart') + ? $this->translate('bulk_email_title') + : $mailer->getDefaultLinkSubject(); + $view = $this->createEmailViewModel(null, $defaultSubject); $mailer->sendLink( $view->to, $view->from, $view->message, $url, - $this->getViewRenderer(), $this->params()->fromPost('subject') + $this->getViewRenderer(), $view->subject ); if ($this->params()->fromPost('ccself') && $view->from != $view->to ) { $mailer->sendLink( $view->from, $view->from, $view->message, $url, - $this->getViewRenderer(), $this->params()->fromPost('subject') + $this->getViewRenderer(), $view->subject ); } return $this->output( diff --git a/module/VuFind/src/VuFind/Controller/CartController.php b/module/VuFind/src/VuFind/Controller/CartController.php index a632da939668379577e516fe2960a1a5c40c8105..1ba94af32a46eb1ff2f46c31bc0a6b99602f2d29 100644 --- a/module/VuFind/src/VuFind/Controller/CartController.php +++ b/module/VuFind/src/VuFind/Controller/CartController.php @@ -200,7 +200,9 @@ class CartController extends AbstractBase ); } - $view = $this->createEmailViewModel(); + $view = $this->createEmailViewModel( + null, $this->translate('bulk_email_title') + ); $view->records = $this->getRecordLoader()->loadBatch($ids); // Set up reCaptcha $view->useRecaptcha = $this->recaptcha()->active('email'); @@ -220,14 +222,14 @@ class CartController extends AbstractBase $mailer = $this->getServiceLocator()->get('VuFind\Mailer'); $mailer->sendLink( $view->to, $view->from, $view->message, - $url, $this->getViewRenderer(), 'bulk_email_title' + $url, $this->getViewRenderer(), $view->subject ); if ($this->params()->fromPost('ccself') && $view->from != $view->to ) { $mailer->sendLink( $view->from, $view->from, $view->message, - $url, $this->getViewRenderer(), 'bulk_email_title' + $url, $this->getViewRenderer(), $view->subject ); } return $this->redirectToSource('info', 'email_success'); diff --git a/module/VuFind/src/VuFind/Controller/SearchController.php b/module/VuFind/src/VuFind/Controller/SearchController.php index c2df102b1a9021e616141d665d9f9693af30baec..f5120dd24e0640f1d693a2034a49d8e7d334e5e7 100644 --- a/module/VuFind/src/VuFind/Controller/SearchController.php +++ b/module/VuFind/src/VuFind/Controller/SearchController.php @@ -81,7 +81,8 @@ class SearchController extends AbstractSearch { // If a URL was explicitly passed in, use that; otherwise, try to // find the HTTP referrer. - $view = $this->createEmailViewModel(); + $mailer = $this->getServiceLocator()->get('VuFind\Mailer'); + $view = $this->createEmailViewModel(null, $mailer->getDefaultLinkSubject()); // Set up reCaptcha $view->useRecaptcha = $this->recaptcha()->active('email'); $view->url = $this->params()->fromPost( @@ -115,17 +116,16 @@ class SearchController extends AbstractSearch // Attempt to send the email and show an appropriate flash message: try { // If we got this far, we're ready to send the email: - $mailer = $this->getServiceLocator()->get('VuFind\Mailer'); $mailer->sendLink( $view->to, $view->from, $view->message, - $view->url, $this->getViewRenderer() + $view->url, $this->getViewRenderer(), $view->subject ); if ($this->params()->fromPost('ccself') && $view->from != $view->to ) { $mailer->sendLink( $view->from, $view->from, $view->message, - $view->url, $this->getViewRenderer() + $view->url, $this->getViewRenderer(), $view->subject ); } $this->flashMessenger()->setNamespace('info') diff --git a/module/VuFind/src/VuFind/Mailer/Mailer.php b/module/VuFind/src/VuFind/Mailer/Mailer.php index 35965a3e9db47070164d2d5855502fc2e54339a6..cfd91c7b339565ff294cbc26af72fc45d99f6050 100644 --- a/module/VuFind/src/VuFind/Mailer/Mailer.php +++ b/module/VuFind/src/VuFind/Mailer/Mailer.php @@ -153,10 +153,9 @@ class Mailer implements \VuFind\I18n\Translator\TranslatorAwareInterface */ public function sendLink($to, $from, $msg, $url, $view, $subject = null) { - if (is_null($subject)) { - $subject = 'Library Catalog Search Result'; + if (null === $subject) { + $subject = $this->getDefaultLinkSubject(); } - $subject = $this->translate($subject); $body = $view->partial( 'Email/share-link.phtml', array( @@ -166,6 +165,16 @@ class Mailer implements \VuFind\I18n\Translator\TranslatorAwareInterface return $this->send($to, $from, $subject, $body); } + /** + * Get the default subject line for sendLink(). + * + * @return string + */ + public function getDefaultLinkSubject() + { + return $this->translate('Library Catalog Search Result'); + } + /** * Send an email message representing a record. * @@ -176,14 +185,16 @@ class Mailer implements \VuFind\I18n\Translator\TranslatorAwareInterface * @param \VuFind\RecordDriver\AbstractBase $record Record being emailed * @param \Zend\View\Renderer\PhpRenderer $view View object (used to render * email templates) + * @param string $subject Subject for email (optional) * * @throws MailException * @return void */ - public function sendRecord($to, $from, $msg, $record, $view) + public function sendRecord($to, $from, $msg, $record, $view, $subject = null) { - $subject = $this->translate('Library Catalog Record') . ': ' - . $record->getBreadcrumb(); + if (null === $subject) { + $subject = $this->getDefaultRecordSubject(); + } $body = $view->partial( 'Email/record.phtml', array( @@ -192,4 +203,17 @@ class Mailer implements \VuFind\I18n\Translator\TranslatorAwareInterface ); return $this->send($to, $from, $subject, $body); } + + /** + * Get the default subject line for sendRecord() + * + * @param \VuFind\RecordDriver\AbstractBase $record Record being emailed + * + * @return string + */ + public function getDefaultRecordSubject($record) + { + return $this->translate('Library Catalog Record') . ': ' + . $record->getBreadcrumb(); + } } \ No newline at end of file diff --git a/themes/blueprint/js/lightbox.js b/themes/blueprint/js/lightbox.js index 1d9279dce2553c8ab415ca9524792ca6d8c822a0..740a7615be76b062c2aaea252825cb49941b03ad 100644 --- a/themes/blueprint/js/lightbox.js +++ b/themes/blueprint/js/lightbox.js @@ -467,7 +467,7 @@ function registerAjaxEmailSearch() { function registerAjaxBulkEmail() { $('#modalDialog form[name="bulkEmail"]').unbind('submit').submit(function(){ if (!$(this).valid()) { return false; } - var url = path + '/AJAX/JSON?' + $.param({method:'emailSearch', 'subject':'bulk_email_title'}); + var url = path + '/AJAX/JSON?' + $.param({method:'emailSearch', 'cart':'1'}); var ids = []; $(':input[name="ids[]"]', this).each(function() { ids.push(encodeURIComponent('id[]') + '=' + encodeURIComponent(this.value));