You are here

class TMGMTTestSourcePluginController in Translation Management Tool 7

@file Contains the test source plugin.

Hierarchy

Expanded class hierarchy of TMGMTTestSourcePluginController

2 string references to 'TMGMTTestSourcePluginController'
hook_tmgmt_source_plugin_info in ./tmgmt.api.php
Provide information about source plugins.
tmgmt_test_tmgmt_source_plugin_info in tests/tmgmt_test.module
Implements hook_tmgmt_source_plugin_info().

File

tests/tmgmt_test.plugin.source.inc, line 8
Contains the test source plugin.

View source
class TMGMTTestSourcePluginController extends TMGMTDefaultSourcePluginController {

  /**
   * {@inheritdoc}
   */
  public function getUri(TMGMTJobItem $job_item) {

    // Provide logic which allows to test for source which is either accessible
    // or not accessible to anonymous user. This is may then be used to test if
    // the source url is attached to the job comment sent to a translation
    // service.
    $path = 'node';
    if ($job_item->item_type == 'test_not_accessible') {
      $path = 'admin';
    }
    return array(
      'path' => $path,
      'options' => array(),
    );
  }

  /**
   * {@inheritdoc}
   */
  public function getLabel(TMGMTJobItem $job_item) {
    $label = $this->pluginType . ':' . $job_item->item_type . ':' . $job_item->item_id;

    // We need to test if job and job item labels get properly truncated,
    // therefore in case the job item type is "test_with_long_label" we append
    // further text to the existing label.
    if ($job_item->item_type == 'test_with_long_label') {
      $label .= 'Some very long and boring label that definitely exceeds hundred and twenty eight characters which is the maximum character count for the job item label.';
    }
    return $label;
  }

  /**
   * {@inheritdoc}
   */
  public function getData(TMGMTJobItem $job_item) {

    // Allow tests to set custom source data.
    $source = variable_get('tmgmt_test_source_data', array(
      'dummy' => array(
        'deep_nesting' => array(
          '#text' => 'Text for job item with type @type and id @id.',
          '#label' => 'Label for job item with type @type and id @id.',
        ),
      ),
    ));
    $variables = array(
      '@type' => $job_item->item_type,
      '@id' => $job_item->item_id,
    );
    $this
      ->replacePlaceholders($source, $variables);
    return $source;
  }

  /**
   * Will replace placeholders in the #text offsets.
   *
   * @param array $data
   *   Data structures where to replace placeholders.
   * @param $variables
   *   Key value pairs.
   */
  protected function replacePlaceholders(&$data, $variables) {
    foreach (element_children($data) as $key) {
      if (isset($data[$key]['#text'])) {
        $data[$key]['#text'] = format_string($data[$key]['#text'], $variables);
      }
      else {
        $this
          ->replacePlaceholders($data[$key], $variables);
      }
    }
  }

  /**
   * {@inheritdoc}
   */
  public function saveTranslation(TMGMTJobItem $job_item) {

    // Set a variable that can be checked later for a given job item.
    variable_set('tmgmt_test_saved_translation_' . $job_item->item_type . '_' . $job_item->item_id, TRUE);
    $job_item
      ->accepted();
  }

  /**
   * {@inheritdoc}
   */
  public function getExistingLangCodes(TMGMTJobItem $job_item) {
    return array_keys(language_list());
  }

  /**
   * {@inheritdoc}
   */
  public function getSourceLangCode(TMGMTJobItem $job_item) {
    $source_languages = variable_get('tmgmt_test_source_languages', array());
    if (isset($source_languages[$job_item->tjiid])) {
      return $source_languages[$job_item->tjiid];
    }
    return 'en';
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TMGMTDefaultSourcePluginController::getItemTypeLabel public function Returns the label of a source item type. Overrides TMGMTSourcePluginControllerInterface::getItemTypeLabel
TMGMTDefaultSourcePluginController::getItemTypes public function Returns an array of translatable source item types. Overrides TMGMTSourcePluginControllerInterface::getItemTypes
TMGMTDefaultSourcePluginController::getType public function Returns the type of a job item. Overrides TMGMTSourcePluginControllerInterface::getType 4
TMGMTPluginBase::$pluginInfo protected property
TMGMTPluginBase::$pluginType protected property
TMGMTPluginBase::pluginInfo public function Returns the info of the type of the plugin. Overrides TMGMTPluginBaseInterface::pluginInfo
TMGMTPluginBase::pluginType public function Returns the type of the plugin. Overrides TMGMTPluginBaseInterface::pluginType
TMGMTPluginBase::__construct public function Constructor. Overrides TMGMTPluginBaseInterface::__construct
TMGMTTestSourcePluginController::getData public function Returns an array with the data structured for translation. Overrides TMGMTSourcePluginControllerInterface::getData 1
TMGMTTestSourcePluginController::getExistingLangCodes public function Gets existing translation language codes of the job item source. Overrides TMGMTDefaultSourcePluginController::getExistingLangCodes
TMGMTTestSourcePluginController::getLabel public function Return a title for this job item. Overrides TMGMTDefaultSourcePluginController::getLabel
TMGMTTestSourcePluginController::getSourceLangCode public function Gets language code of the job item source. Overrides TMGMTSourcePluginControllerInterface::getSourceLangCode
TMGMTTestSourcePluginController::getUri public function Returns the Uri for this job item. Overrides TMGMTDefaultSourcePluginController::getUri
TMGMTTestSourcePluginController::replacePlaceholders protected function Will replace placeholders in the #text offsets.
TMGMTTestSourcePluginController::saveTranslation public function Saves a translation. Overrides TMGMTSourcePluginControllerInterface::saveTranslation