Issue #1188388 by plach, peximo, YesCT | Gábor Hojtsy, fago, webchick, Bojhan, podarok, cosmicdreams, Berdir, aspilicious, bforchhammer, penyaskito: Added Entity translation UI in core.
2012-11-04 02:38:49 +00:00
<?php
/**
* @file
2013-06-25 19:16:20 +00:00
* Installation functions for Content Translation module.
Issue #1188388 by plach, peximo, YesCT | Gábor Hojtsy, fago, webchick, Bojhan, podarok, cosmicdreams, Berdir, aspilicious, bforchhammer, penyaskito: Added Entity translation UI in core.
2012-11-04 02:38:49 +00:00
*/
2014-04-03 21:38:51 +00:00
use Drupal\Core\Entity\EntityTypeInterface;
2014-06-10 16:52:58 +00:00
use Drupal\Core\Language\LanguageInterface;
Issue #1862202 by plach, Berdir, katbailey, ParisLiakos, alexpott, chx, sun, larowlan, Gábor Hojtsy, cosmicdreams, vijaycs85, YesCT, penyaskito, andypost, Albert Volkman, joelpitett: Objectify the language system.
2014-01-15 16:27:37 +00:00
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
2013-05-25 20:12:45 +00:00
Issue #1188388 by plach, peximo, YesCT | Gábor Hojtsy, fago, webchick, Bojhan, podarok, cosmicdreams, Berdir, aspilicious, bforchhammer, penyaskito: Added Entity translation UI in core.
2012-11-04 02:38:49 +00:00
/**
* Implements hook_schema().
*/
2013-06-25 19:16:20 +00:00
function content_translation_schema() {
$schema['content_translation'] = array(
'description' => 'Table to track content translations',
Issue #1188388 by plach, peximo, YesCT | Gábor Hojtsy, fago, webchick, Bojhan, podarok, cosmicdreams, Berdir, aspilicious, bforchhammer, penyaskito: Added Entity translation UI in core.
2012-11-04 02:38:49 +00:00
'fields' => array(
'entity_type' => array(
'type' => 'varchar',
2014-04-03 21:38:51 +00:00
'length' => EntityTypeInterface::ID_MAX_LENGTH,
Issue #1188388 by plach, peximo, YesCT | Gábor Hojtsy, fago, webchick, Bojhan, podarok, cosmicdreams, Berdir, aspilicious, bforchhammer, penyaskito: Added Entity translation UI in core.
2012-11-04 02:38:49 +00:00
'not null' => TRUE,
'default' => '',
'description' => 'The entity type this translation relates to',
),
'entity_id' => array(
2012-11-06 09:08:25 +00:00
'type' => 'varchar',
'length' => 128,
Issue #1188388 by plach, peximo, YesCT | Gábor Hojtsy, fago, webchick, Bojhan, podarok, cosmicdreams, Berdir, aspilicious, bforchhammer, penyaskito: Added Entity translation UI in core.
2012-11-04 02:38:49 +00:00
'not null' => TRUE,
2012-11-06 09:08:25 +00:00
'default' => '',
Issue #1188388 by plach, peximo, YesCT | Gábor Hojtsy, fago, webchick, Bojhan, podarok, cosmicdreams, Berdir, aspilicious, bforchhammer, penyaskito: Added Entity translation UI in core.
2012-11-04 02:38:49 +00:00
'description' => 'The entity id this translation relates to',
),
'langcode' => array(
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
'description' => 'The target language for this translation.',
),
'source' => array(
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
'description' => 'The source language from which this translation was created.',
),
2013-02-12 12:05:19 +00:00
'outdated' => array(
Issue #1188388 by plach, peximo, YesCT | Gábor Hojtsy, fago, webchick, Bojhan, podarok, cosmicdreams, Berdir, aspilicious, bforchhammer, penyaskito: Added Entity translation UI in core.
2012-11-04 02:38:49 +00:00
'description' => 'A boolean indicating whether this translation needs to be updated.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
2013-02-12 12:05:19 +00:00
'uid' => array(
'description' => 'The author of this translation.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'status' => array(
'description' => 'Boolean indicating whether the translation is visible to non-translators.',
'type' => 'int',
'not null' => TRUE,
'default' => 1,
),
'created' => array(
'description' => 'The Unix timestamp when the translation was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'changed' => array(
'description' => 'The Unix timestamp when the translation was most recently saved.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
Issue #1188388 by plach, peximo, YesCT | Gábor Hojtsy, fago, webchick, Bojhan, podarok, cosmicdreams, Berdir, aspilicious, bforchhammer, penyaskito: Added Entity translation UI in core.
2012-11-04 02:38:49 +00:00
),
'primary key' => array('entity_type', 'entity_id', 'langcode'),
);
return $schema;
}
/**
* Implements hook_install().
*/
2013-06-25 19:16:20 +00:00
function content_translation_install() {
2013-01-07 11:36:47 +00:00
// Assign a fairly low weight to ensure our implementation of
// hook_module_implements_alter() is run among the last ones.
2013-06-25 19:16:20 +00:00
module_set_weight('content_translation', 10);
2014-06-10 16:52:58 +00:00
\Drupal::service('language_negotiator')->saveConfiguration(LanguageInterface::TYPE_CONTENT, array(LanguageNegotiationUrl::METHOD_ID => 0));
2014-04-04 13:49:13 +00:00
$config_names = \Drupal::configFactory()->listAll('field.field.');
foreach ($config_names as $name) {
\Drupal::config($name)
->set('settings.translation_sync', FALSE)
->save();
}
$config_names = \Drupal::configFactory()->listAll('field.instance.');
foreach ($config_names as $name) {
\Drupal::config($name)
->set('settings.translation_sync', FALSE)
->save();
}
Issue #1188388 by plach, peximo, YesCT | Gábor Hojtsy, fago, webchick, Bojhan, podarok, cosmicdreams, Berdir, aspilicious, bforchhammer, penyaskito: Added Entity translation UI in core.
2012-11-04 02:38:49 +00:00
}
/**
* Implements hook_enable().
*/
2013-06-25 19:16:20 +00:00
function content_translation_enable() {
2014-05-04 17:19:57 +00:00
// Translation works when at least two languages are added.
2014-03-31 17:29:01 +00:00
if (count(\Drupal::languageManager()->getLanguages()) < 2) {
2013-01-07 11:36:47 +00:00
$t_args = array('!language_url' => url('admin/config/regional/language'));
2014-05-04 17:19:57 +00:00
$message = t('Be sure to <a href="!language_url">add at least two languages</a> to translate content.', $t_args);
2013-01-07 11:36:47 +00:00
drupal_set_message($message, 'warning');
}
// Point the user to the content translation settings.
$t_args = array('!settings_url' => url('admin/config/regional/content-language'));
$message = t('<a href="!settings_url">Enable translation</a> for <em>content types</em>, <em>taxonomy vocabularies</em>, <em>accounts</em>, or any other element you wish to translate.', $t_args);
Issue #1188388 by plach, peximo, YesCT | Gábor Hojtsy, fago, webchick, Bojhan, podarok, cosmicdreams, Berdir, aspilicious, bforchhammer, penyaskito: Added Entity translation UI in core.
2012-11-04 02:38:49 +00:00
drupal_set_message($message, 'warning');
}
2014-04-04 13:49:13 +00:00
/**
* Implements hook_uninstall().
*/
function content_translation_uninstall() {
$config_names = \Drupal::configFactory()->listAll('field.field.');
foreach ($config_names as $name) {
\Drupal::config($name)
->clear('settings.translation_sync')
->save();
}
$config_names = \Drupal::configFactory()->listAll('field.instance.');
foreach ($config_names as $name) {
\Drupal::config($name)
->clear('settings.translation_sync')
->save();
}
}