Issue #1952394 by vijaycs85, tstoeckler, webflo, Gábor Hojtsy, Schnitzel, falcon03, YesCT, kfritsche, Ryan Weal, dagmita, likin, toddtomlinson, nonsie, Kristen Pol, dawehner, tim.plunkett, penyaskito, EclipseGC, larowlan, robertdbailey, helenkim, David Hernández, EllaTheHarpy, lazysoundsystem, juanolalla, R.Hendel, Kartagis: Add configuration translation user interface module.
2013-11-18 02:41:04 +00:00
<?php
/**
* @file
* Configuration Translation module.
*/
use Drupal\config_translation\Plugin\Derivative\ConfigTranslationLocalTasks;
use Drupal\Core\Entity\EntityInterface;
2014-06-30 03:33:08 +00:00
use Drupal\Core\Routing\RouteMatchInterface;
Issue #1952394 by vijaycs85, tstoeckler, webflo, Gábor Hojtsy, Schnitzel, falcon03, YesCT, kfritsche, Ryan Weal, dagmita, likin, toddtomlinson, nonsie, Kristen Pol, dawehner, tim.plunkett, penyaskito, EclipseGC, larowlan, robertdbailey, helenkim, David Hernández, EllaTheHarpy, lazysoundsystem, juanolalla, R.Hendel, Kartagis: Add configuration translation user interface module.
2013-11-18 02:41:04 +00:00
use Symfony\Component\Routing\Exception\RouteNotFoundException;
/**
* Implements hook_help().
*/
2014-06-30 03:33:08 +00:00
function config_translation_help($route_name, RouteMatchInterface $route_match) {
2014-05-07 02:04:53 +00:00
switch ($route_name) {
case 'help.page.config_translation':
Issue #1952394 by vijaycs85, tstoeckler, webflo, Gábor Hojtsy, Schnitzel, falcon03, YesCT, kfritsche, Ryan Weal, dagmita, likin, toddtomlinson, nonsie, Kristen Pol, dawehner, tim.plunkett, penyaskito, EclipseGC, larowlan, robertdbailey, helenkim, David Hernández, EllaTheHarpy, lazysoundsystem, juanolalla, R.Hendel, Kartagis: Add configuration translation user interface module.
2013-11-18 02:41:04 +00:00
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
2014-06-25 21:10:11 +00:00
$output .= '<p>' . t('The Configuration Translation module allows you to translate configuration text; for example, the site name, vocabularies, menus, or date formats. Together with the modules <a href="!language">Language</a>, <a href="!content-translation">Content Translation</a>, and <a href="!locale">Interface Translation</a>, it allows you to build multilingual websites. For more information, see the <a href="!doc_url">online documentation for the Configuration Translation module</a>.', array('!doc_url' => 'https://drupal.org/documentation/modules/config_translation', '!config' => \Drupal::url('help.page', array('name' => 'config')), '!language' => \Drupal::url('help.page', array('name' => 'language')), '!locale' => \Drupal::url('help.page', array('name' => 'locale')), '!content-translation' => (\Drupal::moduleHandler()->moduleExists('content_translation')) ? \Drupal::url('help.page', array('name' => 'content_translation')) : '#')) . '</p>';
Issue #1952394 by vijaycs85, tstoeckler, webflo, Gábor Hojtsy, Schnitzel, falcon03, YesCT, kfritsche, Ryan Weal, dagmita, likin, toddtomlinson, nonsie, Kristen Pol, dawehner, tim.plunkett, penyaskito, EclipseGC, larowlan, robertdbailey, helenkim, David Hernández, EllaTheHarpy, lazysoundsystem, juanolalla, R.Hendel, Kartagis: Add configuration translation user interface module.
2013-11-18 02:41:04 +00:00
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
2014-06-25 21:10:11 +00:00
$output .= '<dt>' . t('Enabling translation') . '</dt>';
$output .= '<dd>' . t('In order to translate configuration, the website must have at least two <a href="!url">languages</a>.', array('!url' => \Drupal::url('language.admin_overview'))) . '</dd>';
$output .= '<dt>' . t('Translating configuration text') . '</dt>';
$output .= '<dd>' . t('Users with the <em>Translate user edited configuration</em> permission can access the configuration translation overview, and manage translations for specific languages. The <a href="!translation-page">Configuration translation</a> page shows a list of all configuration text that can be translated, either as individual items or as lists. After you click on <em>Translate</em>, you are provided with a list of all languages. You can <em>add</em> or <em>edit</em> a translation for a specific language. Users with specific configuration permissions can also <em>edit</em> the text for the site\'s default language. For some configuration text items (for example for the site information), the specific translation pages can also be accessed directly from their configuration pages.', array('!translation-page' => \Drupal::url('config_translation.mapper_list'))) . '</dd>';
$output .= '<dt>' . t('Translating date formats') . '</dt>';
$output .= '<dd>' . t('You can choose to translate date formats on the <a href="!translation-page">Configuration translation</a> page. This allows you not only to translate the label text, but also to set a language-specific <em>PHP date format</em>.', array('!translation-page' => \Drupal::url('config_translation.mapper_list'))) . '</dd>';
Issue #1952394 by vijaycs85, tstoeckler, webflo, Gábor Hojtsy, Schnitzel, falcon03, YesCT, kfritsche, Ryan Weal, dagmita, likin, toddtomlinson, nonsie, Kristen Pol, dawehner, tim.plunkett, penyaskito, EclipseGC, larowlan, robertdbailey, helenkim, David Hernández, EllaTheHarpy, lazysoundsystem, juanolalla, R.Hendel, Kartagis: Add configuration translation user interface module.
2013-11-18 02:41:04 +00:00
$output .= '</dl>';
return $output;
2014-05-07 02:04:53 +00:00
case 'config_translation.mapper_list':
2014-06-25 21:10:11 +00:00
$output = '<p>' . t('This page lists all configuration items on your site that have translatable text, like your site name, role names, etc.') . '</p>';
Issue #1952394 by vijaycs85, tstoeckler, webflo, Gábor Hojtsy, Schnitzel, falcon03, YesCT, kfritsche, Ryan Weal, dagmita, likin, toddtomlinson, nonsie, Kristen Pol, dawehner, tim.plunkett, penyaskito, EclipseGC, larowlan, robertdbailey, helenkim, David Hernández, EllaTheHarpy, lazysoundsystem, juanolalla, R.Hendel, Kartagis: Add configuration translation user interface module.
2013-11-18 02:41:04 +00:00
return $output;
}
}
/**
* Implements hook_theme().
*/
function config_translation_theme() {
return array(
'config_translation_manage_form_element' => array(
'render element' => 'element',
'template' => 'config_translation_manage_form_element',
),
);
}
2014-04-22 18:37:12 +00:00
/**
2014-09-19 09:25:26 +00:00
* Implements hook_themes_installed().
2014-04-22 18:37:12 +00:00
*/
2014-09-19 09:25:26 +00:00
function config_translation_themes_installed() {
2014-04-22 18:37:12 +00:00
// Themes can provide *.config_translation.yml declarations.
// @todo Make ThemeHandler trigger an event instead and make
// ConfigMapperManager plugin manager subscribe to it.
// @see https://drupal.org/node/2206347
\Drupal::service('plugin.manager.config_translation.mapper')->clearCachedDefinitions();
}
/**
2014-09-19 09:25:26 +00:00
* Implements hook_themes_uninstalled().
2014-04-22 18:37:12 +00:00
*/
2014-09-19 09:25:26 +00:00
function config_translation_themes_uninstalled() {
2014-04-22 18:37:12 +00:00
// Themes can provide *.config_translation.yml declarations.
// @todo Make ThemeHandler trigger an event instead and make
// ConfigMapperManager plugin manager subscribe to it.
// @see https://drupal.org/node/2206347
\Drupal::service('plugin.manager.config_translation.mapper')->clearCachedDefinitions();
}
2014-01-22 07:32:29 +00:00
/**
2014-02-20 10:04:54 +00:00
* Implements hook_entity_type_alter().
2014-01-22 07:32:29 +00:00
*/
2014-02-20 10:04:54 +00:00
function config_translation_entity_type_alter(array &$entity_types) {
/** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
foreach ($entity_types as $entity_type_id => $entity_type) {
2014-02-12 20:42:43 +00:00
if ($entity_type->isSubclassOf('Drupal\Core\Config\Entity\ConfigEntityInterface')) {
if ($entity_type_id == 'block') {
2014-03-23 22:25:46 +00:00
$class = 'Drupal\config_translation\Controller\ConfigTranslationBlockListBuilder';
2014-02-12 20:42:43 +00:00
}
2014-09-20 02:45:52 +00:00
elseif ($entity_type_id == 'field_config') {
$class = 'Drupal\config_translation\Controller\ConfigTranslationFieldListBuilder';
// Will be filled in dynamically, see \Drupal\field\Entity\FieldConfig::linkTemplates().
2014-02-12 20:42:43 +00:00
$entity_type->setLinkTemplate('drupal:config-translation-overview', 'config_translation.item.overview.');
}
else {
2014-03-23 22:25:46 +00:00
$class = 'Drupal\config_translation\Controller\ConfigTranslationEntityListBuilder';
2014-02-12 20:42:43 +00:00
}
2014-08-22 11:59:25 +00:00
$entity_type->setHandlerClass('config_translation_list', $class);
2014-02-12 20:42:43 +00:00
if ($entity_type->hasLinkTemplate('edit-form')) {
$entity_type->setLinkTemplate('drupal:config-translation-overview', 'config_translation.item.overview.' . $entity_type->getLinkTemplate('edit-form'));
}
2014-01-22 07:32:29 +00:00
}
}
}
Issue #1952394 by vijaycs85, tstoeckler, webflo, Gábor Hojtsy, Schnitzel, falcon03, YesCT, kfritsche, Ryan Weal, dagmita, likin, toddtomlinson, nonsie, Kristen Pol, dawehner, tim.plunkett, penyaskito, EclipseGC, larowlan, robertdbailey, helenkim, David Hernández, EllaTheHarpy, lazysoundsystem, juanolalla, R.Hendel, Kartagis: Add configuration translation user interface module.
2013-11-18 02:41:04 +00:00
/**
* Implements hook_config_translation_info().
*/
function config_translation_config_translation_info(&$info) {
$entity_manager = \Drupal::entityManager();
$route_provider = \Drupal::service('router.route_provider');
// If field UI is not enabled, the base routes of the type
2014-09-20 02:45:52 +00:00
// "field_ui.field_edit_$entity_type" are not defined.
Issue #1952394 by vijaycs85, tstoeckler, webflo, Gábor Hojtsy, Schnitzel, falcon03, YesCT, kfritsche, Ryan Weal, dagmita, likin, toddtomlinson, nonsie, Kristen Pol, dawehner, tim.plunkett, penyaskito, EclipseGC, larowlan, robertdbailey, helenkim, David Hernández, EllaTheHarpy, lazysoundsystem, juanolalla, R.Hendel, Kartagis: Add configuration translation user interface module.
2013-11-18 02:41:04 +00:00
if (\Drupal::moduleHandler()->moduleExists('field_ui')) {
// Add fields entity mappers to all fieldable entity types defined.
2014-02-10 09:24:05 +00:00
foreach ($entity_manager->getDefinitions() as $entity_type_id => $entity_type) {
Issue #1952394 by vijaycs85, tstoeckler, webflo, Gábor Hojtsy, Schnitzel, falcon03, YesCT, kfritsche, Ryan Weal, dagmita, likin, toddtomlinson, nonsie, Kristen Pol, dawehner, tim.plunkett, penyaskito, EclipseGC, larowlan, robertdbailey, helenkim, David Hernández, EllaTheHarpy, lazysoundsystem, juanolalla, R.Hendel, Kartagis: Add configuration translation user interface module.
2013-11-18 02:41:04 +00:00
$base_route = NULL;
try {
2014-09-20 02:45:52 +00:00
$base_route = $route_provider->getRouteByName('field_ui.field_edit_' . $entity_type_id);
Issue #1952394 by vijaycs85, tstoeckler, webflo, Gábor Hojtsy, Schnitzel, falcon03, YesCT, kfritsche, Ryan Weal, dagmita, likin, toddtomlinson, nonsie, Kristen Pol, dawehner, tim.plunkett, penyaskito, EclipseGC, larowlan, robertdbailey, helenkim, David Hernández, EllaTheHarpy, lazysoundsystem, juanolalla, R.Hendel, Kartagis: Add configuration translation user interface module.
2013-11-18 02:41:04 +00:00
}
catch (RouteNotFoundException $e) {
2014-05-01 09:46:02 +00:00
if ($collection = \Drupal::service('router.builder')->getCollectionDuringRebuild()) {
2014-09-20 02:45:52 +00:00
$base_route = $collection->get('field_ui.field_edit_' . $entity_type_id);
2014-05-01 09:46:02 +00:00
}
Issue #1952394 by vijaycs85, tstoeckler, webflo, Gábor Hojtsy, Schnitzel, falcon03, YesCT, kfritsche, Ryan Weal, dagmita, likin, toddtomlinson, nonsie, Kristen Pol, dawehner, tim.plunkett, penyaskito, EclipseGC, larowlan, robertdbailey, helenkim, David Hernández, EllaTheHarpy, lazysoundsystem, juanolalla, R.Hendel, Kartagis: Add configuration translation user interface module.
2013-11-18 02:41:04 +00:00
// Ignore non-existent routes.
}
// Make sure entity type is fieldable and has a base route.
2014-02-10 09:24:05 +00:00
if ($entity_type->isFieldable() && !empty($base_route)) {
$info[$entity_type_id . '_fields'] = array(
2014-09-20 02:45:52 +00:00
'base_route_name' => 'field_ui.field_edit_' . $entity_type_id,
'entity_type' => 'field_config',
Issue #1952394 by vijaycs85, tstoeckler, webflo, Gábor Hojtsy, Schnitzel, falcon03, YesCT, kfritsche, Ryan Weal, dagmita, likin, toddtomlinson, nonsie, Kristen Pol, dawehner, tim.plunkett, penyaskito, EclipseGC, larowlan, robertdbailey, helenkim, David Hernández, EllaTheHarpy, lazysoundsystem, juanolalla, R.Hendel, Kartagis: Add configuration translation user interface module.
2013-11-18 02:41:04 +00:00
'title' => '!label field',
2014-09-20 02:45:52 +00:00
'class' => '\Drupal\config_translation\ConfigFieldMapper',
2014-02-10 09:24:05 +00:00
'base_entity_type' => $entity_type_id,
Issue #1952394 by vijaycs85, tstoeckler, webflo, Gábor Hojtsy, Schnitzel, falcon03, YesCT, kfritsche, Ryan Weal, dagmita, likin, toddtomlinson, nonsie, Kristen Pol, dawehner, tim.plunkett, penyaskito, EclipseGC, larowlan, robertdbailey, helenkim, David Hernández, EllaTheHarpy, lazysoundsystem, juanolalla, R.Hendel, Kartagis: Add configuration translation user interface module.
2013-11-18 02:41:04 +00:00
'weight' => 10,
);
}
}
}
// Discover configuration entities automatically.
2014-02-10 09:24:05 +00:00
foreach ($entity_manager->getDefinitions() as $entity_type_id => $entity_type) {
Issue #1952394 by vijaycs85, tstoeckler, webflo, Gábor Hojtsy, Schnitzel, falcon03, YesCT, kfritsche, Ryan Weal, dagmita, likin, toddtomlinson, nonsie, Kristen Pol, dawehner, tim.plunkett, penyaskito, EclipseGC, larowlan, robertdbailey, helenkim, David Hernández, EllaTheHarpy, lazysoundsystem, juanolalla, R.Hendel, Kartagis: Add configuration translation user interface module.
2013-11-18 02:41:04 +00:00
// Determine base path for entities automatically if provided via the
// configuration entity.
if (
2014-02-10 09:24:05 +00:00
!$entity_type->isSubclassOf('Drupal\Core\Config\Entity\ConfigEntityInterface') ||
!$entity_type->hasLinkTemplate('edit-form')
Issue #1952394 by vijaycs85, tstoeckler, webflo, Gábor Hojtsy, Schnitzel, falcon03, YesCT, kfritsche, Ryan Weal, dagmita, likin, toddtomlinson, nonsie, Kristen Pol, dawehner, tim.plunkett, penyaskito, EclipseGC, larowlan, robertdbailey, helenkim, David Hernández, EllaTheHarpy, lazysoundsystem, juanolalla, R.Hendel, Kartagis: Add configuration translation user interface module.
2013-11-18 02:41:04 +00:00
) {
// Do not record this entity mapper if the entity type does not
// provide a base route. We'll surely not be able to do anything with
// it anyway. Configuration entities with a dynamic base path, such as
2014-09-20 02:45:52 +00:00
// fields, need special treatment. See above.
Issue #1952394 by vijaycs85, tstoeckler, webflo, Gábor Hojtsy, Schnitzel, falcon03, YesCT, kfritsche, Ryan Weal, dagmita, likin, toddtomlinson, nonsie, Kristen Pol, dawehner, tim.plunkett, penyaskito, EclipseGC, larowlan, robertdbailey, helenkim, David Hernández, EllaTheHarpy, lazysoundsystem, juanolalla, R.Hendel, Kartagis: Add configuration translation user interface module.
2013-11-18 02:41:04 +00:00
continue;
}
// Use the entity type as the plugin ID.
2014-02-10 09:24:05 +00:00
$info[$entity_type_id] = array(
Issue #1952394 by vijaycs85, tstoeckler, webflo, Gábor Hojtsy, Schnitzel, falcon03, YesCT, kfritsche, Ryan Weal, dagmita, likin, toddtomlinson, nonsie, Kristen Pol, dawehner, tim.plunkett, penyaskito, EclipseGC, larowlan, robertdbailey, helenkim, David Hernández, EllaTheHarpy, lazysoundsystem, juanolalla, R.Hendel, Kartagis: Add configuration translation user interface module.
2013-11-18 02:41:04 +00:00
'class' => '\Drupal\config_translation\ConfigEntityMapper',
2014-02-10 09:24:05 +00:00
'base_route_name' => $entity_type->getLinkTemplate('edit-form'),
Issue #1952394 by vijaycs85, tstoeckler, webflo, Gábor Hojtsy, Schnitzel, falcon03, YesCT, kfritsche, Ryan Weal, dagmita, likin, toddtomlinson, nonsie, Kristen Pol, dawehner, tim.plunkett, penyaskito, EclipseGC, larowlan, robertdbailey, helenkim, David Hernández, EllaTheHarpy, lazysoundsystem, juanolalla, R.Hendel, Kartagis: Add configuration translation user interface module.
2013-11-18 02:41:04 +00:00
'title' => '!label !entity_type',
'names' => array(),
2014-02-10 09:24:05 +00:00
'entity_type' => $entity_type_id,
Issue #1952394 by vijaycs85, tstoeckler, webflo, Gábor Hojtsy, Schnitzel, falcon03, YesCT, kfritsche, Ryan Weal, dagmita, likin, toddtomlinson, nonsie, Kristen Pol, dawehner, tim.plunkett, penyaskito, EclipseGC, larowlan, robertdbailey, helenkim, David Hernández, EllaTheHarpy, lazysoundsystem, juanolalla, R.Hendel, Kartagis: Add configuration translation user interface module.
2013-11-18 02:41:04 +00:00
'weight' => 10,
);
}
}
/**
2014-04-07 18:12:13 +00:00
* Implements hook_entity_operation().
Issue #1952394 by vijaycs85, tstoeckler, webflo, Gábor Hojtsy, Schnitzel, falcon03, YesCT, kfritsche, Ryan Weal, dagmita, likin, toddtomlinson, nonsie, Kristen Pol, dawehner, tim.plunkett, penyaskito, EclipseGC, larowlan, robertdbailey, helenkim, David Hernández, EllaTheHarpy, lazysoundsystem, juanolalla, R.Hendel, Kartagis: Add configuration translation user interface module.
2013-11-18 02:41:04 +00:00
*/
2014-04-07 18:12:13 +00:00
function config_translation_entity_operation(EntityInterface $entity) {
$operations = array();
2014-05-30 10:17:26 +00:00
$entity_type = $entity->getEntityType();
if ($entity_type->isSubclassOf('Drupal\Core\Config\Entity\ConfigEntityInterface') &&
$entity->hasLinkTemplate('drupal:config-translation-overview') &&
\Drupal::currentUser()->hasPermission('translate configuration')) {
Issue #1952394 by vijaycs85, tstoeckler, webflo, Gábor Hojtsy, Schnitzel, falcon03, YesCT, kfritsche, Ryan Weal, dagmita, likin, toddtomlinson, nonsie, Kristen Pol, dawehner, tim.plunkett, penyaskito, EclipseGC, larowlan, robertdbailey, helenkim, David Hernández, EllaTheHarpy, lazysoundsystem, juanolalla, R.Hendel, Kartagis: Add configuration translation user interface module.
2013-11-18 02:41:04 +00:00
$operations['translate'] = array(
'title' => t('Translate'),
'weight' => 50,
2014-03-28 23:07:00 +00:00
) + $entity->urlInfo('drupal:config-translation-overview')->toArray();
Issue #1952394 by vijaycs85, tstoeckler, webflo, Gábor Hojtsy, Schnitzel, falcon03, YesCT, kfritsche, Ryan Weal, dagmita, likin, toddtomlinson, nonsie, Kristen Pol, dawehner, tim.plunkett, penyaskito, EclipseGC, larowlan, robertdbailey, helenkim, David Hernández, EllaTheHarpy, lazysoundsystem, juanolalla, R.Hendel, Kartagis: Add configuration translation user interface module.
2013-11-18 02:41:04 +00:00
}
2014-04-07 18:12:13 +00:00
return $operations;
Issue #1952394 by vijaycs85, tstoeckler, webflo, Gábor Hojtsy, Schnitzel, falcon03, YesCT, kfritsche, Ryan Weal, dagmita, likin, toddtomlinson, nonsie, Kristen Pol, dawehner, tim.plunkett, penyaskito, EclipseGC, larowlan, robertdbailey, helenkim, David Hernández, EllaTheHarpy, lazysoundsystem, juanolalla, R.Hendel, Kartagis: Add configuration translation user interface module.
2013-11-18 02:41:04 +00:00
}
/**
2014-08-06 09:50:16 +00:00
* Implements hook_config_schema_info_alter().
Issue #1952394 by vijaycs85, tstoeckler, webflo, Gábor Hojtsy, Schnitzel, falcon03, YesCT, kfritsche, Ryan Weal, dagmita, likin, toddtomlinson, nonsie, Kristen Pol, dawehner, tim.plunkett, penyaskito, EclipseGC, larowlan, robertdbailey, helenkim, David Hernández, EllaTheHarpy, lazysoundsystem, juanolalla, R.Hendel, Kartagis: Add configuration translation user interface module.
2013-11-18 02:41:04 +00:00
*/
2014-08-06 09:50:16 +00:00
function config_translation_config_schema_info_alter(&$definitions) {
Issue #1952394 by vijaycs85, tstoeckler, webflo, Gábor Hojtsy, Schnitzel, falcon03, YesCT, kfritsche, Ryan Weal, dagmita, likin, toddtomlinson, nonsie, Kristen Pol, dawehner, tim.plunkett, penyaskito, EclipseGC, larowlan, robertdbailey, helenkim, David Hernández, EllaTheHarpy, lazysoundsystem, juanolalla, R.Hendel, Kartagis: Add configuration translation user interface module.
2013-11-18 02:41:04 +00:00
// Enhance the text and date type definitions with classes to generate proper
// form elements in ConfigTranslationFormBase. Other translatable types will
// appear as a one line textfield.
$definitions['text']['form_element_class'] = '\Drupal\config_translation\FormElement\Textarea';
$definitions['date_format']['form_element_class'] = '\Drupal\config_translation\FormElement\DateFormat';
}