Problem/Motivation

When deleting bundles (eg. node types), their language configuration is not deleted.

Proposed resolution

Make sure they are deleted and add tests.

Remaining tasks

Review. Commit.

User interface changes

No.

API changes

No.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kfritsche’s picture

Status: Active » Needs review
FileSize
4.13 KB

Proposal

Everything in the configuration will be deleted, when a bundle is deleted, so this should be deleted to.

We already have a language_node_type_update in language, to detect changes in the bundle name, so it could be easily added a delete hook to. Attached a inital patch for this.

I wonder why a node_type_update is used and not a entity_bundle_rename? So only when node bundles are changed the bundle keeps the translation settings. In the VocabularyFormController is a special submit function to take care of that, which could be removed. Further comment bundles are currently not renamed at all. Didn't changed it yet, as I'm not sure of the impact.

Also I noticed while testing, when creating a new bundle a entry in language.settings.yml is added, with no bundle name. In the element process function is the old value and not the new one. Added TODO in attached patch.

Added a rename and delete entity_bundle function for translation_entity too, as there its completly missing. Here the problem is that after renaming is done, somewhere the translation data are set again, with the old bundle name. Didn't figured out yet, where this is happening.

YesCT’s picture

Note, when working on #1945226: Add language selector on menus I also got an empty machine name saved in language settings. That's when I figured out what the submit handler was for that was in the taxonomy example I was basing it off of.

See #51 and #59

I dont know if something generic can be added to language, so that every entity does not need to have this custom thing.

YesCT’s picture

opened #2015615: Comment bundles, other newly languagifiied entities get empty machine in language.settings.yml without custom submit handler

need to clarify (on that issue is fine) what are the steps to reproduce the empty machine name in language settings? Was it for comments? How did you make a new comment bundle?

YesCT’s picture

adding the link to the todo issue, and change https://drupal.org/node/1354#inheritdoc (and copy and paste which referenced delete for the rename inherit) and used https://drupal.org/node/1354#todo format for @todo

Gábor Hojtsy’s picture

Status: Needs review » Needs work

The meat of the test is commented out, so not sure it proves anything (yet). Comments on the code:

+++ b/core/modules/language/language.moduleundefined
@@ -315,6 +315,8 @@ function language_configuration_element_process($element, &$form_state, &$form)
+  // @todo On bundle create $element['#entity_information']['bundle'] is empty.
+  //   http://drupal.org/node/2015615

I don't think we need to mention this here, we have an issue for this one.

