Commit bbcf4348 authored by Sergiu Stici's avatar Sergiu Stici Committed by TravisCarden

Issue #3042760 by Sergiu Stici, TravisCarden: Update deprecated code

parent a4e42b6d
...@@ -143,8 +143,8 @@ function drush_checklistapi_info() { ...@@ -143,8 +143,8 @@ function drush_checklistapi_info() {
// Append completion details. // Append completion details.
$user = User::load($saved_item['#uid']); $user = User::load($saved_item['#uid']);
$title .= ' - ' . dt('Completed @time by @user', [ $title .= ' - ' . dt('Completed @time by @user', [
'@time' => format_date($saved_item['#completed'], 'short'), '@time' => \Drupal::service('date.formatter')->format($saved_item['#completed'], 'short'),
'@user' => $user->getUsername(), '@user' => $user->getAccountName(),
]); ]);
} }
// Print the list item. // Print the list item.
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
namespace Drupal\checklistapi; namespace Drupal\checklistapi;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Render\Element; use Drupal\Core\Render\Element;
use Drupal\Core\Url; use Drupal\Core\Url;
use Drupal\user\Entity\User; use Drupal\user\Entity\User;
...@@ -121,7 +120,7 @@ class ChecklistapiChecklist { ...@@ -121,7 +120,7 @@ class ChecklistapiChecklist {
if ($property_key === '#storage') { if ($property_key === '#storage') {
continue; continue;
} }
$property_name = checklistapi_strtolowercamel(Unicode::substr($property_key, 1)); $property_name = checklistapi_strtolowercamel(mb_substr($property_key, 1));
$this->$property_name = $value; $this->$property_name = $value;
} }
...@@ -144,7 +143,7 @@ class ChecklistapiChecklist { ...@@ -144,7 +143,7 @@ class ChecklistapiChecklist {
public function clearSavedProgress() { public function clearSavedProgress() {
$this->storage->deleteSavedProgress(); $this->storage->deleteSavedProgress();
drupal_set_message(t('%title saved progress has been cleared.', [ \Drupal::messenger()->addMessage(t('%title saved progress has been cleared.', [
'%title' => $this->title, '%title' => $this->title,
])); ]));
} }
...@@ -179,7 +178,7 @@ class ChecklistapiChecklist { ...@@ -179,7 +178,7 @@ class ChecklistapiChecklist {
public function getLastUpdatedUser() { public function getLastUpdatedUser() {
if (isset($this->savedProgress['#changed_by'])) { if (isset($this->savedProgress['#changed_by'])) {
return User::load($this->savedProgress['#changed_by']) return User::load($this->savedProgress['#changed_by'])
->getUsername(); ->getAccountName();
} }
else { else {
return t('n/a'); return t('n/a');
...@@ -194,7 +193,7 @@ class ChecklistapiChecklist { ...@@ -194,7 +193,7 @@ class ChecklistapiChecklist {
* no saved progress. * no saved progress.
*/ */
public function getLastUpdatedDate() { public function getLastUpdatedDate() {
return (!empty($this->savedProgress['#changed'])) ? format_date($this->savedProgress['#changed']) : t('n/a'); return (!empty($this->savedProgress['#changed'])) ? \Drupal::service('date.formatter')->format($this->savedProgress['#changed']) : t('n/a');
} }
/** /**
...@@ -308,7 +307,7 @@ class ChecklistapiChecklist { ...@@ -308,7 +307,7 @@ class ChecklistapiChecklist {
ksort($progress); ksort($progress);
$this->storage->setSavedProgress($progress); $this->storage->setSavedProgress($progress);
drupal_set_message(\Drupal::translation()->formatPlural( \Drupal::messenger()->addMessage(\Drupal::translation()->formatPlural(
$num_changed_items, $num_changed_items,
'%title progress has been saved. 1 item changed.', '%title progress has been saved. 1 item changed.',
'%title progress has been saved. @count items changed.', '%title progress has been saved. @count items changed.',
......
...@@ -4,6 +4,7 @@ namespace Drupal\checklistapi\Controller; ...@@ -4,6 +4,7 @@ namespace Drupal\checklistapi\Controller;
use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Url; use Drupal\Core\Url;
use Drupal\Core\Link;
/** /**
* Controller for Checklist API. * Controller for Checklist API.
...@@ -43,7 +44,7 @@ class ChecklistapiController extends ControllerBase { ...@@ -43,7 +44,7 @@ class ChecklistapiController extends ControllerBase {
$row = []; $row = [];
$row[] = [ $row[] = [
'data' => ($checklist->userHasAccess()) ? $this->l($checklist->title, $checklist->getUrl()) : drupal_placeholder($checklist->title), 'data' => ($checklist->userHasAccess()) ? Link::fromTextAndUrl($checklist->title, $checklist->getUrl()) : $checklist->title,
'title' => (!empty($checklist->description)) ? $checklist->description : '', 'title' => (!empty($checklist->description)) ? $checklist->description : '',
]; ];
$row[] = $this->t('@completed of @total (@percent%)', [ $row[] = $this->t('@completed of @total (@percent%)', [
......
...@@ -3,15 +3,58 @@ ...@@ -3,15 +3,58 @@
namespace Drupal\checklistapi\Form; namespace Drupal\checklistapi\Form;
use Drupal\Component\Utility\Xss; use Drupal\Component\Utility\Xss;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Form\FormInterface; use Drupal\Core\Form\FormInterface;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Link;
use Drupal\Core\Render\Element; use Drupal\Core\Render\Element;
use Drupal\user\Entity\User; use Drupal\user\Entity\User;
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
* Provides a checklist form. * Provides a checklist form.
*/ */
class ChecklistapiChecklistForm implements FormInterface { class ChecklistapiChecklistForm implements FormInterface, ContainerInjectionInterface {
/**
* The date formatter service.
*
* @var \Drupal\Core\Datetime\DateFormatterInterface
*/
protected $dateFormatter;
/**
* The messenger service.
*
* @var \Drupal\Core\Messenger\MessengerInterface
*/
protected $messenger;
/**
* Constructs an instance.
*
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
* The date formatter service.
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
* The messenger service.
*/
public function __construct(DateFormatterInterface $date_formatter, MessengerInterface $messenger) {
$this->dateFormatter = $date_formatter;
$this->messenger = $messenger;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
/** @var \Drupal\Core\Datetime\DateFormatterInterface $date_formatter */
$date_formatter = $container->get('date.formatter');
/** @var \Drupal\Core\Messenger\MessengerInterface $messenger */
$messenger = $container->get('messenger');
return new static($date_formatter, $messenger);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
...@@ -84,8 +127,8 @@ class ChecklistapiChecklistForm implements FormInterface { ...@@ -84,8 +127,8 @@ class ChecklistapiChecklistForm implements FormInterface {
if ($saved_item) { if ($saved_item) {
// Append completion details. // Append completion details.
$title .= '<span class="completion-details"> - ' . t('Completed @time by @user', [ $title .= '<span class="completion-details"> - ' . t('Completed @time by @user', [
'@time' => format_date($saved_item['#completed'], 'short'), '@time' => $this->dateFormatter->format($saved_item['#completed'], 'short'),
'@user' => User::load($saved_item['#uid'])->getUsername(), '@user' => User::load($saved_item['#uid'])->getAccountName(),
]) . '</span>'; ]) . '</span>';
} }
// Set default value. // Set default value.
...@@ -104,7 +147,7 @@ class ChecklistapiChecklistForm implements FormInterface { ...@@ -104,7 +147,7 @@ class ChecklistapiChecklistForm implements FormInterface {
$links = []; $links = [];
foreach (Element::children($item) as $link_key) { foreach (Element::children($item) as $link_key) {
$link = &$item[$link_key]; $link = &$item[$link_key];
$links[] = \Drupal::l($link['#text'], $link['#url']); $links[] = Link::fromTextAndUrl($link['#text'], $link['#url'])->toString();
} }
if (count($links)) { if (count($links)) {
$description .= '<div class="links">' . implode(' | ', $links) . '</div>'; $description .= '<div class="links">' . implode(' | ', $links) . '</div>';
...@@ -156,7 +199,7 @@ class ChecklistapiChecklistForm implements FormInterface { ...@@ -156,7 +199,7 @@ class ChecklistapiChecklistForm implements FormInterface {
t('%checklist found 1 unchecked item that was already completed and checked it for you. Save the form to record the change.', $args), t('%checklist found 1 unchecked item that was already completed and checked it for you. Save the form to record the change.', $args),
t('%checklist found @num unchecked items that were already completed and checked them for you. Save the form to record the changes.', $args) t('%checklist found @num unchecked items that were already completed and checked them for you. Save the form to record the changes.', $args)
); );
drupal_set_message($message, 'status'); $this->messenger->addStatus($message);
} }
return $form; return $form;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment