updated core to 7.58 (right after the site was hacked)
This commit is contained in:
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains TMGMTJobItemUICart.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Represents a job item cart.
|
||||
*
|
||||
* @ingroup tmgmt_ui_cart
|
||||
*/
|
||||
class TMGMTJobItemUICart {
|
||||
|
||||
/**
|
||||
* Singleton instance of cart.
|
||||
*/
|
||||
protected static $instance;
|
||||
|
||||
/**
|
||||
* Array key to store the contents of $this->cart into the $_SESSION variable.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $session_key = 'tmgmt_cart';
|
||||
|
||||
/**
|
||||
* An array to hold and manipulate the contents of the job item cart.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $cart;
|
||||
|
||||
/**
|
||||
* Set up a new TMGMTJobItemUICart instance.
|
||||
*
|
||||
* Will load the cart from the session or initialize a new one if nothing has
|
||||
* been stored yet.
|
||||
*/
|
||||
protected function __construct() {
|
||||
if (!isset($_SESSION[$this->session_key])) {
|
||||
$_SESSION[$this->session_key] = array();
|
||||
}
|
||||
$this->cart = &$_SESSION[$this->session_key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the singleton cart.
|
||||
*
|
||||
* @return TMGMTJobItemUICart
|
||||
* An instance of the cart.
|
||||
*/
|
||||
public static function getInstance() {
|
||||
if (!isset(self::$instance)) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds existing job items into the cart.
|
||||
*
|
||||
* @param TMGMTJobItem[] $items
|
||||
* Job items to be added.
|
||||
*/
|
||||
public function addExistingJobItems(array $items) {
|
||||
foreach ($items as $item) {
|
||||
if (!$this->isSourceItemAdded($item->plugin, $item->item_type, $item->item_id)) {
|
||||
$this->cart[] = $item->tjiid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a job item and adds it into the cart.
|
||||
*
|
||||
* @param string $plugin
|
||||
* The source plugin.
|
||||
* @param string $item_type
|
||||
* The source item type.
|
||||
* @param $item_id
|
||||
* The source item id.
|
||||
*
|
||||
* @return TMGMTJobItem|null
|
||||
* Added job item. If the item exists NULL is returned.
|
||||
*/
|
||||
public function addJobItem($plugin, $item_type, $item_id) {
|
||||
if ($this->isSourceItemAdded($plugin, $item_type, $item_id)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$job_item = tmgmt_job_item_create($plugin, $item_type, $item_id);
|
||||
$job_item->save();
|
||||
$this->cart[] = $job_item->tjiid;
|
||||
return $job_item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the source item has been added into the cart.
|
||||
*
|
||||
* @param string $plugin
|
||||
* The source plugin.
|
||||
* @param string $item_type
|
||||
* The source type.
|
||||
* @param int $source_id
|
||||
* The source id.
|
||||
*
|
||||
* @return bool
|
||||
* If the source item is in the cart.
|
||||
*/
|
||||
public function isSourceItemAdded($plugin, $item_type, $source_id) {
|
||||
foreach ($this->getJobItemsFromCart() as $job_item) {
|
||||
if ($job_item->item_id == $source_id && $job_item->item_type == $item_type && $job_item->plugin == $plugin) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove job items from the cart.
|
||||
*
|
||||
* @param array $job_item_ids
|
||||
* Job items to be removed.
|
||||
*/
|
||||
public function removeJobItems(array $job_item_ids) {
|
||||
$this->cart = array_diff($this->cart, $job_item_ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets job items in the cart.
|
||||
*
|
||||
* @return TMGMTJobItem[] $items
|
||||
* Job items in the cart.
|
||||
*/
|
||||
public function getJobItemsFromCart() {
|
||||
return entity_load('tmgmt_job_item', $this->cart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets count of items in the cart.
|
||||
*
|
||||
* @return int
|
||||
* Number of items in the cart.
|
||||
*/
|
||||
public function count() {
|
||||
return count($this->cart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all contents from the cart.
|
||||
*/
|
||||
public function emptyCart() {
|
||||
$this->cart = array();
|
||||
}
|
||||
}
|
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains the job UI controller.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Entity UI controller for the Job Entity.
|
||||
*/
|
||||
class TMGMTJobUIController extends EntityDefaultUIController {
|
||||
|
||||
/**
|
||||
* Translation job that is a duplicate of an aborted job.
|
||||
*
|
||||
* @var TMGMTJob
|
||||
*/
|
||||
private $jobToResubmit = NULL;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hook_menu() {
|
||||
$id_count = count(explode('/', $this->path));
|
||||
$wildcard = isset($this->entityInfo['admin ui']['menu wildcard']) ? $this->entityInfo['admin ui']['menu wildcard'] : '%entity_object';
|
||||
$items[$this->path . '/' . $wildcard] = array(
|
||||
'title callback' => 'entity_label',
|
||||
'title arguments' => array($this->entityType, $id_count),
|
||||
'page callback' => 'tmgmt_ui_job_view',
|
||||
'page arguments' => array($id_count),
|
||||
'load arguments' => array($this->entityType),
|
||||
'access callback' => 'entity_access',
|
||||
'access arguments' => array('view', $this->entityType, $id_count),
|
||||
'file' => $this->entityInfo['admin ui']['file'],
|
||||
'file path' => $this->entityInfo['admin ui']['file path'],
|
||||
);
|
||||
$items[$this->path . '/' . $wildcard . '/delete'] = array(
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array($this->entityType . '_operation_form', $this->entityType, $id_count, $id_count + 1),
|
||||
'load arguments' => array($this->entityType),
|
||||
'access callback' => 'entity_access',
|
||||
'access arguments' => array('delete', $this->entityType, $id_count),
|
||||
'type' => MENU_CALLBACK,
|
||||
);
|
||||
$items[$this->path . '/' . $wildcard . '/abort'] = array(
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array($this->entityType . '_operation_form', $this->entityType, $id_count, $id_count + 1),
|
||||
'load arguments' => array($this->entityType),
|
||||
'access callback' => 'entity_access',
|
||||
'access arguments' => array('abort', $this->entityType, $id_count),
|
||||
'type' => MENU_CALLBACK,
|
||||
);
|
||||
$items[$this->path . '/' . $wildcard . '/resubmit'] = array(
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array($this->entityType . '_operation_form', $this->entityType, $id_count, $id_count + 1),
|
||||
'load arguments' => array($this->entityType),
|
||||
'access callback' => 'entity_access',
|
||||
'access arguments' => array('resubmit', $this->entityType, $id_count),
|
||||
'type' => MENU_CALLBACK,
|
||||
);
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function operationForm($form, &$form_state, $entity, $op) {
|
||||
switch ($op) {
|
||||
case 'delete':
|
||||
$confirm_question = t('Are you sure you want to delete the translation job %label?', array('%label' => $entity->label()));
|
||||
return confirm_form($form, $confirm_question, $this->path);
|
||||
case 'abort':
|
||||
return confirm_form($form, t('Abort this job?'), 'admin/tmgmt/jobs/' . $entity->tjid,
|
||||
t('This will send a request to the translator to abort the job. After the action the job translation process will be aborted and only remaining action will be resubmitting it.'));
|
||||
case 'resubmit':
|
||||
return confirm_form($form, t('Resubmit as a new job?'), 'admin/tmgmt/jobs/' . $entity->tjid,
|
||||
t('This creates a new job with the same items which can then be submitted again. In case the sources meanwhile changed, the new job will reflect the update.'));
|
||||
}
|
||||
drupal_not_found();
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function applyOperation($op, $entity) {
|
||||
switch ($op) {
|
||||
case 'delete':
|
||||
$entity->delete();
|
||||
return t('Deleted the translation job %label.', array('%label' => $entity->label()));
|
||||
case 'abort':
|
||||
if (!$entity->abortTranslation()) {
|
||||
// This is the case when a translator does not support the abort operation.
|
||||
// It would make more sense to not display the button for the action,
|
||||
// however we do not know if the translator is able to abort a job until
|
||||
// we trigger the action.
|
||||
foreach ($entity->getMessagesSince() as $message) {
|
||||
if ($message->type == 'debug') {
|
||||
continue;
|
||||
}
|
||||
if ($text = $message->getMessage()) {
|
||||
// We want to persist also the type therefore we will set the
|
||||
// messages directly and not return them.
|
||||
drupal_set_message(filter_xss($text), $message->type);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'resubmit':
|
||||
$this->jobToResubmit = $entity->cloneAsUnprocessed();
|
||||
$this->jobToResubmit->uid = $GLOBALS['user']->uid;
|
||||
$this->jobToResubmit->save();
|
||||
/** @var TMGMTJobItem $item */
|
||||
foreach ($entity->getItems() as $item) {
|
||||
$item_to_resubmit = $item->cloneAsActive();
|
||||
$this->jobToResubmit->addExistingItem($item_to_resubmit);
|
||||
}
|
||||
|
||||
$entity->addMessage('Job has been duplicated as a new job <a href="@url">#@id</a>.',
|
||||
array('@url' => url('admin/tmgmt/jobs/' . $this->jobToResubmit->tjid), '@id' => $this->jobToResubmit->tjid));
|
||||
$this->jobToResubmit->addMessage('This job is a duplicate of the previously aborted job <a href="@url">#@id</a>',
|
||||
array('@url' => url('admin/tmgmt/jobs/' . $entity->tjid), '@id' => $entity->tjid));
|
||||
|
||||
return t('The aborted job has been duplicated. You can resubmit it now.');
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Operation form submit callback.
|
||||
*/
|
||||
public function operationFormSubmit($form, &$form_state) {
|
||||
parent::operationFormSubmit($form, $form_state);
|
||||
if ($form_state['op'] == 'resubmit') {
|
||||
$form_state['redirect'] = $this->path . '/' . $this->jobToResubmit->tjid;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains the job item UI controller.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Entity UI controller for the Job Entity.
|
||||
*/
|
||||
class TMGMTJobItemUIController extends EntityDefaultUIController {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hook_menu() {
|
||||
$id_count = count(explode('/', $this->path));
|
||||
$wildcard = isset($this->entityInfo['admin ui']['menu wildcard']) ? $this->entityInfo['admin ui']['menu wildcard'] : '%entity_object';
|
||||
$items[$this->path . '/' . $wildcard] = array(
|
||||
'title callback' => 'entity_label',
|
||||
'title arguments' => array($this->entityType, $id_count),
|
||||
'page callback' => 'tmgmt_ui_job_item_view',
|
||||
'page arguments' => array($id_count),
|
||||
'load arguments' => array($this->entityType),
|
||||
'access callback' => 'entity_access',
|
||||
'access arguments' => array('view', 'tmgmt_job_item', $id_count),
|
||||
'file' => $this->entityInfo['admin ui']['file'],
|
||||
'file path' => $this->entityInfo['admin ui']['file path'],
|
||||
);
|
||||
$items[$this->path . '/' . $wildcard . '/view'] = array(
|
||||
'title' => 'View',
|
||||
'load arguments' => array($this->entityType),
|
||||
'type' => MENU_DEFAULT_LOCAL_TASK,
|
||||
'weight' => -10,
|
||||
);
|
||||
$items[$this->path . '/' . $wildcard . '/reject/%'] = array(
|
||||
'title' => 'Reject',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('tmgmt_ui_translation_review_form_reject_confirm', $id_count, $id_count + 2),
|
||||
'load arguments' => array($this->entityType),
|
||||
'access callback' => 'entity_access',
|
||||
'access arguments' => array('accept', $this->entityType, $id_count),
|
||||
'type' => MENU_VISIBLE_IN_BREADCRUMB,
|
||||
'file' => $this->entityInfo['admin ui']['file'],
|
||||
'file path' => $this->entityInfo['admin ui']['file path'],
|
||||
);
|
||||
$items[$this->path . '/' . $wildcard . '/delete'] = array(
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array($this->entityType . '_operation_form', $this->entityType, $id_count, $id_count + 1),
|
||||
'load arguments' => array($this->entityType),
|
||||
'access callback' => 'entity_access',
|
||||
'access arguments' => array('delete', $this->entityType, $id_count),
|
||||
'type' => MENU_CALLBACK,
|
||||
);
|
||||
$items[$this->path . '/' . $wildcard . '/accept'] = array(
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array($this->entityType . '_operation_form', $this->entityType, $id_count, $id_count + 1),
|
||||
'load arguments' => array($this->entityType),
|
||||
'access callback' => 'entity_access',
|
||||
'access arguments' => array('accept', $this->entityType, $id_count),
|
||||
'type' => MENU_CALLBACK,
|
||||
);
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function operationForm($form, &$form_state, $entity, $op) {
|
||||
$controller = $entity->getSourceController();
|
||||
$info = $controller->pluginInfo();
|
||||
switch ($op) {
|
||||
case 'delete':
|
||||
$confirm_question = t('Are you sure you want to delete the %plugin translation job item for %label?', array('%plugin' => $info['label'], '%label' => $entity->label()));
|
||||
return confirm_form($form, $confirm_question, $this->path);
|
||||
case 'accept':
|
||||
$confirm_question = t('Are you sure you want to accept the %plugin translation job item for %label?', array('%plugin' => $info['label'], '%label' => $entity->label()));
|
||||
return confirm_form($form, $confirm_question, $this->path);
|
||||
}
|
||||
drupal_not_found();
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function applyOperation($op, $entity) {
|
||||
switch ($op) {
|
||||
case 'delete':
|
||||
$entity->delete();
|
||||
return t('The translation job item %label has been deleted.', array('%label' => $entity->label()));
|
||||
case 'accept':
|
||||
$entity->accepted('The translation job item has been accepted by !user.', array('!user' => theme('username', array('account' => $GLOBALS['user']))));
|
||||
return t('The translation job item %label has been accepted.', array('%label' => $entity->label()));
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains the translator UI controller.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Entity UI controller for the Translator Entity.
|
||||
*/
|
||||
class TMGMTTranslatorUIController extends EntityDefaultUIController {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hook_menu() {
|
||||
$items = parent::hook_menu();
|
||||
$items[$this->path . '/add']['title'] = 'Add Translator';
|
||||
unset($items[$this->path . '/add']['title callback']);
|
||||
unset($items[$this->path . '/add']['title arguments']);
|
||||
if (!empty($this->entityInfo['exportable'])) {
|
||||
$items[$this->path . '/import']['title'] = 'Import Translator';
|
||||
unset($items[$this->path . '/import']['title callback']);
|
||||
unset($items[$this->path . '/import']['title arguments']);
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function overviewForm($form, &$form_state) {
|
||||
$form['translators']['#tree'] = TRUE;
|
||||
$form['translators']['#theme'] = 'tmgmt_ui_translator_overview_form';
|
||||
$form['translators']['#entity_info'] = $this->entityInfo;
|
||||
// Load all translator entities.
|
||||
$translators = tmgmt_translator_load_multiple(FALSE);
|
||||
foreach ($translators as $key => $translator) {
|
||||
$form['translators'][$key] = $this->overviewFormRow(array(), $form_state, $translator, $key);
|
||||
$form['translators'][$key]['#translator'] = $translator;
|
||||
}
|
||||
$form['actions']['#type'] = 'actions';
|
||||
$form['actions']['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Save'),
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function overviewFormSubmit($form, &$form_state) {
|
||||
// Update image effect weights.
|
||||
if (!empty($form_state['values']['translators'])) {
|
||||
$translators = tmgmt_translator_load_multiple(array_keys($form_state['values']['translators']));
|
||||
foreach ($form_state['values']['translators'] as $key => $item) {
|
||||
if (isset($translators[$key])) {
|
||||
$translators[$key]->weight = $item['weight'];
|
||||
entity_save($this->entityType, $translators[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method for building a row in the overview form.
|
||||
*/
|
||||
protected function overviewFormRow($form, &$form_state, $entity, $id) {
|
||||
$form['#weight'] = isset($form_state['input']['translators']) ? $form_state['input']['translators'][$id]['weight'] : NULL;
|
||||
$form['label'] = array(
|
||||
'#theme' => 'tmgmt_ui_translator_overview_item',
|
||||
'#attached' => array('css' => array(drupal_get_path('module', 'tmgmt_ui') . '/css/tmgmt_ui.admin.css')),
|
||||
'#label' => $entity->label(),
|
||||
'#name' => !empty($this->entityInfo['exportable']) ? entity_id($this->entityType, $entity) : FALSE,
|
||||
'#url' => FALSE,
|
||||
'#description' => $entity->description,
|
||||
'#entity_type' => $this->entityType,
|
||||
);
|
||||
// Add a row for the exportable status.
|
||||
if (!empty($this->entityInfo['exportable'])) {
|
||||
$form['status'] = array(
|
||||
'#theme' => 'entity_status',
|
||||
'#status' => $entity->{$this->statusKey},
|
||||
);
|
||||
}
|
||||
$wrapper = entity_metadata_wrapper($this->entityType, $entity);
|
||||
// Add a column to show the translator plugin via the metadata wrapper.
|
||||
$form['plugin'] = array(
|
||||
'#markup' => $wrapper->plugin->label(),
|
||||
'#status' => $entity->{$this->statusKey},
|
||||
);
|
||||
$controller = $entity->getController();
|
||||
$form['configured'] = array(
|
||||
'#markup' => $controller->isAvailable($entity) ? t('Yes') : t('No'),
|
||||
);
|
||||
$form['weight'] = array(
|
||||
'#type' => 'weight',
|
||||
'#delta' => 30,
|
||||
'#default_value' => $entity->weight,
|
||||
);
|
||||
// Add operations depending on the status.
|
||||
if (entity_has_status($this->entityType, $entity, ENTITY_FIXED)) {
|
||||
$form['operations']['clone'] = array(
|
||||
'#type' => 'link',
|
||||
'#title' => t('clone'),
|
||||
'#href' => $this->path . '/manage/' . $id . '/clone',
|
||||
);
|
||||
}
|
||||
else {
|
||||
$form['operations']['edit'] = array(
|
||||
'#type' => 'link',
|
||||
'#title' => t('edit'),
|
||||
'#href' => $this->path . '/manage/' . $id,
|
||||
);
|
||||
if (!empty($this->entityInfo['exportable'])) {
|
||||
$form['operations']['clone'] = array(
|
||||
'#type' => 'link',
|
||||
'#title' => t('clone'),
|
||||
'#href' => $this->path . '/manage/' . $id . '/clone',
|
||||
);
|
||||
}
|
||||
if (empty($this->entityInfo['exportable']) || !entity_has_status($this->entityType, $entity, ENTITY_IN_CODE)) {
|
||||
$form['operations']['delete'] = array(
|
||||
'#type' => 'link',
|
||||
'#title' => t('delete'),
|
||||
'#href' => $this->path . '/manage/' . $id . '/delete',
|
||||
'#options' => array('query' => drupal_get_destination()),
|
||||
);
|
||||
}
|
||||
elseif (entity_has_status($this->entityType, $entity, ENTITY_OVERRIDDEN)) {
|
||||
$form['operations']['revert'] = array(
|
||||
'#type' => 'link',
|
||||
'#title' => t('revert'),
|
||||
'#href' => $this->path . '/manage/' . $id . '/revert',
|
||||
'#options' => array('query' => drupal_get_destination()),
|
||||
);
|
||||
}
|
||||
else {
|
||||
$row[] = '';
|
||||
}
|
||||
}
|
||||
if (!empty($this->entityInfo['exportable'])) {
|
||||
$form['operations']['export'] = array(
|
||||
'#type' => 'link',
|
||||
'#title' => t('export'),
|
||||
'#href' => $this->path . '/manage/' . $id . '/export',
|
||||
);
|
||||
}
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function applyOperation($op, $entity) {
|
||||
if ($op == 'delete' && tmgmt_translator_busy($entity->name)) {
|
||||
drupal_set_message(t("The translator %translator could not be deleted because it is currently being used by at least one active translation job.", array('%translator' => $entity->label())), 'error');
|
||||
return FALSE;
|
||||
}
|
||||
return parent::applyOperation($op, $entity);
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,315 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Theme file stub for tmgmt.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Generic theme function for use with Render API.
|
||||
*
|
||||
* Renders the #title and #attributes properties if they are present.
|
||||
*/
|
||||
function theme_tmgmt_ui_element($variables) {
|
||||
$element = $variables['element'];
|
||||
|
||||
// Use the #title attribute.
|
||||
$title = '';
|
||||
if (!empty($element['#title'])) {
|
||||
$title = '<h3>' . check_plain($element['#title']) . '</h3>';
|
||||
}
|
||||
|
||||
// Use #attributes to customize a wrapper <div>.
|
||||
$attributes = '';
|
||||
if (!empty($element['#attributes'])) {
|
||||
$attributes = drupal_attributes($element['#attributes']);
|
||||
}
|
||||
|
||||
// Render any child items.
|
||||
if (!$element['#children']) {
|
||||
$element['#children'] = drupal_render_children($element);
|
||||
}
|
||||
|
||||
// Build simple output.
|
||||
$output = "<div{$attributes}>{$title}{$element['#children']}</div>";
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets translation language status.
|
||||
*
|
||||
* @param array $variables
|
||||
* - 'translation_status': A flag that determines the status. Possible values:
|
||||
* original, missing, outofdate.
|
||||
* - 'job_item': Current job item entity associated with translation.
|
||||
*
|
||||
* @return string
|
||||
* Icon or a link icon that explains the translation status and possibly
|
||||
* links to an active translation job.
|
||||
*/
|
||||
function theme_tmgmt_ui_translation_language_status_single($variables) {
|
||||
switch ($variables['translation_status']) {
|
||||
case 'original':
|
||||
$label = t('Source language');
|
||||
$icon_color = 'tmgmt-ui-icon-white';
|
||||
break;
|
||||
|
||||
case 'missing':
|
||||
$label = t('Not translated');
|
||||
$icon_color = 'tmgmt-ui-icon-grey';
|
||||
break;
|
||||
|
||||
case 'outofdate':
|
||||
$label = t('Translation Outdated');
|
||||
$icon_color = 'tmgmt-ui-icon-orange';
|
||||
break;
|
||||
|
||||
default:
|
||||
$label = t('Translation up to date');
|
||||
$icon_color = 'tmgmt-ui-icon-green';
|
||||
}
|
||||
|
||||
// Add classes to show the correct html icon.
|
||||
$classes = array();
|
||||
$classes[] = 'tmgmt-ui-icon';
|
||||
// Icon size 10px square.
|
||||
$classes[] = 'tmgmt-ui-icon-10';
|
||||
$classes[] = $icon_color;
|
||||
|
||||
// Add necessary css file.
|
||||
drupal_add_css(drupal_get_path('module', 'tmgmt_ui') . '/css/tmgmt_ui.admin.css');
|
||||
|
||||
$status = sprintf('<div class="%s" title="%s"><span></span></div>', implode(' ', $classes), $label);
|
||||
|
||||
// If we have an active job item, wrap it in a link.
|
||||
if (!empty($variables['job_item'])) {
|
||||
$job_item_wrapper = entity_metadata_wrapper('tmgmt_job_item', $variables['job_item']);
|
||||
$label = t('Active job item: @state', array('@state' => $job_item_wrapper->state->label()));
|
||||
$uri = $variables['job_item']->uri();
|
||||
/** @var TMGMTJob $job */
|
||||
$job = $variables['job_item']->getJob();
|
||||
$job_wrapper = entity_metadata_wrapper('tmgmt_job', $job);
|
||||
|
||||
switch ($variables['job_item']->state) {
|
||||
case TMGMT_JOB_ITEM_STATE_ACTIVE:
|
||||
if ($job->isUnprocessed()) {
|
||||
$uri = $job->uri();
|
||||
$label = t('Active job item: @state', array('@state' => $job_wrapper->state->label()));
|
||||
}
|
||||
$icon_color = 'tmgmt-ui-icon-blue';
|
||||
break;
|
||||
|
||||
case TMGMT_JOB_ITEM_STATE_REVIEW:
|
||||
$icon_color = 'tmgmt-ui-icon-yellow';
|
||||
break;
|
||||
}
|
||||
|
||||
// Add classes to show the correct html icon.
|
||||
$classes = array();
|
||||
$classes[] = 'tmgmt-ui-icon';
|
||||
// Icon size 10px square.
|
||||
$classes[] = 'tmgmt-ui-icon-10';
|
||||
$classes[] = $icon_color;
|
||||
|
||||
$job_status = sprintf('<div class="%s" title="%s"><span></span></div>', implode(' ', $classes), $label);
|
||||
|
||||
$status .= l($job_status, $uri['path'], array(
|
||||
'query' => array('destination' => current_path()),
|
||||
'html' => TRUE,
|
||||
'attributes' => array('title' => $label),
|
||||
));
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a data item status as an HTML/CSS icon.
|
||||
*/
|
||||
function theme_tmgmt_ui_translator_review_form_element_status($variables) {
|
||||
$classes = array();
|
||||
$classes[] = 'tmgmt-ui-icon';
|
||||
$classes[] = 'tmgmt-ui-icon-32'; // Icon size 32px square.
|
||||
switch ($variables['status']['#value']) {
|
||||
case TMGMT_DATA_ITEM_STATE_ACCEPTED:
|
||||
$title = t('Accepted');
|
||||
// Unicode character U+2611 BALLOT BOX WITH CHECK.
|
||||
$icon = '☑';
|
||||
$classes[] = 'tmgmt-ui-icon-darkgreen';
|
||||
$classes[] = 'tmgmt-ui-state-accepted';
|
||||
break;
|
||||
case TMGMT_DATA_ITEM_STATE_REVIEWED:
|
||||
$title = t('Reviewed');
|
||||
// Unicode character U+2611 BALLOT BOX WITH CHECK.
|
||||
$icon = '☑';
|
||||
$classes[] = 'tmgmt-ui-icon-green';
|
||||
$classes[] = 'tmgmt-ui-state-reviewed';
|
||||
break;
|
||||
case TMGMT_DATA_ITEM_STATE_TRANSLATED:
|
||||
$title = t('Translated');
|
||||
// Unicode character U+2610 BALLOT BOX.
|
||||
$icon = '☐';
|
||||
$classes[] = 'tmgmt-ui-icon-yellow';
|
||||
$classes[] = 'tmgmt-ui-state-translated';
|
||||
break;
|
||||
case TMGMT_DATA_ITEM_STATE_PENDING:
|
||||
default:
|
||||
$title = t('Pending');
|
||||
// Just an empty icon without a sign.
|
||||
$icon = '';
|
||||
$classes[] = 'tmgmt-ui-icon-grey';
|
||||
$classes[] = 'tmgmt-ui-state-pending';
|
||||
break;
|
||||
}
|
||||
return sprintf('<div class="%s" title="%s"><span>%s</span></div>', implode(' ', $classes), $title, $icon);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render one single data item as a table row.
|
||||
*/
|
||||
function theme_tmgmt_ui_translator_review_form_element($variables) {
|
||||
$element = $variables['element'];
|
||||
// Label of all element groups.
|
||||
if (!isset($element['#top_label'])) {
|
||||
$element['#top_label'] = array_shift($element['#parent_label']);
|
||||
}
|
||||
// Label of the current data item.
|
||||
if (!isset($element['#leave_label'])) {
|
||||
$element['#leave_label'] = array_pop($element['#parent_label']);
|
||||
}
|
||||
// Do not repeat labels inside the same hierarchy.
|
||||
if ($element['#top_label'] == $element['#leave_label']) {
|
||||
$element['#leave_label'] = '';
|
||||
}
|
||||
$result = '<tr' . drupal_attributes(array('class' => $element['#zebra'])) . '>';
|
||||
$row = array();
|
||||
$leaf_label = '<label>' . $element['#leave_label'] . '</label>';
|
||||
$leaf_label = '<div class="form-item form-type-label">' . $leaf_label . '</div>';
|
||||
$row[] = array(
|
||||
'data' => $leaf_label . '<div class="tmgmt-ui-state">' . drupal_render($element['status']) . '</div>',
|
||||
'class' => 'tmgmt-ui-data-item-label',
|
||||
);
|
||||
$row[] = array(
|
||||
'data' => drupal_render($element['source']),
|
||||
'class' => 'tmgmt-ui-data-item-source',
|
||||
);
|
||||
$row[] = array(
|
||||
'data' => drupal_render($element['translation']),
|
||||
'class' => 'tmgmt-ui-data-item-translation',
|
||||
);
|
||||
$row[] = array(
|
||||
'data' => drupal_render($element['actions']),
|
||||
'class' => 'tmgmt-ui-data-item-actions',
|
||||
);
|
||||
foreach ($row as $cell) {
|
||||
$result .= _theme_table_cell($cell);
|
||||
}
|
||||
$result .= '</tr>';
|
||||
|
||||
if (!empty($element['below'])) {
|
||||
$result .= '<tr' . drupal_attributes(array('class' => $element['#zebra'])) . '>';
|
||||
$result .= _theme_table_cell(array(
|
||||
'data' => drupal_render($element['below']),
|
||||
'colspan' => '4',
|
||||
));
|
||||
$result .= '</tr>';
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a table containing a group of data items belonging to the same field.
|
||||
*/
|
||||
function theme_tmgmt_ui_translator_review_form($variables) {
|
||||
$element = $variables['element'];
|
||||
$result = '';
|
||||
$labels = '';
|
||||
$parent_label = '';
|
||||
$element_groups = array();
|
||||
$element_group = '';
|
||||
foreach (element_children($element) as $key) {
|
||||
// Label of all element groups.
|
||||
$parent_label = array_shift($element[$key]['#parent_label']);
|
||||
$element[$key]['#top_label'] = $parent_label;
|
||||
$element[$key]['#leave_label'] = array_pop($element[$key]['#parent_label']);
|
||||
// Start a new element group.
|
||||
if ($labels != $element[$key]['#parent_label']) {
|
||||
$labels = $element[$key]['#parent_label'];
|
||||
if (!empty($labels)) {
|
||||
// Append to previous group to the group collection.
|
||||
if (!empty($element_group)) {
|
||||
$element_groups[] = '<tbody>' . $element_group . '</tbody>';
|
||||
}
|
||||
// Header row for the current element group.
|
||||
$cell = array(
|
||||
// @todo: Deal with right to left languages.
|
||||
'data' => check_plain(implode(t(' > '), $labels)),
|
||||
'colspan' => 4,
|
||||
);
|
||||
$element_group = '<tr>' . _theme_table_cell($cell, TRUE) . '</tr>';
|
||||
}
|
||||
}
|
||||
$element_group .= drupal_render($element[$key]);
|
||||
}
|
||||
|
||||
// Append the last group to the group collection.
|
||||
$element_groups[] = '<tbody>' . $element_group . '</tbody>';
|
||||
|
||||
// Display the label of all element groups inside a table header.
|
||||
if (!empty($parent_label)) {
|
||||
$cell = array(
|
||||
'data' => $parent_label,
|
||||
'colspan' => 5,
|
||||
);
|
||||
$result = '<thead><tr>' . _theme_table_cell($cell, TRUE) . '</tr></thead>' . implode('', $element_groups);
|
||||
}
|
||||
$table = '<table class="tmgmt-ui-review"><colgroup width="100" /><colgroup width="*" span="2" /><colgroup width="100" />' . $result . '</table>';
|
||||
return '<div id="' . $element['#ajaxid'] . '">' . $table . '</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a description to the translator entity on the entity overview form.
|
||||
*
|
||||
* @see theme_entity_ui_overview_item()
|
||||
*/
|
||||
function theme_tmgmt_ui_translator_overview_item($variables) {
|
||||
$output = theme('entity_ui_overview_item', $variables);
|
||||
if (!empty($variables['description'])) {
|
||||
$output = '<div class="tmgmt-ui-translator-label-wrapper">' . $output . '<div class="description">' . $variables['description'] . '</div></div>';
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Theme callback for adding the tabledrag to the translator entity overview
|
||||
* form.
|
||||
*/
|
||||
function theme_tmgmt_ui_translator_overview_form($variables) {
|
||||
$form = $variables['form'];
|
||||
$colspan = !empty($form['#entity_info']['exportable']) ? 4 : 3;
|
||||
$rows = array();
|
||||
$header = array(
|
||||
t('Label'),
|
||||
t('Plugin'),
|
||||
t('Configured'),
|
||||
t('Status'),
|
||||
array('data' => t('Operations'), 'colspan' => $colspan),
|
||||
t('Weight'),
|
||||
);
|
||||
foreach (element_children($form) as $key) {
|
||||
$row = array();
|
||||
$form[$key]['weight']['#attributes']['class'] = array('tmgmt-ui-translator-weight');
|
||||
$row[] = drupal_render($form[$key]['label']);
|
||||
$row[] = drupal_render($form[$key]['plugin']);
|
||||
$row[] = drupal_render($form[$key]['configured']);
|
||||
$row[] = drupal_render($form[$key]['status']);
|
||||
$operations = element_children($form[$key]['operations']);
|
||||
foreach ($operations as $op) {
|
||||
$row[] = array('data' => $form[$key]['operations'][$op]);
|
||||
}
|
||||
$row[] = drupal_render($form[$key]['weight']);
|
||||
$rows[] = array('data' => $row, 'class' => array('draggable'));
|
||||
}
|
||||
drupal_add_tabledrag('tmgmt-ui-translator-overview', 'order', 'sibling', 'tmgmt-ui-translator-weight');
|
||||
return theme('table', array('header' => $header, 'rows' => $rows, 'empty' => t('None.'), 'attributes' => array('id' => 'tmgmt-ui-translator-overview')));
|
||||
}
|
Reference in New Issue
Block a user