Problem/Motivation

I recently saw a site (in D7) where the body field was deleted. No log message surfaced. I confirmed this is still an issue in D8. If a user deletes a content type, the action is logged, so it seems to make sense to log field deletion too. There are probably numerous other places where we could add logging too.

Proposed resolution

Log field deletions.

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork drupal-2859735

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

jhedstrom created an issue. See original summary.

jhedstrom’s picture

Status: Active » Needs review
StatusFileSize
new2.64 KB
jhedstrom’s picture

StatusFileSize
new574 bytes
new2.51 KB

Removes an unused use statement.

krina.addweb’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new33.9 KB

@jhedstrom,Thanks for the patch i checked it over simplytest.Me & it works well it adds the delete logs to report.

xjm’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

Thanks @krina.addweb for manually testing this! The screenshot is helpful.

This seems like a good idea. We should add automated tests for it as well, though.

jhedstrom’s picture

Status: Needs work » Needs review

We should add automated tests for it as well, though.

I started to look into doing this, and realized I don't think we have a generic way of testing for log messages. I was hoping the test base classes added an in-memory logger, so there would then be a simple assertLogMessage() that could be called.

We could add a one-off here for field_ui, but that seems messy (eg, enable dblog, check db for message, etc).

Thoughts?

jhedstrom’s picture

jhedstrom’s picture

Issue tags: -Needs tests

Since we currently don't have testing for the logging of messages anywhere in our test framework outside of explicit dblog module tests (see #2862282: Add a test logger channel for test base classes to use), I don't think that should hold this task up. Our existent test coverage verifies the message logged to the screen, and since tests are green here, I think we could proceed...

dagmar’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

We could add a one-off here for field_ui, but that seems messy (eg, enable dblog, check db for message, etc).

It seems #2862282: Add a test logger channel for test base classes to use is a bit blocked. My recommendation here is to install dblog in the test and make the assertion. We are doing this in other tickets #2793637: Use human readable dates for one-link login log entries.:

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jhedstrom’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new3.48 KB
new6.31 KB

Since the issues to add a test logger are taking some time, and this issue really shouldn't depend on those, this adds a test for the logged message to the trait for field deletion. I added a todo for when the test logger issue is done.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

jhedstrom’s picture

StatusFileSize
new6.21 KB

Re-roll of #14.

mayurgajar’s picture

Assigned: Unassigned » mayurgajar
mayurgajar’s picture

Hi @ jhedstrom,

patch #16 apply cleanly LGTM +1 RTBC .

Thanks..!!!

mayurgajar’s picture

Status: Needs review » Reviewed & tested by the community
mayurgajar’s picture

StatusFileSize
new162.7 KB
alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/field_ui/src/Form/FieldConfigDeleteForm.php
@@ -24,14 +25,24 @@ class FieldConfigDeleteForm extends EntityDeleteForm {
+  /**
+   * The logger service.
+   *
+   * @var \Psr\Log\LoggerInterface
+   */
+  protected $logger;
+
...
-  public function __construct(EntityTypeBundleInfoInterface $entity_type_bundle_info) {
+  public function __construct(EntityTypeBundleInfoInterface $entity_type_bundle_info, LoggerInterface $logger) {
     $this->entityTypeBundleInfo = $entity_type_bundle_info;
+    $this->logger = $logger;

@@ -39,7 +50,8 @@ public function __construct(EntityTypeBundleInfoInterface $entity_type_bundle_in
+      $container->get('logger.channel.field_ui')

@@ -99,6 +111,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
+      $this->logger->info($this->t('The field %field has been deleted from the %type content type.', ['%field' => $this->entity->label(), '%type' => $bundle_label]));

As a form I'd use $this->logger('logger.channel.field_ui'). That way we don't need to wonder about deprecating calling the constructor with the logger channel. Way less change.

hardik_patel_12’s picture

StatusFileSize
new4.87 KB
new2.18 KB

Kindly review a patch , removing logger service injection and using $this->logger('logger.channel.field_ui') to log messsages.

hardik_patel_12’s picture

Assigned: mayurgajar » Unassigned
Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 22: add_log_messages_for-2859735-22.patch, failed testing. View results

Lal_’s picture

StatusFileSize
new4.86 KB

@hardik wrong name for the `type`

Lal_’s picture

Status: Needs work » Needs review
StatusFileSize
new1.09 KB

forgot the interdiff

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

vikashsoni’s picture

StatusFileSize
new182.9 KB

Apply #2 patch working fine add deleted fields in logger

sharing screenshot....

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new165 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.