Loading helpfulness.info.yml +1 −1 Original line number Diff line number Diff line name: Helpfulness description: 'Provides a block for the user to leave feedback' core: 8.x core_version_requirement: ^8.8 || ^9 configure: helpfulness.admin_form type: module src/Form/HelpfulnessAdminForm.php +18 −1 Original line number Diff line number Diff line Loading @@ -4,12 +4,29 @@ namespace Drupal\helpfulness\Form; use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Defines a form for the administration values. */ class HelpfulnessAdminForm extends ConfigFormBase { /** * An email validator service instance. * * @var \Drupal\Component\Utility\EmailValidator */ protected $emailValidator; /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { $instance = parent::create($container); $instance->emailValidator = $container->get('email.validator'); return $instance; } /** * {@inheritdoc} */ Loading Loading @@ -127,7 +144,7 @@ class HelpfulnessAdminForm extends ConfigFormBase { */ public function validateForm(array &$form, FormStateInterface $form_state) { $notification_email = trim($form_state->getValue('helpfulness_notification_email')); if (!empty($notification_email) && !valid_email_address($notification_email)) { if (!empty($notification_email) && !$this->emailValidator->isValid($notification_email)) { $form_state->setErrorByName('helpfulness_notification_email', $this->t('The email address you entered is not valid.')); } } Loading src/Form/HelpfulnessBlockForm.php +11 −4 Original line number Diff line number Diff line Loading @@ -5,7 +5,6 @@ namespace Drupal\helpfulness\Form; use Drupal\Core\Url; use Drupal\Core\Form\FormBase; use Drupal\Component\Utility\Html; use Drupal\Component\Utility\Unicode; use Drupal\Core\Form\FormStateInterface; use Symfony\Component\DependencyInjection\ContainerInterface; Loading @@ -21,6 +20,13 @@ class HelpfulnessBlockForm extends FormBase { */ protected $database; /** * A time service instance. * * @var \Drupal\Component\Datetime\Time */ protected $time; /** * A current path service instance. * Loading Loading @@ -48,6 +54,7 @@ class HelpfulnessBlockForm extends FormBase { public static function create(ContainerInterface $container) { $instance = parent::create($container); $instance->database = $container->get('database'); $instance->time = $container->get('datetime.time'); $instance->currentPath = $container->get('path.current'); $instance->mailManager = $container->get('plugin.manager.mail'); $instance->languageManager = $container->get('language_manager'); Loading Loading @@ -133,7 +140,7 @@ class HelpfulnessBlockForm extends FormBase { } // Validate the comments. $comments = Unicode::substr(trim(strip_tags($form_state->getValue('helpfulness_comments'))), 0, 1024); $comments = mb_substr(trim(strip_tags($form_state->getValue('helpfulness_comments'))), 0, 1024); if (empty($comments)) { $comments = $this->t('None'); } Loading @@ -151,7 +158,7 @@ class HelpfulnessBlockForm extends FormBase { 'helpfulness' => $form_state->getValue('helpfulness_rating'), 'message' => $comments, 'useragent' => $user_agent, 'timestamp' => REQUEST_TIME, 'timestamp' => $this->time->getRequestTime(), ]; // Insert the data to the helpfulness table. Loading @@ -177,7 +184,7 @@ class HelpfulnessBlockForm extends FormBase { $this->mailManager->mail('helpfulness', 'new_feedback_notification', $notification_email, $language, $params, $site_mail); } drupal_set_message($this->t('Thank you for your feedback.')); $this->messenger()->addMessage($this->t('Thank you for your feedback.')); } } src/Form/HelpfulnessConfirmDeleteFeedbackForm.php +1 −1 Original line number Diff line number Diff line Loading @@ -102,7 +102,7 @@ class HelpfulnessConfirmDeleteFeedbackForm extends ConfirmFormBase { $query->execute(); } drupal_set_message(t('The selected feedbacks have been deleted.')); $this->messenger()->addMessage(t('The selected feedbacks have been deleted.')); $form_state->setRedirect('helpfulness.report_form'); } Loading src/Form/HelpfulnessReportDownloadForm.php +10 −2 Original line number Diff line number Diff line Loading @@ -18,6 +18,13 @@ class HelpfulnessReportDownloadForm extends FormBase { */ protected $database; /** * A date formatter service instance. * * @var \Drupal\Core\Datetime\DateFormatter */ protected $dateFormatter; /** * An entity type manager service instance. * Loading @@ -31,6 +38,7 @@ class HelpfulnessReportDownloadForm extends FormBase { public static function create(ContainerInterface $container) { $instance = parent::create($container); $instance->database = $container->get('database'); $instance->dateFormatter = $container->get('date.formatter'); $instance->entityTypeManager = $container->get('entity_type.manager'); return $instance; } Loading Loading @@ -159,7 +167,7 @@ class HelpfulnessReportDownloadForm extends FormBase { $csv_output .= '"' . $row->useragent . '",'; // Time of submission. $csv_output .= '"' . format_date($row->timestamp, 'custom', "Y-m-d H:i:s") . '",'; $csv_output .= '"' . $this->dateFormatter->format($row->timestamp, 'custom', "Y-m-d H:i:s") . '",'; // That should be everything for this submission. $csv_output .= "\n"; Loading @@ -167,7 +175,7 @@ class HelpfulnessReportDownloadForm extends FormBase { // Build the filename and start the download. $prefix = $this->t('feedbacks'); $filename = $prefix . "_" . format_date(time(), 'custom', "Y-m-d_His"); $filename = $prefix . "_" . $this->dateFormatter->format(time(), 'custom', "Y-m-d_His"); header("Content-type: application/vnd.ms-excel"); header("Content-disposition: filename=" . $filename . ".csv"); print $csv_output; Loading Loading
helpfulness.info.yml +1 −1 Original line number Diff line number Diff line name: Helpfulness description: 'Provides a block for the user to leave feedback' core: 8.x core_version_requirement: ^8.8 || ^9 configure: helpfulness.admin_form type: module
src/Form/HelpfulnessAdminForm.php +18 −1 Original line number Diff line number Diff line Loading @@ -4,12 +4,29 @@ namespace Drupal\helpfulness\Form; use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Defines a form for the administration values. */ class HelpfulnessAdminForm extends ConfigFormBase { /** * An email validator service instance. * * @var \Drupal\Component\Utility\EmailValidator */ protected $emailValidator; /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { $instance = parent::create($container); $instance->emailValidator = $container->get('email.validator'); return $instance; } /** * {@inheritdoc} */ Loading Loading @@ -127,7 +144,7 @@ class HelpfulnessAdminForm extends ConfigFormBase { */ public function validateForm(array &$form, FormStateInterface $form_state) { $notification_email = trim($form_state->getValue('helpfulness_notification_email')); if (!empty($notification_email) && !valid_email_address($notification_email)) { if (!empty($notification_email) && !$this->emailValidator->isValid($notification_email)) { $form_state->setErrorByName('helpfulness_notification_email', $this->t('The email address you entered is not valid.')); } } Loading
src/Form/HelpfulnessBlockForm.php +11 −4 Original line number Diff line number Diff line Loading @@ -5,7 +5,6 @@ namespace Drupal\helpfulness\Form; use Drupal\Core\Url; use Drupal\Core\Form\FormBase; use Drupal\Component\Utility\Html; use Drupal\Component\Utility\Unicode; use Drupal\Core\Form\FormStateInterface; use Symfony\Component\DependencyInjection\ContainerInterface; Loading @@ -21,6 +20,13 @@ class HelpfulnessBlockForm extends FormBase { */ protected $database; /** * A time service instance. * * @var \Drupal\Component\Datetime\Time */ protected $time; /** * A current path service instance. * Loading Loading @@ -48,6 +54,7 @@ class HelpfulnessBlockForm extends FormBase { public static function create(ContainerInterface $container) { $instance = parent::create($container); $instance->database = $container->get('database'); $instance->time = $container->get('datetime.time'); $instance->currentPath = $container->get('path.current'); $instance->mailManager = $container->get('plugin.manager.mail'); $instance->languageManager = $container->get('language_manager'); Loading Loading @@ -133,7 +140,7 @@ class HelpfulnessBlockForm extends FormBase { } // Validate the comments. $comments = Unicode::substr(trim(strip_tags($form_state->getValue('helpfulness_comments'))), 0, 1024); $comments = mb_substr(trim(strip_tags($form_state->getValue('helpfulness_comments'))), 0, 1024); if (empty($comments)) { $comments = $this->t('None'); } Loading @@ -151,7 +158,7 @@ class HelpfulnessBlockForm extends FormBase { 'helpfulness' => $form_state->getValue('helpfulness_rating'), 'message' => $comments, 'useragent' => $user_agent, 'timestamp' => REQUEST_TIME, 'timestamp' => $this->time->getRequestTime(), ]; // Insert the data to the helpfulness table. Loading @@ -177,7 +184,7 @@ class HelpfulnessBlockForm extends FormBase { $this->mailManager->mail('helpfulness', 'new_feedback_notification', $notification_email, $language, $params, $site_mail); } drupal_set_message($this->t('Thank you for your feedback.')); $this->messenger()->addMessage($this->t('Thank you for your feedback.')); } }
src/Form/HelpfulnessConfirmDeleteFeedbackForm.php +1 −1 Original line number Diff line number Diff line Loading @@ -102,7 +102,7 @@ class HelpfulnessConfirmDeleteFeedbackForm extends ConfirmFormBase { $query->execute(); } drupal_set_message(t('The selected feedbacks have been deleted.')); $this->messenger()->addMessage(t('The selected feedbacks have been deleted.')); $form_state->setRedirect('helpfulness.report_form'); } Loading
src/Form/HelpfulnessReportDownloadForm.php +10 −2 Original line number Diff line number Diff line Loading @@ -18,6 +18,13 @@ class HelpfulnessReportDownloadForm extends FormBase { */ protected $database; /** * A date formatter service instance. * * @var \Drupal\Core\Datetime\DateFormatter */ protected $dateFormatter; /** * An entity type manager service instance. * Loading @@ -31,6 +38,7 @@ class HelpfulnessReportDownloadForm extends FormBase { public static function create(ContainerInterface $container) { $instance = parent::create($container); $instance->database = $container->get('database'); $instance->dateFormatter = $container->get('date.formatter'); $instance->entityTypeManager = $container->get('entity_type.manager'); return $instance; } Loading Loading @@ -159,7 +167,7 @@ class HelpfulnessReportDownloadForm extends FormBase { $csv_output .= '"' . $row->useragent . '",'; // Time of submission. $csv_output .= '"' . format_date($row->timestamp, 'custom', "Y-m-d H:i:s") . '",'; $csv_output .= '"' . $this->dateFormatter->format($row->timestamp, 'custom', "Y-m-d H:i:s") . '",'; // That should be everything for this submission. $csv_output .= "\n"; Loading @@ -167,7 +175,7 @@ class HelpfulnessReportDownloadForm extends FormBase { // Build the filename and start the download. $prefix = $this->t('feedbacks'); $filename = $prefix . "_" . format_date(time(), 'custom', "Y-m-d_His"); $filename = $prefix . "_" . $this->dateFormatter->format(time(), 'custom', "Y-m-d_His"); header("Content-type: application/vnd.ms-excel"); header("Content-disposition: filename=" . $filename . ".csv"); print $csv_output; Loading