Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix drupal 9 deprecations in generateentitycontent] #4214

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions templates/module/src/Controller/entity-controller.php.twig
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Drupal\{{ module }}\Controller;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Link;
use Drupal\Core\Url;
use Drupal\{{ module }}\Entity\{{ entity_class }}Interface;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand Down Expand Up @@ -132,13 +133,13 @@ class {{ entity_class }}Controller extends ControllerBase implements ContainerIn
// Use revision link to link to revisions that are not active.
$date = $this->dateFormatter->format($revision->getRevisionCreationTime(), 'short');
if ($vid != ${{ entity_name }}->getRevisionId()) {
$link = $this->l($date, new Url('entity.{{ entity_name }}.revision', [
$link = Link::fromTextAndUrl($date, new Url('entity.{{ entity_name }}.revision', [
'{{ entity_name }}' => ${{ entity_name }}->id(),
'{{ entity_name }}_revision' => $vid,
]));
}
else {
$link = ${{ entity_name }}->link($date);
$link = ${{ entity_name }}->toLink($date)->toString();
}

$row = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*/
class {{ entity_class }}RevisionDeleteForm extends ConfirmFormBase {% endblock %}
{% block class_methods %}

/**
* The date formatter.
*
* @var \Drupal\Core\Datetime\DateFormatterInterface
*/
protected $dateFormatter;

/**
* The {{ label }} revision.
*
Expand All @@ -49,6 +57,7 @@ class {{ entity_class }}RevisionDeleteForm extends ConfirmFormBase {% endblock %
*/
public static function create(ContainerInterface $container) {
$instance = parent::create($container);
$instance->dateFormatter = $container->get('date.formatter');
$instance->{{ entity_class[:1]|lower ~ entity_class[1:] }}Storage = $container->get('entity_type.manager')->getStorage('{{ entity_name }}');
$instance->connection = $container->get('database');
return $instance;
Expand All @@ -66,7 +75,7 @@ class {{ entity_class }}RevisionDeleteForm extends ConfirmFormBase {% endblock %
*/
public function getQuestion() {
return $this->t('Are you sure you want to delete the revision from %revision-date?', [
'%revision-date' => \Drupal::service('date.formatter')->format($this->revision->getRevisionCreationTime()),
'%revision-date' => $this->dateFormatter->format($this->revision->getRevisionCreationTime()),
]);
}

Expand Down Expand Up @@ -101,7 +110,7 @@ class {{ entity_class }}RevisionDeleteForm extends ConfirmFormBase {% endblock %
$this->{{ entity_class }}Storage->deleteRevision($this->revision->getRevisionId());

$this->logger('content')->notice('{{ label }}: deleted %title revision %revision.', ['%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()]);
$this->messenger()->addMessage(t('Revision from %revision-date of {{ label }} %title has been deleted.', ['%revision-date' => \Drupal::service('date.formatter')->format($this->revision->getRevisionCreationTime()), '%title' => $this->revision->label()]));
$this->messenger()->addMessage(t('Revision from %revision-date of {{ label }} %title has been deleted.', ['%revision-date' => $this->dateFormatter->format($this->revision->getRevisionCreationTime()), '%title' => $this->revision->label()]));
$form_state->setRedirect(
'entity.{{ entity_name }}.canonical',
['{{ entity_name }}' => $this->revision->id()]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ class {{ entity_class }}RevisionRevertForm extends ConfirmFormBase {% endblock %
* @var \Drupal\Core\Datetime\DateFormatterInterface
*/
protected $dateFormatter;

/**
* The time service.
*
* @var \Drupal\Component\Datetime\TimeInterface
*/
protected $time;

/**
* {@inheritdoc}
Expand All @@ -52,6 +59,7 @@ class {{ entity_class }}RevisionRevertForm extends ConfirmFormBase {% endblock %
$instance = parent::create($container);
$instance->{{ entity_class[:1]|lower ~ entity_class[1:] }}Storage = $container->get('entity_type.manager')->getStorage('{{ entity_name }}');
$instance->dateFormatter = $container->get('date.formatter');
$instance->time = $container->get('datetime.time');
return $instance;
}

Expand Down Expand Up @@ -138,7 +146,7 @@ class {{ entity_class }}RevisionRevertForm extends ConfirmFormBase {% endblock %
protected function prepareRevertedRevision({{ entity_class }}Interface $revision, FormStateInterface $form_state) {
$revision->setNewRevision();
$revision->isDefaultRevision(TRUE);
$revision->setRevisionCreationTime(\Drupal::time()->getRequestTime());
$revision->setRevisionCreationTime($this->time->getRequestTime());

return $revision;
}
Expand Down