I noticed recently that the Content Translation module still had a content_translation_enable() function even though hook_enable() has been removed.

I'm attaching a patch that moves the code that was previously in the content_translation_enable() to content_translation_install() instead.

Comments

matt v.’s picture

Status: Active » Needs review
plach’s picture

Status: Needs review » Needs work

Patch looks good, but we need some test coverage for this. Just checking whether messages are displayed.

joelpittet’s picture

Issue tags: +Needs tests

@plach should this test be for enabling/disabling modules with messages in the hook or just this specific module has that message after install?

plach’s picture

just this specific module has that message after install

:)

chi’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new3.13 KB

Re-rolled the previous patch and added test.

Status: Needs review » Needs work

The last submitted patch, 5: 2342015-5.patch, failed testing.

The last submitted patch, 5: 2342015-5.patch, failed testing.

gábor hojtsy’s picture

chi’s picture

Status: Needs work » Needs review
gábor hojtsy’s picture

Status: Needs review » Needs work

Needs work given it fails.

The last submitted patch, 5: 2342015-5.patch, failed testing.

chi’s picture

StatusFileSize
new534 bytes

Just wonder if this empty patch will fail.

chi’s picture

Status: Needs work » Needs review
chi’s picture

Assigned: Unassigned » chi
Status: Needs review » Needs work
chi’s picture

Assigned: chi » Unassigned
Status: Needs work » Needs review
StatusFileSize
new4.24 KB

HelpEmptyPageTest::testEmptyHookHelp() should only check hook_help() but not module installation process.

chi’s picture

StatusFileSize
new4.46 KB

Minor cleanup.

chi’s picture

vijaycs85’s picture

