Commit 9fae2e16 authored by Pjotr Savitski's avatar Pjotr Savitski
Browse files

Fixed newlines for challenge mails and content title.

Challenge email messages had newlines as code instead of meaningful
characters, that added &13#; to the end of each line. Made sure that
translation system object is forced into a string representation before
running the mail system logic. Code that fetched title for the entity
challenge is attached to was incorrect, there is no meaningful way to
determine the connection as only the field has data about H5PContent
identifier, not the other way around. Changed the code to use the
H5PContent specific title instead.
parent 50fcd04e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -205,7 +205,7 @@ class H5PChallengeController extends ControllerBase {
      '@results' => $url,
    ]);
    $params = [
      'body' => $message,
      'body' => (string) $message,
    ];
    $this->mailManager->mail('h5p_challenge', 'new_challenge_created', $email, $langcode, $params, NULL, TRUE);

+9 −7
Original line number Diff line number Diff line
@@ -2,24 +2,26 @@

namespace Drupal\h5p_challenge\FetchClass;

use Drupal\h5p\Entity\H5PContent;

/**
 * Class H5PChallenge
 */
class H5PChallenge {

  /**
   * Returns content title by content identifier.
   * NB! It is assumed that content is a Node and not some other type of Entity
   * Returns content title by content identifier. Title of H5PContent entity is
   * used, not the title of the container Node or Entity.
   * @param  int    $id
   *   Content identifier
   * @return string
   *   Content title or empty string
   */
  public static function getContentTitleById(int $id) {
    $node = \Drupal::entityTypeManager()->getStorage('node')->load($id);
    $content = H5PContent::load($id);

    if ($node) {
      return $node->getTitle();
    if ($content) {
      return $content->get('title')->value;
    }

    return '';
@@ -35,8 +37,8 @@ class H5PChallenge {
  }

  /**
   * Returns content title used for current challenge.
   * NB! It is assumed that content is a Node and not some other type of Entity
   * Returns content title used for current challenge.Title of H5PContent
   * entity is used, not the title of the container Node or Entity.
   * @return string
   *   Content title or empry string
   */
+1 −1
Original line number Diff line number Diff line
@@ -305,7 +305,7 @@ class H5PChallengeService {
        ]);

        $params = [
          'body' => $message,
          'body' => (string) $message,
          'attachment' => [
            'filecontent' => $this->getChallengeReultsCsv($challenge),
            'filename' => 'results.csv',