updated core to 7.58 (right after the site was hacked)
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @file
|
||||
* API documentation for this module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Alter source field data before being saved in a translation job.
|
||||
*
|
||||
* @param array $data
|
||||
* Source field data.
|
||||
* @param string $entity_type
|
||||
* The entity type.
|
||||
* @param object $entity
|
||||
* An entity object.
|
||||
* @param string $langcode
|
||||
* The language of retrieved field values.
|
||||
*/
|
||||
function hook_tmgmt_field_source_data_alter(&$data, $entity_type, $entity, $langcode) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract translatable text elements from a field.
|
||||
*
|
||||
* @param $entity_type
|
||||
* The type of $entity.
|
||||
* @param $entity
|
||||
* The entity being extracted.
|
||||
* @param $field
|
||||
* The field structure.
|
||||
* @param $instance
|
||||
* The field instance.
|
||||
* @param $langcode
|
||||
* The language associated with $items.
|
||||
* @param $items
|
||||
* Array of values for this field.
|
||||
*
|
||||
* @return
|
||||
* An array of translatable text elements, keyed by the schema name of the
|
||||
* field.
|
||||
*
|
||||
* @see text_tmgmt_source_translation_structure()
|
||||
*
|
||||
* @ingroup tmgmt_source
|
||||
*/
|
||||
function hook_tmgmt_source_translation_structure($entity_type, $entity, $field, $instance, $langcode, $items) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts data on the entity of the field type owned by the module.
|
||||
*
|
||||
* @param $entity_type
|
||||
* The type of $entity.
|
||||
* @param $entity
|
||||
* The entity being extracted.
|
||||
* @param $field
|
||||
* The field structure.
|
||||
* @param $instance
|
||||
* The field instance.
|
||||
* @param $langcode
|
||||
* The language associated with $items.
|
||||
* @param $data
|
||||
* Translated data array.
|
||||
* @param $use_field_translation
|
||||
* TRUE if field translation is being used.
|
||||
*
|
||||
* @see tmgmt_field_populate_entity()
|
||||
*/
|
||||
function hook_tmgmt_field_type_populate_entity($entity_type, $entity, $field, $instance, $langcode, $data, $use_field_translation) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Alter an entity object before populating its field with translations.
|
||||
*
|
||||
* @param array $data
|
||||
* Source field data.
|
||||
* @param object $entity
|
||||
* An entity object.
|
||||
* @param string $entity_type
|
||||
* The entity type.
|
||||
* @param string $langcode
|
||||
* The language of retrieved field values.
|
||||
*/
|
||||
function hook_tmgmt_field_pre_populate_entity_alter(&$data, $entity, $entity_type, $langcode) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Alter an entity object after populating its field with translations.
|
||||
*
|
||||
* @param object $entity
|
||||
* An entity object.
|
||||
* @param string $entity_type
|
||||
* The entity type.
|
||||
* @param array $data
|
||||
* Source field data.
|
||||
* @param string $langcode
|
||||
* The language of retrieved field values.
|
||||
*/
|
||||
function hook_tmgmt_field_post_populate_entity_alter(&$entity, $entity_type, $data, $langcode) {
|
||||
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
name = Translation Management Field
|
||||
description = Implements some hooks on behalf of the core Field modules that are required in the Translation Management module.
|
||||
package = Translation Management
|
||||
core = 7.x
|
||||
test_dependencies[] = field_collection
|
||||
|
||||
; Information added by Drupal.org packaging script on 2016-09-21
|
||||
version = "7.x-1.0-rc2+1-dev"
|
||||
core = "7.x"
|
||||
project = "tmgmt"
|
||||
datestamp = "1474446494"
|
||||
|
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Main module file for the Translation Management Source Field module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_tmgmt_source_translation_structure().
|
||||
*
|
||||
* This hook is implemented on behalf of the core text module.
|
||||
*/
|
||||
function text_tmgmt_source_translation_structure($entity_type, $entity, $field, $instance, $langcode, $items) {
|
||||
$structure = array();
|
||||
if (!empty($items)) {
|
||||
$structure['#label'] = check_plain($instance['label']);
|
||||
foreach ($items as $delta => $value) {
|
||||
$structure[$delta]['#label'] = t('Delta #@delta', array('@delta' => $delta));
|
||||
$structure[$delta]['value'] = array(
|
||||
'#label' => $structure['#label'],
|
||||
'#text' => $value['value'],
|
||||
'#translate' => TRUE,
|
||||
);
|
||||
// Add format.
|
||||
$structure[$delta]['format'] = array(
|
||||
'#label' => '',
|
||||
'#text' => $value['format'],
|
||||
'#translate' => FALSE,
|
||||
);
|
||||
if ($field['type'] == 'text_with_summary' && !empty($value['summary'])) {
|
||||
$structure[$delta]['summary'] = array(
|
||||
'#label' => t('Summary'),
|
||||
'#text' => $value['summary'],
|
||||
'#translate' => TRUE,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $structure;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for retrieving all translatable field values from an entity.
|
||||
*
|
||||
* @param $entity_type
|
||||
* The entity type.
|
||||
* @param $entity
|
||||
* An entity object.
|
||||
* @param $langcode
|
||||
* The language of retrieved field values.
|
||||
* @param $only_translatable
|
||||
* If TRUE, only the fields which are flagged as translatable are returned.
|
||||
* Defaults to FALSE, which is usually used for node translation, where the
|
||||
* field translatability does not matter.
|
||||
*
|
||||
* @return array
|
||||
* The structured field data for all translatable fields
|
||||
*/
|
||||
function tmgmt_field_get_source_data($entity_type, $entity, $langcode, $only_translatable = FALSE) {
|
||||
try {
|
||||
list(, , $bundle) = entity_extract_ids($entity_type, $entity);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
watchdog_exception('tmgmt field', $e);
|
||||
return array();
|
||||
}
|
||||
|
||||
$fields = array();
|
||||
foreach (field_info_instances($entity_type, $bundle) as $field_name => $instance) {
|
||||
$field = field_info_field($field_name);
|
||||
$items = field_get_items($entity_type, $entity, $field_name, $langcode);
|
||||
if ((!$only_translatable || $field['translatable']) && $items) {
|
||||
if ($data = module_invoke($field['module'], 'tmgmt_source_translation_structure', $entity_type, $entity, $field, $instance, $langcode, $items)) {
|
||||
$fields[$field_name] = $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
drupal_alter('tmgmt_field_source_data', $fields, $entity_type, $entity, $langcode);
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates a field on an object with the provided field values.
|
||||
*
|
||||
* @param $entity_type
|
||||
* The type of $entity.
|
||||
* @param $entity
|
||||
* The object to be populated.
|
||||
* @param $langcode
|
||||
* The field language.
|
||||
* @param $data
|
||||
* An array of values.
|
||||
* @param $use_field_translation
|
||||
* TRUE if field translation is being used.
|
||||
*/
|
||||
function tmgmt_field_populate_entity($entity_type, $entity, $langcode, $data, $use_field_translation = TRUE) {
|
||||
drupal_alter('tmgmt_field_pre_populate_entity', $data, $entity, $entity_type, $langcode);
|
||||
|
||||
foreach (element_children($data) as $field_name) {
|
||||
if ($field = field_info_field($field_name)) {
|
||||
$function = $field['module'] . '_field_type_tmgmt_populate_entity';
|
||||
list(, , $bundle) = entity_extract_ids($entity_type, $entity);
|
||||
$instance = field_info_instance($entity_type, $field_name, $bundle);
|
||||
if (function_exists($function)) {
|
||||
$function($entity_type, $entity, $field, $instance, $langcode, $data, $use_field_translation);
|
||||
}
|
||||
else {
|
||||
$field_langcode = $field['translatable'] ? $langcode : LANGUAGE_NONE;
|
||||
// When not using field translation, make sure we're not storing
|
||||
// multiple languages.
|
||||
if (!$use_field_translation) {
|
||||
$entity->{$field_name} = array($field_langcode => array());
|
||||
}
|
||||
|
||||
foreach (element_children($data[$field_name]) as $delta) {
|
||||
$columns = array();
|
||||
foreach (element_children($data[$field_name][$delta]) as $column) {
|
||||
if (isset($data[$field_name][$delta][$column]['#translation']['#text'])) {
|
||||
$columns[$column] = $data[$field_name][$delta][$column]['#translation']['#text'];
|
||||
}
|
||||
// For elements which are not translatable, keep using the original
|
||||
// value.
|
||||
elseif (isset($data[$field_name][$delta][$column]['#translate']) && $data[$field_name][$delta][$column]['#translate'] == FALSE) {
|
||||
$columns[$column] = $data[$field_name][$delta][$column]['#text'];
|
||||
}
|
||||
}
|
||||
// Make sure the array_merge() gets an array as a first parameter.
|
||||
if (!isset($entity->{$field_name}[$field_langcode][$delta])) {
|
||||
$entity->{$field_name}[$field_langcode][$delta] = array();
|
||||
}
|
||||
$entity->{$field_name}[$field_langcode][$delta] = array_merge($entity->{$field_name}[$field_langcode][$delta], $columns);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
drupal_alter('tmgmt_field_post_populate_entity', $entity, $entity_type, $data, $langcode);
|
||||
}
|
||||
|
Reference in New Issue
Block a user