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;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
/**
* Implements hook_help().
*/
function config_translation_help($path) {
switch ($path) {
case 'admin/help#config_translation':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Configuration Translation module allows configurations to be translated into different languages. Views, your site name, contact module categories, vocabularies, menus, blocks, and so on are all stored within the unified configuration system and can be translated with this module. Content, such as nodes, taxonomy terms, custom blocks, and so on are translatable with the Content Translation module in Drupal core, while the built-in user interface (such as registration forms, content submission and administration interfaces) are translated with the Interface Translation module. Use these three modules effectively together to translate your whole site to different languages.') . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Translating') . '</dt>';
$output .= '<dd>' . t('To translate configuration items, select the translate tab when viewing the configuration, select the language for which you wish to provide translations and then enter the content.') . '</dd>';
$output .= '</dl>';
return $output;
case 'admin/config/regional/config-translation':
$output = '<p>' . t('This page lists all configuration items on your site which have translatable text, like your site name, role names, etc.') . '</p>';
return $output;
}
}
2014-01-29 08:25:00 +00:00
/**
* Implements hook_menu_link_defaults().
*/
function config_translation_menu_link_defaults() {
2014-03-24 10:34:32 +00:00
$links['config_translation.mapper_list'] = array(
2014-01-29 08:25:00 +00:00
'link_title' => 'Configuration translation',
2014-03-24 10:34:32 +00:00
'parent' => 'system.admin_config_regional',
2014-01-29 08:25:00 +00:00
'description' => 'Translate the configuration.',
'route_name' => 'config_translation.mapper_list',
'weight' => 30,
);
return $links;
}
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_permission().
*/
function config_translation_permission() {
return array(
'translate configuration' => array(
'title' => t('Translate user edited configuration'),
'description' => t('Translate any configuration not shipped with modules and themes.'),
),
);
}
/**
* 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-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-02-19 23:29:14 +00:00
elseif ($entity_type_id == 'field_instance_config') {
2014-03-23 22:25:46 +00:00
$class = 'Drupal\config_translation\Controller\ConfigTranslationFieldInstanceListBuilder';
2014-02-19 23:29:14 +00:00
// Will be filled in dynamically, see \Drupal\field\Entity\FieldInstanceConfig::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
}
$entity_type->setControllerClass('config_translation_list', $class);
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
// "field_ui.instance_edit_$entity_type" are not defined.
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-02-10 09:24:05 +00:00
$base_route = $route_provider->getRouteByName('field_ui.instance_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) {
// 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(
'base_route_name' => 'field_ui.instance_edit_' . $entity_type_id,
2014-02-19 23:29:14 +00:00
'entity_type' => 'field_instance_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',
'class' => '\Drupal\config_translation\ConfigFieldInstanceMapper',
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
// field instances, need special treatment. See above.
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-03-26 18:53:12 +00:00
* Implements hook_entity_operation_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-03-26 18:53:12 +00:00
function config_translation_entity_operation_alter(array &$operations, EntityInterface $entity) {
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::currentUser()->hasPermission('translate configuration')) {
$operations['translate'] = array(
'title' => t('Translate'),
'weight' => 50,
2014-02-12 20:42:43 +00:00
) + $entity->urlInfo('drupal:config-translation-overview');
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_type_info_alter().
*/
function config_translation_config_translation_type_info_alter(&$definitions) {
// 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';
}