/** * {@inheritdoc} */ public function init(array $data) { foreach ($data as $property => $value) { $this->{$property} = $data[$property]; } if (isset($data['options'])) { $this->options = array_replace_recursive((array) $this->options, (array) $data['options']); } $this->loggerChannel->error($this->getMessage(), array('channel' => 'openlayers')); $this->messenger->addMessage($this->getMessage(), 'error', FALSE); }
/** * {@inheritdoc} */ public function setCache($form_build_id, $form, FormStateInterface $form_state) { // 6 hours cache life time for forms should be plenty. $expire = 21600; // Ensure that the form build_id embedded in the form structure is the same // as the one passed in as a parameter. This is an additional safety measure // to prevent legacy code operating directly with // \Drupal::formBuilder()->getCache() and \Drupal::formBuilder()->setCache() // from accidentally overwriting immutable form state. if (isset($form['#build_id']) && $form['#build_id'] != $form_build_id) { $this->logger->error('Form build-id mismatch detected while attempting to store a form in the cache.'); return; } // Cache form structure. if (isset($form)) { if ($this->currentUser->isAuthenticated()) { $form['#cache_token'] = $this->csrfToken->get(); } unset($form['#build_id_old']); $this->keyValueExpirableFactory->get('form')->setWithExpire($form_build_id, $form, $expire); } // Cache form state. if ($this->configFactory->get('system.performance')->get('cache.page.use_internal') && $this->isPageCacheable()) { $form_state->addBuildInfo('immutable', TRUE); } // Store the known list of safe strings for form re-use. // @todo Ensure we are not storing an excessively large string list in: // https://www.drupal.org/node/2295823 $form_state->addBuildInfo('safe_strings', SafeMarkup::getAll()); if ($data = $form_state->getCacheableArray()) { $this->keyValueExpirableFactory->get('form_state')->setWithExpire($form_build_id, $data, $expire); } }
/** * {@inheritdoc} */ public function setCache($form_build_id, $form, FormStateInterface $form_state) { // 6 hours cache life time for forms should be plenty. $expire = 21600; // Ensure that the form build_id embedded in the form structure is the same // as the one passed in as a parameter. This is an additional safety measure // to prevent legacy code operating directly with // \Drupal::formBuilder()->getCache() and \Drupal::formBuilder()->setCache() // from accidentally overwriting immutable form state. if (isset($form['#build_id']) && $form['#build_id'] != $form_build_id) { $this->logger->error('Form build-id mismatch detected while attempting to store a form in the cache.'); return; } // Cache form structure. if (isset($form)) { if ($this->currentUser->isAuthenticated()) { $form['#cache_token'] = $this->csrfToken->get(); } unset($form['#build_id_old']); $this->keyValueExpirableFactory->get('form')->setWithExpire($form_build_id, $form, $expire); } if ($data = $form_state->getCacheableArray()) { $this->keyValueExpirableFactory->get('form_state')->setWithExpire($form_build_id, $data, $expire); } }
/** * {@inheritdoc} */ public function unsubscribe($mail, $newsletter_id, $confirm = TRUE, $source = 'unknown') { $subscriber = simplenews_subscriber_load_by_mail($mail); // The unlikely case that a user is unsubscribed from a non existing mailing list is logged if (!($newsletter = simplenews_newsletter_load($newsletter_id))) { $this->logger->error('Attempt to unsubscribe from non existing mailing list ID %id', array('%id' => $newsletter_id)); return $this; } // If confirmation is not explicitly specified, use the newsletter // configuration. if ($confirm === NULL) { $confirm = $this->requiresConfirmation($newsletter, $subscriber->getUserId()); } if ($confirm) { // Make sure the mail address is set. if (empty($subscriber)) { $subscriber = Subscriber::create(array()); $subscriber->setMail($mail); $subscriber->save(); } $this->addConfirmation('unsubscribe', $subscriber, $newsletter); } elseif ($subscriber && $subscriber->isSubscribed($newsletter_id)) { // Unsubscribe the user from the mailing list. $subscriber->unsubscribe($newsletter_id, $source); $subscriber->save(); } return $this; }
/** * {@inheritdoc} */ public function sendMailMessages(MessageInterface $message, AccountInterface $sender) { // Clone the sender, as we make changes to mail and name properties. $sender_cloned = clone $this->userStorage->load($sender->id()); $params = array(); $current_langcode = $this->languageManager->getCurrentLanguage()->getId(); $recipient_langcode = $this->languageManager->getDefaultLanguage()->getId(); $contact_form = $message->getContactForm(); if ($sender_cloned->isAnonymous()) { // At this point, $sender contains an anonymous user, so we need to take // over the submitted form values. $sender_cloned->name = $message->getSenderName(); $sender_cloned->mail = $message->getSenderMail(); // For the email message, clarify that the sender name is not verified; it // could potentially clash with a username on this site. $sender_cloned->name = $this->t('@name (not verified)', array('@name' => $message->getSenderName())); } // Build email parameters. $params['contact_message'] = $message; $params['sender'] = $sender_cloned; if (!$message->isPersonal()) { // Send to the form recipient(s), using the site's default language. $params['contact_form'] = $contact_form; $to = implode(', ', $contact_form->getRecipients()); } elseif ($recipient = $message->getPersonalRecipient()) { // Send to the user in the user's preferred language. $to = $recipient->getEmail(); $recipient_langcode = $recipient->getPreferredLangcode(); $params['recipient'] = $recipient; } else { throw new MailHandlerException('Unable to determine message recipient'); } // Send email to the recipient(s). $key_prefix = $message->isPersonal() ? 'user' : 'page'; $this->mailManager->mail('contact', $key_prefix . '_mail', $to, $recipient_langcode, $params, $sender_cloned->getEmail()); // If requested, send a copy to the user, using the current language. if ($message->copySender()) { $this->mailManager->mail('contact', $key_prefix . '_copy', $sender_cloned->getEmail(), $current_langcode, $params, $sender_cloned->getEmail()); } // If configured, send an auto-reply, using the current language. if (!$message->isPersonal() && $contact_form->getReply()) { // User contact forms do not support an auto-reply message, so this // message always originates from the site. if (!$sender_cloned->getEmail()) { $this->logger->error('Error sending auto-reply, missing sender e-mail address in %contact_form', ['%contact_form' => $contact_form->label()]); } else { $this->mailManager->mail('contact', 'page_autoreply', $sender_cloned->getEmail(), $current_langcode, $params); } } if (!$message->isPersonal()) { $this->logger->notice('%sender-name (@sender-from) sent an email regarding %contact_form.', array('%sender-name' => $sender_cloned->getUsername(), '@sender-from' => $sender_cloned->getEmail(), '%contact_form' => $contact_form->label())); } else { $this->logger->notice('%sender-name (@sender-from) sent %recipient-name an email.', array('%sender-name' => $sender_cloned->getUsername(), '@sender-from' => $sender_cloned->getEmail(), '%recipient-name' => $message->getPersonalRecipient()->getUsername())); } }
/** * {@inheritdoc} */ public function sortedGroupsWithTags() { $groups = $this->sortedGroups(); $tags = $this->sortedTags(); foreach ($tags as $tag_id => $tag) { $tag_group = $tag['group']; if (!isset($groups[$tag_group])) { // If the tag is claiming a group that has no matching plugin, log an // error and force it to the basic group. $this->logger->error("Undefined group '%group' on tag '%tag'", ['%group' => $tag_group, '%tag' => $tag_id]); $tag['group'] = 'basic'; $tag_group = 'basic'; } $groups[$tag_group]['tags'][$tag_id] = $tag; } return $groups; }
/** * {@inheritdoc} */ public function thumbnailURI() { $thumbnail = 'http://img.youtube.com/vi/' . $this->matches['id'] . '/hqdefault.jpg'; if ($this->apiKey) { $options = ['query' => ['part' => 'snippet', 'id' => $this->matches['id'], 'key' => $this->apiKey]]; $url = Url::fromUri('https://www.googleapis.com/youtube/v3/videos', $options)->toString(); try { $response = $this->httpClient->get($url, ['http_errors' => TRUE]); $response = json_decode($response->getBody(), TRUE); return $response['items'][0]['snippet']['thumbnails']['high']['url']; } catch (ClientException $e) { $this->log->error($e->getMessage()); return $thumbnail; } } else { return $thumbnail; } }
/** * {@inheritdoc} */ public function sendMail(MailInterface $mail) { $params['simplenews_mail'] = $mail; // Send mail. $message = $this->mailManager->mail('simplenews', $mail->getKey(), $mail->getRecipient(), $mail->getLanguage(), $params, $mail->getFromFormatted()); // Log sent result in watchdog. if ($this->config->get('mail.debug')) { if ($message['result']) { $this->logger->debug('Outgoing email. Message type: %type<br />Subject: %subject<br />Recipient: %to', array('%type' => $mail->getKey(), '%to' => $message['to'], '%subject' => $message['subject'])); } else { $this->logger->error('Outgoing email failed. Message type: %type<br />Subject: %subject<br />Recipient: %to', array('%type' => $mail->getKey(), '%to' => $message['to'], '%subject' => $message['subject'])); } } // Build array of sent results for spool table and reporting. if ($message['result']) { $result = array('status' => SpoolStorageInterface::STATUS_DONE, 'error' => FALSE); } else { // This error may be caused by faulty mailserver configuration or overload. // Mark "pending" to keep trying. $result = array('status' => SpoolStorageInterface::STATUS_PENDING, 'error' => TRUE); } return $result; }
/** * {@inheritdoc} */ public function init() { parent::init(); $this->loggerChannel->error($this->getMessage(), array('channel' => 'openlayers')); $this->messenger->addMessage($this->getMessage(), 'error', FALSE); }