+++ b/core/modules/content_translation/content_translation.install
@@ -5,27 +5,28 @@
-}
...
-/**
- * Implements hook_enable().
- */
-function content_translation_enable() {

Discussed in #2632560-5: Content translation implements nonexistent hook_enable, we want to keep the function. So kinda like this:

index d44b2d1..11b30c5 100644
--- a/core/modules/content_translation/content_translation.install
+++ b/core/modules/content_translation/content_translation.install
@@ -12,10 +12,14 @@ function content_translation_install() {
   // Assign a fairly low weight to ensure our implementation of
   // hook_module_implements_alter() is run among the last ones.
   module_set_weight('content_translation', 10);
+  content_translation_enable();
 }

 /**
- * Implements hook_enable().
+ * Callback to provide warning messages on install.
+ *
+ * This is hook_enable() of Drupal < 8 versions. Left here to avoid fatal for
+ * direct calls from contrib modules.
  */
 function content_translation_enable() {
   // Translation works when at least two languages are added.
gábor hojtsy’s picture

Status: Needs review » Needs work
chi’s picture

Status: Needs work » Needs review
StatusFileSize
new4.73 KB

I marked content_translation_enable() as deprecated.

swentel’s picture

+++ b/core/modules/content_translation/content_translation.install
@@ -5,27 +5,38 @@
+ * because if Language module is enabled simultinuesly with Content translation

simultaneously

chi’s picture

StatusFileSize
new4.73 KB

Fixed typo.

Status: Needs review » Needs work

The last submitted patch, 22: 2342015-22.patch, failed testing.

rodrigoaguilera’s picture

I will give this a try for the sprint weekend

rodrigoaguilera’s picture

Status: Needs work » Needs review
rodrigoaguilera’s picture

Nothing to do actually, the patch and the test look OK to me.

vijaycs85’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +london_2016_january

Patch in #22 looks fine and applies to HEAD.

chandeepkhosa’s picture

Issue tags: +SprintWeekend2016
chandeepkhosa’s picture

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/content_translation/content_translation.install
@@ -5,27 +5,38 @@
+ * @deprecated in Drupal 8.0.x, will be removed before Drupal 9.0.0. This is

So the problem here is that we are not just going to remove this method we're going have to move the functionality to hook_install. BUT I have to disagree that hook implementations are API - you are not meant to call hooks directly and if you do that is wrong and contrary to our API. Therefore we should be able to remove hook implementations in minor versions at least. Especially hook implementations that have no impact.

All of this said I'm really sad that we're not using routes here - it feels really wrong. If a module depends on another module it ought to be able to rely on its routes being there. This code will break if someone installs language and alters the routes to have different paths (for whatever reason).

I think modules that need to be able to add post installation messages need to have a way to do so that is route safe. As this means a module can't even rely on its own routes.

berdir’s picture

alexpott’s picture

Yeah an @todo would help - probably pointing to #2589967: Rebuild routes immediately when modules are installed.

chi’s picture

Status: Needs work » Needs review
StatusFileSize
new4.32 KB
new1.82 KB

The patch is the same as #16 but with different comments.

vijaycs85’s picture

Status: Needs review » Reviewed & tested by the community

Looks good.

catch’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/content_translation/content_translation.install
@@ -12,20 +14,16 @@ function content_translation_install() {
     $message = t('Be sure to <a href=":language_url">add at least two languages</a> to translate content.', $t_args);

I know this isn't touched by the patch, but the string looks wrong to me. Sites will have one language installed, so they only need to add at least one language, not two.

Since this message isn't showing at all at the moment, seems like something we could change here. Or if not, let's open a follow-up.

catch’s picture

For the string something like:

This site has only a single language enabled. Add at least one more language in order to translate content.

chi’s picture

StatusFileSize
new4.49 KB
new1.46 KB
chi’s picture

Status: Needs work » Needs review
StatusFileSize
new1 KB
chi’s picture

StatusFileSize
new4.48 KB
new1.51 KB

I am not sure how it works before, but toUriString is not suitable here.

Status: Needs review » Needs work

The last submitted patch, 39: 2342015-39.patch, failed testing.

chi’s picture

Status: Needs work » Needs review
StatusFileSize
new4.53 KB
new936 bytes

Updated text in the test.

chi’s picture

We might want to assert URLs in those messages.

Status: Needs review » Needs work

The last submitted patch, 41: interdiff-39-41.patch, failed testing.

chi’s picture

Status: Needs work » Needs review
alexpott’s picture

Changing the translated string means that we can only do this in 8.1.x. I think we should make this change without the string change because then we can fix this in 8.0.x and 8.1.x and open a followup to change the message. Thanks for all the patches @Chi.

alexpott’s picture

Status: Needs review » Needs work

Back to needs work for #45

chi’s picture

Status: Needs work » Needs review
StatusFileSize
new4.32 KB
vijaycs85’s picture

gábor hojtsy’s picture

Status: Needs review » Reviewed & tested by the community

Looks good, thanks for the fixes.

catch’s picture

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

No longer applies to 8.1.x now that #2662078: Update the misleading warning message in Content Translation module has been committed, so needs a quick 8.1.x re-roll.

vijaycs85’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new4.36 KB

Quick reroll...

vijaycs85’s picture

Version: 8.0.x-dev » 8.1.x-dev

Status: Needs review » Needs work

The last submitted patch, 51: 2342015-8.1.x-51.patch, failed testing.

vijaycs85’s picture

Status: Needs work » Needs review

Changing the branch and retesting...

gábor hojtsy’s picture

Status: Needs review » Reviewed & tested by the community

Yay, thanks!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 51: 2342015-8.1.x-51.patch, failed testing.

The last submitted patch, 51: 2342015-8.1.x-51.patch, failed testing.

joelpittet’s picture

Status: Needs work » Needs review
StatusFileSize
new4.41 KB
new936 bytes

New test assertion needed to change with that string change too. Here's the fix, tested locally against that fail.

vijaycs85’s picture

Status: Needs review » Reviewed & tested by the community

ah right. I missed that why we had to re-roll. thanks @joelpittet. Now it's RTBC as per #55

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/help/src/Tests/HelpEmptyPageTest.php
@@ -7,7 +7,6 @@
-use Drupal\Core\DependencyInjection\ContainerBuilder;

@@ -34,15 +33,6 @@ protected function setUp() {
   /**
-   * {@inheritdoc}
-   */
-  public function containerBuild(ContainerBuilder $container) {
-    parent::containerBuild($container);
-
-    $container->set('url_generator', new SupernovaGenerator());
-  }
...
   public function testEmptyHookHelp() {

@@ -59,6 +49,10 @@ public function testEmptyHookHelp() {
+
+    // Enable URL generator which always throws an exception.
+    \Drupal::getContainer()->set('url_generator', new SupernovaGenerator());
+

I think this change is wrong. In reality the container should be frozen after the containerBuild is called.

Given this is a kernel test there is no need to call module install here. We can replace the module install with...

    $this->enableModules(array_keys($all_modules));
    $this->installEntitySchema('menu_link_content');
alexpott’s picture

We should also have a follow up to improve the HelpEmptyPageTest so that it tests that if a route is passed in to hook_help that the supernova generator does indeed throw an error.

chi’s picture

Status: Needs work » Needs review
StatusFileSize
new3.79 KB

$this->installEntitySchema('menu_link_content');

It's not clear what is so special with menu_link_content schema. Looks as some another trick at least if it is not commented.

gábor hojtsy’s picture

@chi: can you post an interdiff to help review?

The last submitted patch, 58: content_translation-2342015-58.patch, failed testing.

chi’s picture

StatusFileSize
new1.46 KB

Notice that patch in #58 is outdated because of #2338747: Move {router} out of system.install and create the table lazy.

Status: Needs review » Needs work

The last submitted patch, 65: interdiff-58-63.diff, failed testing.

chi’s picture

Status: Needs work » Needs review
StatusFileSize
new1.46 KB
gábor hojtsy’s picture

@chi: instead of an interdiff, can you roll an updated patch please?

chi’s picture

@Gábor Hojtsy, patch in #62 is up to date. It's made per #60 recommendations. I can also roll patch from #58 if needed.

gábor hojtsy’s picture

Status: Needs review » Reviewed & tested by the community

Yeah sorry for the misunderstanding. The fix looks fine to me, thanks for the update!

alexpott’s picture

@Chi it is not what is special with the menu_link_content schema - it is was is special about installing modules in a kernel test base. The module installer shouldn't be used for this and the class has it's own methods to enable modules in its funky way. We need to install the menu_link_content schema because that test depends on it.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 9ba7422 and pushed to 8.1.x. Thanks!

In addition to crediting those that provided a patch I've created @Gábor Hojtsy and myself for providing reviews and @catch for the suggestion that lead to #2662078: Update the misleading warning message in Content Translation module.

Given that nothing is actually broken I would hold off on porting this to 8.0.x - if people think I'm wrong please re-open the issue.

  • alexpott committed d5af255 on 8.1.x
    Issue #2342015 by Chi, joelpittet, vijaycs85, Matt V., Gábor Hojtsy,...
gábor hojtsy’s picture

Issue tags: -sprint

Yay, thanks! I think its fine on the 8.1 branch, it is soon released :)

Status: Fixed » Closed (fixed)

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