From b0a15c981e2723bb2bf38bdac936a8427d79560d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Harold=20Ju=C3=A1rez?= Date: Fri, 10 May 2019 18:40:57 -0600 Subject: [PATCH] [generate:entity:content] Add coding standards for Entity classes (#4031) * REL #3985: Correct entity link templates * REL #3985: Correct Controller CS * REL #3985: Correct hook docblock * REL #3985: Correct entity forms CS * REL #3985: Correct StorageInterface CS * REL #3985: Correct Entity Interface CS * FIX #3985: Remove unnecessary use statement from the entity --- templates/module/links.action-entity.yml.twig | 1 - .../module/links.menu-entity-config.yml.twig | 1 - .../module/links.task-entity-content.yml.twig | 1 - templates/module/module.twig | 2 + .../src/Controller/entity-controller.php.twig | 104 ++++++++++++++---- .../entity-content-revision-delete.php.twig | 12 +- ...ntent-revision-revert-translation.php.twig | 9 +- .../entity-content-revision-revert.php.twig | 14 ++- .../src/Entity/Form/entity-content.php.twig | 64 +++++++++-- .../Entity/entity-content-views-data.php.twig | 1 - ...ith-bundle.theme_hook_suggestions.php.twig | 4 +- .../module/src/Entity/entity-content.php.twig | 8 +- .../Entity/interface-entity-content.php.twig | 5 +- .../module/src/Form/entity-delete.php.twig | 12 +- templates/module/src/Form/entity.php.twig | 4 +- templates/module/src/Form/form.php.twig | 1 - .../entity-content-route-provider.php.twig | 2 +- .../module/src/entity-route-provider.php.twig | 2 - .../src/entity-translation-handler.php.twig | 2 +- .../src/interface-entity-storage.php.twig | 1 + .../src/listbuilder-entity-content.php.twig | 4 +- 21 files changed, 186 insertions(+), 68 deletions(-) diff --git a/templates/module/links.action-entity.yml.twig b/templates/module/links.action-entity.yml.twig index 2be50635c..ae3baa6f8 100644 --- a/templates/module/links.action-entity.yml.twig +++ b/templates/module/links.action-entity.yml.twig @@ -3,4 +3,3 @@ entity.{{ entity_name }}.add_form: title: 'Add {{ label }}' appears_on: - entity.{{ entity_name }}.collection - diff --git a/templates/module/links.menu-entity-config.yml.twig b/templates/module/links.menu-entity-config.yml.twig index 0afe1feeb..150f4106e 100644 --- a/templates/module/links.menu-entity-config.yml.twig +++ b/templates/module/links.menu-entity-config.yml.twig @@ -7,4 +7,3 @@ entity.{{ entity_name }}.collection: description: 'List {{ label }} (bundles)' parent: system.admin_structure weight: 99 - diff --git a/templates/module/links.task-entity-content.yml.twig b/templates/module/links.task-entity-content.yml.twig index 206389c77..94dc2ccec 100644 --- a/templates/module/links.task-entity-content.yml.twig +++ b/templates/module/links.task-entity-content.yml.twig @@ -29,4 +29,3 @@ entity.{{ entity_name }}.delete_form: base_route: entity.{{ entity_name }}.canonical title: Delete weight: 10 - diff --git a/templates/module/module.twig b/templates/module/module.twig index 53540372f..4ff21d17a 100644 --- a/templates/module/module.twig +++ b/templates/module/module.twig @@ -16,7 +16,9 @@ function {{machine_name}}_help($route_name, RouteMatchInterface $route_match) { case 'help.page.{{ machine_name }}': $output = ''; $output .= '

' . t('About') . '

'; +{% if description %} $output .= '

' . t('{{ description|escape }}') . '

'; +{% endif %} return $output; default: diff --git a/templates/module/src/Controller/entity-controller.php.twig b/templates/module/src/Controller/entity-controller.php.twig index cd15c8e01..8cfe6c48b 100644 --- a/templates/module/src/Controller/entity-controller.php.twig +++ b/templates/module/src/Controller/entity-controller.php.twig @@ -11,9 +11,12 @@ namespace Drupal\{{ module }}\Controller; {% block use_class %} use Drupal\Component\Utility\Xss; use Drupal\Core\Controller\ControllerBase; +use Drupal\Core\Datetime\DateFormatter; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; +use Drupal\Core\Render\Renderer; use Drupal\Core\Url; use Drupal\{{ module }}\Entity\{{ entity_class }}Interface; +use Symfony\Component\DependencyInjection\ContainerInterface; {% endblock %} {% block class_declaration %} /** @@ -22,50 +25,92 @@ use Drupal\{{ module }}\Entity\{{ entity_class }}Interface; * Returns responses for {{ label }} routes. */ class {{ entity_class }}Controller extends ControllerBase implements ContainerInjectionInterface {% endblock %} - {% block class_methods %} + + /** + * The date formatter. + * + * @var \Drupal\Core\Datetime\DateFormatter + */ + protected $dateFormatter; + + /** + * The renderer. + * + * @var \Drupal\Core\Render\Renderer + */ + protected $renderer; + + /** + * Constructs a new {{ entity_class }}Controller. + * + * @param \Drupal\Core\Datetime\DateFormatter $date_formatter + * The date formatter. + * @param \Drupal\Core\Render\Renderer $renderer + * The renderer. + */ + public function __construct(DateFormatter $date_formatter, Renderer $renderer) { + $this->dateFormatter = $date_formatter; + $this->renderer = $renderer; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('date.formatter'), + $container->get('renderer') + ); + } + /** - * Displays a {{ label }} revision. + * Displays a {{ label }} revision. * * @param int ${{ entity_name }}_revision - * The {{ label }} revision ID. + * The {{ label }} revision ID. * * @return array * An array suitable for drupal_render(). */ public function revisionShow(${{ entity_name }}_revision) { - ${{ entity_name }} = $this->entityManager()->getStorage('{{ entity_name }}')->loadRevision(${{ entity_name }}_revision); - $view_builder = $this->entityManager()->getViewBuilder('{{ entity_name }}'); + ${{ entity_name }} = $this->entityTypeManager()->getStorage('{{ entity_name }}') + ->loadRevision(${{ entity_name }}_revision); + $view_builder = $this->entityTypeManager()->getViewBuilder('{{ entity_name }}'); return $view_builder->view(${{ entity_name }}); } /** - * Page title callback for a {{ label }} revision. + * Page title callback for a {{ label }} revision. * * @param int ${{ entity_name }}_revision - * The {{ label }} revision ID. + * The {{ label }} revision ID. * * @return string * The page title. */ public function revisionPageTitle(${{ entity_name }}_revision) { - ${{ entity_name }} = $this->entityManager()->getStorage('{{ entity_name }}')->loadRevision(${{ entity_name }}_revision); - return $this->t('Revision of %title from %date', ['%title' => ${{ entity_name }}->label(), '%date' => format_date(${{ entity_name }}->getRevisionCreationTime())]); + ${{ entity_name }} = $this->entityTypeManager()->getStorage('{{ entity_name }}') + ->loadRevision(${{ entity_name }}_revision); + return $this->t('Revision of %title from %date', [ + '%title' => ${{ entity_name }}->label(), + '%date' => $this->dateFormatter->format(${{ entity_name }}->getRevisionCreationTime()), + ]); } /** - * Generates an overview table of older revisions of a {{ label }} . + * Generates an overview table of older revisions of a {{ label }}. * * @param \Drupal\{{ module }}\Entity\{{ entity_class }}Interface ${{ entity_name }} - * A {{ label }} object. + * A {{ label }} object. * * @return array * An array as expected by drupal_render(). */ public function revisionOverview({{ entity_class }}Interface ${{ entity_name }}) { $account = $this->currentUser(); - ${{ entity_name }}_storage = $this->entityManager()->getStorage('{{ entity_name }}'); + ${{ entity_name }}_storage = $this->entityTypeManager()->getStorage('{{ entity_name }}'); {% if is_translatable %} $langcode = ${{ entity_name }}->language()->getId(); @@ -101,9 +146,12 @@ class {{ entity_class }}Controller extends ControllerBase implements ContainerIn ]; // Use revision link to link to revisions that are not active. - $date = \Drupal::service('date.formatter')->format($revision->getRevisionCreationTime(), 'short'); + $date = $this->dateFormatter->format($revision->getRevisionCreationTime(), 'short'); if ($vid != ${{ entity_name }}->getRevisionId()) { - $link = $this->l($date, new Url('entity.{{ entity_name }}.revision', ['{{ entity_name }}' => ${{ entity_name }}->id(), '{{ entity_name }}_revision' => $vid])); + $link = $this->l($date, new Url('entity.{{ entity_name }}.revision', [ + '{{ entity_name }}' => ${{ entity_name }}->id(), + '{{ entity_name }}_revision' => $vid, + ])); } else { $link = ${{ entity_name }}->link($date); @@ -116,8 +164,11 @@ class {{ entity_class }}Controller extends ControllerBase implements ContainerIn '#template' => '{{ '{% trans %}{{ date }} by {{ username }}{% endtrans %}{% if message %}

{{ message }}

{% endif %}' }}', '#context' => [ 'date' => $link, - 'username' => \Drupal::service('renderer')->renderPlain($username), - 'message' => ['#markup' => $revision->getRevisionLogMessage(), '#allowed_tags' => Xss::getHtmlTagList()], + 'username' => $this->renderer->renderPlain($username), + 'message' => [ + '#markup' => $revision->getRevisionLogMessage(), + '#allowed_tags' => Xss::getHtmlTagList(), + ], ], ], ]; @@ -143,10 +194,20 @@ class {{ entity_class }}Controller extends ControllerBase implements ContainerIn 'title' => $this->t('Revert'), {% if is_translatable %} 'url' => $has_translations ? - Url::fromRoute('entity.{{ entity_name }}.translation_revert', ['{{ entity_name }}' => ${{ entity_name }}->id(), '{{ entity_name }}_revision' => $vid, 'langcode' => $langcode]) : - Url::fromRoute('entity.{{ entity_name }}.revision_revert', ['{{ entity_name }}' => ${{ entity_name }}->id(), '{{ entity_name }}_revision' => $vid]), + Url::fromRoute('entity.{{ entity_name }}.translation_revert', [ + '{{ entity_name }}' => ${{ entity_name }}->id(), + '{{ entity_name }}_revision' => $vid, + 'langcode' => $langcode, + ]) : + Url::fromRoute('entity.{{ entity_name }}.revision_revert', [ + '{{ entity_name }}' => ${{ entity_name }}->id(), + '{{ entity_name }}_revision' => $vid, + ]), {% else %} - 'url' => Url::fromRoute('entity.{{ entity_name }}.revision_revert', ['{{ entity_name }}' => ${{ entity_name }}->id(), '{{ entity_name }}_revision' => $vid]), + 'url' => Url::fromRoute('entity.{{ entity_name }}.revision_revert', [ + '{{ entity_name }}' => ${{ entity_name }}->id(), + '{{ entity_name }}_revision' => $vid, + ]), {% endif %} ]; } @@ -154,7 +215,10 @@ class {{ entity_class }}Controller extends ControllerBase implements ContainerIn if ($delete_permission) { $links['delete'] = [ 'title' => $this->t('Delete'), - 'url' => Url::fromRoute('entity.{{ entity_name }}.revision_delete', ['{{ entity_name }}' => ${{ entity_name }}->id(), '{{ entity_name }}_revision' => $vid]), + 'url' => Url::fromRoute('entity.{{ entity_name }}.revision_delete', [ + '{{ entity_name }}' => ${{ entity_name }}->id(), + '{{ entity_name }}_revision' => $vid, + ]), ]; } diff --git a/templates/module/src/Entity/Form/entity-content-revision-delete.php.twig b/templates/module/src/Entity/Form/entity-content-revision-delete.php.twig index aad292455..5dda19626 100644 --- a/templates/module/src/Entity/Form/entity-content-revision-delete.php.twig +++ b/templates/module/src/Entity/Form/entity-content-revision-delete.php.twig @@ -64,9 +64,9 @@ class {{ entity_class }}RevisionDeleteForm extends ConfirmFormBase {% endblock % * {@inheritdoc} */ public static function create(ContainerInterface $container) { - $entity_manager = $container->get('entity.manager'); + $entity_type_manager = $container->get('entity_type.manager'); return new static( - $entity_manager->getStorage('{{ entity_name }}'), + $entity_type_manager->getStorage('{{ entity_name }}'), $container->get('database') ); } @@ -82,7 +82,9 @@ class {{ entity_class }}RevisionDeleteForm extends ConfirmFormBase {% endblock % * {@inheritdoc} */ public function getQuestion() { - return t('Are you sure you want to delete the revision from %revision-date?', ['%revision-date' => format_date($this->revision->getRevisionCreationTime())]); + return $this->t('Are you sure you want to delete the revision from %revision-date?', [ + '%revision-date' => format_date($this->revision->getRevisionCreationTime()), + ]); } /** @@ -96,7 +98,7 @@ class {{ entity_class }}RevisionDeleteForm extends ConfirmFormBase {% endblock % * {@inheritdoc} */ public function getConfirmText() { - return t('Delete'); + return $this->t('Delete'); } /** @@ -116,7 +118,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()]); - \Drupal::messenger()->addMessage(t('Revision from %revision-date of {{ label }} %title has been deleted.', ['%revision-date' => format_date($this->revision->getRevisionCreationTime()), '%title' => $this->revision->label()])); + $this->messenger()->addMessage(t('Revision from %revision-date of {{ label }} %title has been deleted.', ['%revision-date' => format_date($this->revision->getRevisionCreationTime()), '%title' => $this->revision->label()])); $form_state->setRedirect( 'entity.{{ entity_name }}.canonical', ['{{ entity_name }}' => $this->revision->id()] diff --git a/templates/module/src/Entity/Form/entity-content-revision-revert-translation.php.twig b/templates/module/src/Entity/Form/entity-content-revision-revert-translation.php.twig index 0c38ba5b3..3245d52f6 100644 --- a/templates/module/src/Entity/Form/entity-content-revision-revert-translation.php.twig +++ b/templates/module/src/Entity/Form/entity-content-revision-revert-translation.php.twig @@ -19,7 +19,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; {% block class_declaration %} /** - * Provides a form for reverting a {{ label }} revision for a single translation. + * Provides a form for reverting a {{ label }} revision for a single trans. * * @ingroup {{module}} */ @@ -60,7 +60,7 @@ class {{ entity_class }}RevisionRevertTranslationForm extends {{ entity_class }} */ public static function create(ContainerInterface $container) { return new static( - $container->get('entity.manager')->getStorage('{{ entity_name }}'), + $container->get('entity_type.manager')->getStorage('{{ entity_name }}'), $container->get('date.formatter'), $container->get('language_manager') ); @@ -77,7 +77,10 @@ class {{ entity_class }}RevisionRevertTranslationForm extends {{ entity_class }} * {@inheritdoc} */ public function getQuestion() { - return t('Are you sure you want to revert @language translation to the revision from %revision-date?', ['@language' => $this->languageManager->getLanguageName($this->langcode), '%revision-date' => $this->dateFormatter->format($this->revision->getRevisionCreationTime())]); + return $this->t('Are you sure you want to revert @language translation to the revision from %revision-date?', [ + '@language' => $this->languageManager->getLanguageName($this->langcode), + '%revision-date' => $this->dateFormatter->format($this->revision->getRevisionCreationTime()), + ]); } /** diff --git a/templates/module/src/Entity/Form/entity-content-revision-revert.php.twig b/templates/module/src/Entity/Form/entity-content-revision-revert.php.twig index 9a29d9281..2a4933509 100644 --- a/templates/module/src/Entity/Form/entity-content-revision-revert.php.twig +++ b/templates/module/src/Entity/Form/entity-content-revision-revert.php.twig @@ -66,7 +66,7 @@ class {{ entity_class }}RevisionRevertForm extends ConfirmFormBase {% endblock % */ public static function create(ContainerInterface $container) { return new static( - $container->get('entity.manager')->getStorage('{{ entity_name }}'), + $container->get('entity_type.manager')->getStorage('{{ entity_name }}'), $container->get('date.formatter') ); } @@ -82,7 +82,9 @@ class {{ entity_class }}RevisionRevertForm extends ConfirmFormBase {% endblock % * {@inheritdoc} */ public function getQuestion() { - return t('Are you sure you want to revert to the revision from %revision-date?', ['%revision-date' => $this->dateFormatter->format($this->revision->getRevisionCreationTime())]); + return $this->t('Are you sure you want to revert to the revision from %revision-date?', [ + '%revision-date' => $this->dateFormatter->format($this->revision->getRevisionCreationTime()), + ]); } /** @@ -96,7 +98,7 @@ class {{ entity_class }}RevisionRevertForm extends ConfirmFormBase {% endblock % * {@inheritdoc} */ public function getConfirmText() { - return t('Revert'); + return $this->t('Revert'); } /** @@ -125,11 +127,13 @@ class {{ entity_class }}RevisionRevertForm extends ConfirmFormBase {% endblock % $original_revision_timestamp = $this->revision->getRevisionCreationTime(); $this->revision = $this->prepareRevertedRevision($this->revision, $form_state); - $this->revision->revision_log = t('Copy of the revision from %date.', ['%date' => $this->dateFormatter->format($original_revision_timestamp)]); + $this->revision->revision_log = $this->t('Copy of the revision from %date.', [ + '%date' => $this->dateFormatter->format($original_revision_timestamp), + ]); $this->revision->save(); $this->logger('content')->notice('{{ label }}: reverted %title revision %revision.', ['%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()]); - \Drupal::messenger()->addMessage(t('{{ label }} %title has been reverted to the revision from %revision-date.', ['%title' => $this->revision->label(), '%revision-date' => $this->dateFormatter->format($original_revision_timestamp)])); + $this->messenger()->addMessage(t('{{ label }} %title has been reverted to the revision from %revision-date.', ['%title' => $this->revision->label(), '%revision-date' => $this->dateFormatter->format($original_revision_timestamp)])); $form_state->setRedirect( 'entity.{{ entity_name }}.version_history', ['{{ entity_name }}' => $this->revision->id()] diff --git a/templates/module/src/Entity/Form/entity-content.php.twig b/templates/module/src/Entity/Form/entity-content.php.twig index 6be6dd2e6..0b3ea48ad 100644 --- a/templates/module/src/Entity/Form/entity-content.php.twig +++ b/templates/module/src/Entity/Form/entity-content.php.twig @@ -9,8 +9,13 @@ namespace Drupal\{{module}}\Form; {% endblock %} {% block use_class %} +use Drupal\Component\Datetime\TimeInterface; use Drupal\Core\Entity\ContentEntityForm; +use Drupal\Core\Entity\EntityRepositoryInterface; +use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Session\AccountProxyInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; {% endblock %} {% block class_declaration %} @@ -21,11 +26,49 @@ use Drupal\Core\Form\FormStateInterface; */ class {{ entity_class }}Form extends ContentEntityForm {% endblock %} {% block class_methods %} + /** + * The current user account. + * + * @var \Drupal\Core\Session\AccountProxyInterface + */ + protected $account; + + /** + * Constructs a new {{ entity_class }}Form. + * + * @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository + * The entity repository service. + * @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info + * The entity type bundle service. + * @param \Drupal\Component\Datetime\TimeInterface $time + * The time service. + * @param \Drupal\Core\Session\AccountProxyInterface $account + * The current user account. + */ + public function __construct(EntityRepositoryInterface $entity_repository, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, TimeInterface $time = NULL, AccountProxyInterface $account) { + parent::__construct($entity_repository, $entity_type_bundle_info, $time); + + $this->account = $account; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + // Instantiates this form class. + return new static( + $container->get('entity.repository'), + $container->get('entity_type.bundle.info'), + $container->get('datetime.time'), + $container->get('current_user') + ); + } + /** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { - /* @var $entity \Drupal\{{module}}\Entity\{{ entity_class }} */ + /* @var \Drupal\{{module}}\Entity\{{ entity_class }} $entity */ $form = parent::buildForm($form, $form_state); {% if revisionable %} @@ -56,8 +99,8 @@ class {{ entity_class }}Form extends ContentEntityForm {% endblock %} $entity->setNewRevision(); // If a new revision is created, save the current user as revision author. - $entity->setRevisionCreationTime(REQUEST_TIME); - $entity->setRevisionUserId(\Drupal::currentUser()->id()); + $entity->setRevisionCreationTime($this->time->getRequestTime()); + $entity->setRevisionUserId($this->account->id()); } else { $entity->setNewRevision(FALSE); @@ -66,11 +109,18 @@ class {{ entity_class }}Form extends ContentEntityForm {% endblock %} $status = parent::save($form, $form_state); - $this->messenger()->addMessage($this->t('%action the %label {{ label }}.', [ - '%action' => $status == SAVED_NEW ? 'Created' : 'Saved', - '%label' => $entity->label(), - ])); + switch ($status) { + case SAVED_NEW: + $this->messenger()->addMessage($this->t('Created the %label {{ label }}.', [ + '%label' => $entity->label(), + ])); + break; + default: + $this->messenger()->addMessage($this->t('Saved the %label {{ label }}.', [ + '%label' => $entity->label(), + ])); + } $form_state->setRedirect('entity.{{ entity_name }}.canonical', ['{{ entity_name }}' => $entity->id()]); } {% endblock %} diff --git a/templates/module/src/Entity/entity-content-views-data.php.twig b/templates/module/src/Entity/entity-content-views-data.php.twig index c8ee2645b..eeb97705b 100644 --- a/templates/module/src/Entity/entity-content-views-data.php.twig +++ b/templates/module/src/Entity/entity-content-views-data.php.twig @@ -26,7 +26,6 @@ class {{ entity_class }}ViewsData extends EntityViewsData {% endblock %} // Additional information for Views integration, such as table joins, can be // put here. - return $data; } {% endblock %} diff --git a/templates/module/src/Entity/entity-content-with-bundle.theme_hook_suggestions.php.twig b/templates/module/src/Entity/entity-content-with-bundle.theme_hook_suggestions.php.twig index 77ea4dfbb..b95afecd4 100644 --- a/templates/module/src/Entity/entity-content-with-bundle.theme_hook_suggestions.php.twig +++ b/templates/module/src/Entity/entity-content-with-bundle.theme_hook_suggestions.php.twig @@ -1,8 +1,8 @@ {% block hook_theme_suggestions_hook %} /** -* Implements hook_theme_suggestions_HOOK(). -*/ + * Implements hook_theme_suggestions_HOOK(). + */ function {{ module }}_theme_suggestions_{{ entity_name }}(array $variables) { $suggestions = []; $entity = $variables['elements']['#{{ entity_name }}']; diff --git a/templates/module/src/Entity/entity-content.php.twig b/templates/module/src/Entity/entity-content.php.twig index 35d9ce371..4a6d2cbbe 100644 --- a/templates/module/src/Entity/entity-content.php.twig +++ b/templates/module/src/Entity/entity-content.php.twig @@ -152,7 +152,7 @@ class {{ entity_class }} extends {% if revisionable %}RevisionableContentEntityB public function preSave(EntityStorageInterface $storage) { parent::preSave($storage); - {% if is_translatable %} +{% if is_translatable %} foreach (array_keys($this->getTranslationLanguages()) as $langcode) { $translation = $this->getTranslation($langcode); @@ -161,10 +161,10 @@ class {{ entity_class }} extends {% if revisionable %}RevisionableContentEntityB $translation->setOwnerId(0); } } - {% endif %} +{% endif %} - // If no revision author has been set explicitly, make the {{ entity_name }} owner the - // revision author. + // If no revision author has been set explicitly, + // make the {{ entity_name }} owner the revision author. if (!$this->getRevisionUser()) { $this->setRevisionUserId($this->getOwnerId()); } diff --git a/templates/module/src/Entity/interface-entity-content.php.twig b/templates/module/src/Entity/interface-entity-content.php.twig index 12b4fdafa..4f9e3795a 100644 --- a/templates/module/src/Entity/interface-entity-content.php.twig +++ b/templates/module/src/Entity/interface-entity-content.php.twig @@ -26,7 +26,9 @@ use Drupal\user\EntityOwnerInterface; */ interface {{ entity_class }}Interface extends ContentEntityInterface{% if revisionable %}, RevisionLogInterface{% endif %}, EntityChangedInterface, EntityPublishedInterface, EntityOwnerInterface {% endblock %} {% block class_methods %} - // Add get/set methods for your configuration properties here. + /** + * Add get/set methods for your configuration properties here. + */ /** * Gets the {{ label }} name. @@ -67,7 +69,6 @@ interface {{ entity_class }}Interface extends ContentEntityInterface{% if revisi public function setCreatedTime($timestamp); {% if revisionable %} - /** * Gets the {{ label }} revision creation timestamp. * diff --git a/templates/module/src/Form/entity-delete.php.twig b/templates/module/src/Form/entity-delete.php.twig index 2bbed35cd..cde34514c 100644 --- a/templates/module/src/Form/entity-delete.php.twig +++ b/templates/module/src/Form/entity-delete.php.twig @@ -47,13 +47,11 @@ class {{ entity_class }}DeleteForm extends EntityConfirmFormBase {% endblock %} public function submitForm(array &$form, FormStateInterface $form_state) { $this->entity->delete(); - \Drupal::messenger()->addMessage( - $this->t('content @type: deleted @label.', - [ - '@type' => $this->entity->bundle(), - '@label' => $this->entity->label(), - ] - ) + $this->messenger()->addMessage( + $this->t('content @type: deleted @label.', [ + '@type' => $this->entity->bundle(), + '@label' => $this->entity->label(), + ]) ); $form_state->setRedirectUrl($this->getCancelUrl()); diff --git a/templates/module/src/Form/entity.php.twig b/templates/module/src/Form/entity.php.twig index ed0fe6aa1..1c8a54c26 100644 --- a/templates/module/src/Form/entity.php.twig +++ b/templates/module/src/Form/entity.php.twig @@ -58,13 +58,13 @@ class {{ entity_class }}Form extends EntityForm {% endblock %} switch ($status) { case SAVED_NEW: - \Drupal::messenger()->addMessage($this->t('Created the %label {{ label }}.', [ + $this->messenger()->addMessage($this->t('Created the %label {{ label }}.', [ '%label' => ${{ entity_name | machine_name }}->label(), ])); break; default: - \Drupal::messenger()->addMessage($this->t('Saved the %label {{ label }}.', [ + $this->messenger()->addMessage($this->t('Saved the %label {{ label }}.', [ '%label' => ${{ entity_name | machine_name }}->label(), ])); } diff --git a/templates/module/src/Form/form.php.twig b/templates/module/src/Form/form.php.twig index 8bcae4455..1a873493f 100644 --- a/templates/module/src/Form/form.php.twig +++ b/templates/module/src/Form/form.php.twig @@ -117,6 +117,5 @@ class {{ class_name }} extends FormBase {% endblock %} foreach ($form_state->getValues() as $key => $value) { \Drupal::messenger()->addMessage($key . ': ' . $value); } - } {% endblock %} diff --git a/templates/module/src/entity-content-route-provider.php.twig b/templates/module/src/entity-content-route-provider.php.twig index 9840ce26a..6ed15308a 100644 --- a/templates/module/src/entity-content-route-provider.php.twig +++ b/templates/module/src/entity-content-route-provider.php.twig @@ -209,4 +209,4 @@ class {{ entity_class }}HtmlRouteProvider extends AdminHtmlRouteProvider {% endb return $route; } } -{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/templates/module/src/entity-route-provider.php.twig b/templates/module/src/entity-route-provider.php.twig index 860d7b307..c7b33fdf4 100644 --- a/templates/module/src/entity-route-provider.php.twig +++ b/templates/module/src/entity-route-provider.php.twig @@ -11,7 +11,6 @@ namespace Drupal\{{ module }}; {% block use_class %} use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider; -use Symfony\Component\Routing\Route; {% endblock %} {% block class_declaration %} @@ -30,7 +29,6 @@ class {{ entity_class }}HtmlRouteProvider extends AdminHtmlRouteProvider {% endb $collection = parent::getRoutes($entity_type); // Provide your custom entity routes here. - return $collection; } {% endblock %} diff --git a/templates/module/src/entity-translation-handler.php.twig b/templates/module/src/entity-translation-handler.php.twig index 4ca6378ec..39e4661b0 100644 --- a/templates/module/src/entity-translation-handler.php.twig +++ b/templates/module/src/entity-translation-handler.php.twig @@ -15,4 +15,4 @@ use Drupal\content_translation\ContentTranslationHandler; class {{ entity_class }}TranslationHandler extends ContentTranslationHandler {% endblock %} {% block class_methods %} // Override here the needed methods from ContentTranslationHandler. -{% endblock %} +{%- endblock -%} \ No newline at end of file diff --git a/templates/module/src/interface-entity-storage.php.twig b/templates/module/src/interface-entity-storage.php.twig index 6baf05cba..d3abdd4bc 100644 --- a/templates/module/src/interface-entity-storage.php.twig +++ b/templates/module/src/interface-entity-storage.php.twig @@ -51,6 +51,7 @@ interface {{ entity_class }}StorageInterface extends ContentEntityStorageInterfa */ public function userRevisionIds(AccountInterface $account); {% if is_translatable %} + /** * Counts the number of revisions in the default language. * diff --git a/templates/module/src/listbuilder-entity-content.php.twig b/templates/module/src/listbuilder-entity-content.php.twig index 46af6648c..f08940816 100644 --- a/templates/module/src/listbuilder-entity-content.php.twig +++ b/templates/module/src/listbuilder-entity-content.php.twig @@ -21,8 +21,8 @@ use Drupal\Core\Link; * @ingroup {{ module }} */ class {{ entity_class }}ListBuilder extends EntityListBuilder {% endblock %} -{% block class_methods %} +{% block class_methods %} /** * {@inheritdoc} */ @@ -36,7 +36,7 @@ class {{ entity_class }}ListBuilder extends EntityListBuilder {% endblock %} * {@inheritdoc} */ public function buildRow(EntityInterface $entity) { - /* @var $entity \Drupal\{{module}}\Entity\{{ entity_class }} */ + /* @var \Drupal\{{module}}\Entity\{{ entity_class }} $entity */ $row['id'] = $entity->id(); $row['name'] = Link::createFromRoute( $entity->label(),