+++ b/core/modules/language/language.moduleundefined
@@ -420,6 +438,13 @@ function language_node_type_update($info) {
 /**
+ * {@inheritdoc}
+ */
+function language_entity_bundle_delete($entity_type, $bundle) {

+++ b/core/modules/translation_entity/translation_entity.moduleundefined
@@ -1038,3 +1038,33 @@ function translation_entity_save_settings($settings) {
+/**
+ * {@inheritdoc}
+ */
+function translation_entity_entity_bundle_delete($entity_type, $bundle) {
...
+/**
+ * {@inheritdoc}
+ */
+function translation_entity_entity_bundle_rename($entity_type, $bundle_old, $bundle_new) {

How can procedural functions have inheritdoc? Where would they inherit from?!

YesCT’s picture

Assigned: Unassigned » YesCT

oops. hooks!

YesCT’s picture

Assigned: YesCT » Unassigned
Status: Needs work » Needs review
FileSize
1.34 KB
8.22 KB

Sorry about that, hooks dont use inheritdoc!
https://drupal.org/node/1354#functions

YesCT’s picture

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

Oops. I think I accidentally included the test from #1945226: Add language selector on menus when I made one of the patches above.
That needs to be taken out of this patch.

I think a test here should be a test on the test Enitity.

YesCT’s picture

Assigned: Unassigned » YesCT

I'll work on this.

YesCT’s picture

Status: Needs work » Needs review
FileSize
927 bytes
4.11 KB
4.12 KB

Just undoing stuff I messed up since #1.
so change since #1, is just adding a link to the issue the todo is for.
@Gábor Hojtsy throught we might be able to just delete the todo since there is an issue, but I thought we kept them in the code too sometimes.
I dont mind either way.

The only other change from #1 is reverting the permissions on .module

After this, I'll try and add a test.

YesCT’s picture

manually testing this patch, I find it fixes this other problem #1739928-176: Generalize language configuration on content types to apply to terms and other entities that results from changing the machine name.

Status: Needs review » Needs work

The last submitted patch, drupal-2014955-deleting-bundle-translation-settings-10.patch, failed testing.

YesCT’s picture

Assigned: YesCT » Unassigned
Status: Needs work » Needs review
FileSize
2.6 KB
6.02 KB

I didn't get very far on this today. Taking a break, so someone else can work on the test.

This fixes the hook name I noticed earlier (but got lost in the inheritdoc debacle) .

Does the location for this test seem reasonable?
Note the test doesn't work. I'm not sure how to "delete" the bundle. I'm not even sure if that bundle was created, or if it's just a name being used to set the config stuff.

Berdir’s picture

Status: Needs review » Needs work
+++ b/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationElementTest.phpundefined
@@ -137,4 +137,30 @@ public function testNodeTypeUpdate() {
+    // Delete the bundle.
+    // ... how?

As this entity type does not actually exist and you can't delete it for real, you need to invoke the hook that would be invoked if the bundle would be deleted directly:

entity_invoke_bundle_hook('delete', 'some_entity_type', 'some_bundle') should do the trick.

jair’s picture

Issue tags: +Needs reroll
balintcsaba’s picture

Assigned: Unassigned » balintcsaba
Issue summary: View changes
balintcsaba’s picture

Assigned: balintcsaba » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
4.5 KB

Rerolled.

Status: Needs review » Needs work

The last submitted patch, 17: 2014955-17.patch, failed testing.

balintcsaba’s picture

Status: Needs work » Needs review
FileSize
4.52 KB
4.52 KB

rerolled

Status: Needs review » Needs work

The last submitted patch, 19: 2014955-19.patch, failed testing.

mgifford’s picture

stefank’s picture

Assigned: Unassigned » stefank
Issue tags: +sprint Amsterdam2014

Im at DrupalCon Amsterdam 2014 and working on it.

Anonymous’s picture

Issue tags: -sprint Amsterdam2014 +sprint, +Amsterdam2014
kfritsche’s picture

Assigned: stefank » Unassigned
Status: Needs work » Needs review
FileSize
2.94 KB
2.19 KB
4.78 KB

Rerolled.

Finished the test which was started but didn't worked yet.

The last submitted patch, 24: 2014955-24-test-only.patch, failed testing.

The last submitted patch, 24: 2014955-24-test-only.patch, failed testing.

Sutharsan’s picture

Issue summary "Proposed resolutions" needs update.

andypost’s picture

I think the scope is too small, this require CUD covered or at least issue for update needed

+++ b/core/modules/language/language.module
@@ -277,6 +293,8 @@ function language_node_type_update(NodeTypeInterface $type) {

+function language_entity_bundle_delete($entity_type, $bundle) {

so update supported only for node types?

penyaskito’s picture

Gábor Hojtsy’s picture

Status: Needs review » Postponed

Postponing on #2355909: language.settings config is not scalable then. That should provide full CRUD but tests that it happens on entity bundle actions will still be useful unless already added there.

Gábor Hojtsy’s picture

Issue tags: -sprint
Gábor Hojtsy’s picture

Status: Postponed » Postponed (maintainer needs more info)
penyaskito’s picture

Status: Postponed (maintainer needs more info) » Needs work

Yep, we covered this, but we miss test coverage for deletion (we have for addition and update).

We should reuse the test (and update the IS).

Gábor Hojtsy’s picture

Title: Deleting bundles do not have their language configuration deleted from language.settings.yml » Add tests that deleting bundles do have their language configuration deleted
Issue summary: View changes
Issue tags: -Needs issue summary update +SprintWeekend2015Queue

Retitled for what needs to be done. Updated issue summary.

penyaskito’s picture

Issue tags: +SprintWeekend2015

I'm working on this one in context of the Global Sprint Weekend 2015.

DevElCuy’s picture

Issue tags: -SprintWeekend2015Queue
DevElCuy’s picture

Issue tags: +SprintWeekend2015Queue

Removed tag by mistake.

penyaskito’s picture

Mmmmm... interesting.

The test actually reveals that this is still a bug on HEAD. But I expected this to be solved by the configuration dependencies. What's wrong there? The proposed fix may not be the best way, as IMHO this should be handled at the config dependency level.

The last submitted patch, 39: 2014955-config-language-deleted-38-ONLY-TEST.patch, failed testing.

alexpott’s picture

Status: Needs review » Needs work

There is nothing automatic about deleting a config entity that is a dependency of another config entity and having that config entity deleted. The only place where something like this occurs in extension uninstall.

+++ b/core/modules/language/language.module
@@ -232,6 +232,15 @@ function language_entity_bundle_rename($entity_type_id, $bundle_old, $bundle_new
+  // Remove the content language settings associated with the bundle.
+  ContentLanguageSettings::loadByEntityTypeBundle($entity_type_id, $bundle)
+    ->delete();

This should only do the delete if it needs to. I've never really liked the fact that the load creates new object. Feels icky.

Berdir’s picture

Well, not creating the object would mean that we would need 5 lines of code instead of 2 everywhere where we use it. But yes, should do an !isNew() check.

Gábor Hojtsy’s picture

Title: Add tests that deleting bundles do have their language configuration deleted » Deleted bundles do not have their language configuration deleted
Issue summary: View changes
Issue tags: -Needs tests +sprint

Retitled according to the current status. Also updated issue summary.

penyaskito’s picture

Checked that the entity existed before deleting.

Berdir’s picture

I think #2416409: Delete dependent config entities that don't implement onDependencyRemoval() when a config entity is deleted should take care of this automatically, we're finally at a place to automatically act based on the dependency information that we have.

The last submitted patch, 44: 2014955-config-language-deleted-44.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 44: 2014955-config-language-deleted-44.only-test.patch, failed testing.

Status: Needs work » Needs review
penyaskito’s picture

@Berdir: that's awesome! I missed that one.
However IMHO getting this in still is interesting because of the additional tests.

Status: Needs review » Needs work

The last submitted patch, 44: 2014955-config-language-deleted-44.only-test.patch, failed testing.

penyaskito’s picture

Status: Needs work » Needs review

Wrong order of the patch uploads, oops.

Gábor Hojtsy’s picture

Status: Needs review » Needs work

I agree additional test coverage would be useful even if the other one fixes the issue. Only found English issues.

  1. +++ b/core/modules/language/src/Tests/LanguageConfigurationElementTest.php
    @@ -164,6 +164,41 @@ public function testNodeTypeUpdate() {
    +   * Tests the language setting are deleted on bundle delete.
    

    settings

  2. +++ b/core/modules/language/src/Tests/LanguageConfigurationElementTest.php
    @@ -164,6 +164,41 @@ public function testNodeTypeUpdate() {
    +    // Create are language configuration for the articles.
    

    Remove "are" IMHO, I think you meant "our" but its fine without it.

  3. +++ b/core/modules/language/src/Tests/LanguageConfigurationElementTest.php
    @@ -164,6 +164,41 @@ public function testNodeTypeUpdate() {
    +    // Check the language default configuration for the articles is present.
    

    Remove the second "the".

  4. +++ b/core/modules/language/src/Tests/LanguageConfigurationElementTest.php
    @@ -164,6 +164,41 @@ public function testNodeTypeUpdate() {
    +    // Delete the articles bundle.
    

    "article" is the bundle name.

  5. +++ b/core/modules/language/src/Tests/LanguageConfigurationElementTest.php
    @@ -164,6 +164,41 @@ public function testNodeTypeUpdate() {
    +    // Check that the language configuration have been deleted.
    

    has been?

    (given its one file).

  6. +++ b/core/modules/language/src/Tests/LanguageConfigurationElementTest.php
    @@ -164,6 +164,41 @@ public function testNodeTypeUpdate() {
    +    $this->assertFalse($configuration, 'The language configuration were deleted after bundle were deleted.');
    

    was instead of were for both no?

penyaskito’s picture

Status: Needs work » Needs review
FileSize
9.85 KB
2.23 KB

Fixed grammar.

Gábor Hojtsy’s picture

Status: Needs review » Reviewed & tested by the community

All righto, thanks!

Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Needs work

Wait, patch includes unrelated things.

penyaskito’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
2.85 KB

Oops, wrong patch. Interdiff was right.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

This issue is a normal bug fix, and doesn't include any disruptive changes, so it is allowed per https://www.drupal.org/core/beta-changes. Committed 6cfaed4 and pushed to 8.0.x. Thanks!

  • alexpott committed 6cfaed4 on 8.0.x
    Issue #2014955 by YesCT, penyaskito, kfritsche, balintcsaba: Deleted...
Gábor Hojtsy’s picture

Issue tags: -sprint

Yay, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.