Problem/Motivation

Currently, the Content Translation Controller generates a table to display the status of translations for a content entity.

Because this is not rendered in a form, there is nothing to hook into in order to modify this form; so changing the content of the Translate page is only possible by altering the route for the following method:

\Drupal\content_translation\Controller\ContentTranslationController::overview

When more than one contributed module does this, the modules are no longer compatible and so become mutually exclusive. It would be good for the Lingotek module, the TMGMT module, and any other module that would like to modify translation pages for content entities to be able to do so without having to exclude each other in a given Drupal instance.

Proposed resolution (some ideas)

  1. One idea is to create a hook somewhere for modifying the page. (There does not seem to be a clear place for this that would allow all elements of the page to be changed.)
  2. Another idea is to convert this page to a form, or else to provide an empty form that could be manipulated by multiple modules.

Remaining tasks

1. Decide on an approach that could let multiple modules modify the page.
2. Write a patch.
3. Review and test.

User interface changes

TBD

API changes

TBD

Issue fork drupal-2351685

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’s picture

Category: Feature request » Task

I think this is arguably a task, not sure if it could still get into 8.0.x or not though.

plach’s picture

Title: Convert table for Content Translation Controller into a form » Make the content translation overview alterable by multiple modules
Priority: Major » Normal
Issue tags: +D8MI, +language-content

Asked @WimLeers to provide feedback on this.

wim leers’s picture

For entities, we have hook_entity_view_alter(), for blocks, we have hook_block_view_alter(), for Views we also have alter hooks.

But this is just a route whose controller returns a render array.

Seemingly the only way you can currently override it is by replacing the controller, as plach pointed out, and that's a problem as soon as >1 module wants to do that.

But there's one more way :) A KernelEvents::VIEW event subscriber that does a is_array($response) && $route_match->getRouteName() == 'the route name' check, and then modifies the render array in $response.

fabianx’s picture

I think a hook would be better than the KernelEvents::VIEW.

The overall out solution would be to have a plugin manager that calls plugins as a chain-of-responsibility.

The simple way is to have a supported alter hook and then can use e.g. #pre_render callbacks ...

Though I must admit that KernelEvents::VIEW also would support adding just to #pre_render, which probably would be fine then ...

Edit to clarify:

My main concern with using a generic hook like Events::VIEW for doing something specific is that if everyone does that then ordering issues occur, while for a specific hook to alter e.g. the table, the modules could negotiate on and around themselves and then the generic ::VIEW would work like normal.

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

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.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.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.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.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.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.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should 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.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should 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.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should 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.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.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: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should 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: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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

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

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should 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.

hchonov’s picture

Status: Active » Needs review
StatusFileSize
new2.58 KB

A small patch that adds a hook. I do not think that we need to convert the controller to a form since the major place that might require some changes by other modules is the render array of the content translation overview. I've also made one further change to use the langcode as a key for the rows instead of numeric values so that it makes it possible for developers to easily identify the rows for the translations.

joachim’s picture

antoniya’s picture

Hi @hchonov, why is this check for German language in the patch?

if ($langcode === 'de') {
  unset($links['edit']);
}

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

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should 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.

anup.sinha’s picture

Hi @hchonov, Can you please reply to Antoniya's question why a condition for a specific language.

Also I think this should be a high priority task as currently we don't have any option to alter the translate overview table. This is really a blocker if we want to add a button for any content translation service or do any modification into that table.

Thanks & Regards,
Anup

anup.sinha’s picture

Status: Needs review » Needs work

Hi @All,

I have validated the latest patch and the newly created hook is not working. I have implemented the new hook in my custom module and getting the below error -

[03-Feb-2023 12:36:33 Asia/Kolkata] Uncaught PHP Exception Error: "Cannot use object of type Drupal\Core\StringTranslation\TranslatableMarkup as array" at C:\wamp64\www\drupal-10.0.0\modules\custom\content_view_alter\content_view_alter.module line 14

Line #14 - "if (isset($column['data']['#type']) && ($column['data']['#type'] === 'operations')) {"

Also whenever a new hook is created, please add a new test for it as the code added in api.php will have not be executed until we are implementing it. So it's very important to have a test for any hook. Changing the ticket status to Needs work.

Thanks & Regards,
Anup

Gunjan Rao Naik’s picture

StatusFileSize
new1.26 KB

Added patch against #16 in 10.1 version

smustgrave credited sonfd.

smustgrave’s picture

sonfd’s picture

https://www.drupal.org/project/drupal/issues/3227102 also gave columns non-numeric, descriptive keys, see patch #2 from that issue. +1 for doing that here too.

miiimooo’s picture

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

+1 from me for this patch.

I have added an example project that is useful when there are many languages installed on a site here https://www.drupal.org/sandbox/miiimooo/3414705

The project depends on this patch at the moment

Left Todo:
* Document in content_translation.api.php

miiimooo’s picture

Issue tags: +content translation

Version: 10.0.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. 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.

majid.ali made their first commit to this issue’s fork.