initial commit of starter install drupal 7
This commit is contained in:
+47
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Comment translation handler for the entity translation module.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Comment translation handler.
|
||||
*/
|
||||
class EntityTranslationCommentHandler extends EntityTranslationDefaultHandler {
|
||||
|
||||
public function __construct($entity_type, $entity_info, $entity) {
|
||||
parent::__construct('comment', $entity_info, $entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see EntityTranslationDefaultHandler::entityForm()
|
||||
*/
|
||||
public function entityForm(&$form, &$form_state) {
|
||||
parent::entityForm($form, $form_state);
|
||||
// Adjust the translation fieldset weight to move it below the admin one.
|
||||
$form['translation']['#weight'] = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see EntityTranslationDefaultHandler::entityFormLanguageWidgetSubmit()
|
||||
*/
|
||||
public function entityFormLanguageWidgetSubmit($form, &$form_state) {
|
||||
$this->updateFormLanguage($form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see EntityTranslationDefaultHandler::entityFormTitle()
|
||||
*/
|
||||
protected function entityFormTitle() {
|
||||
return t('Edit comment @subject', array('@subject' => $this->getLabel()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see EntityTranslationDefaultHandler::getStatus()
|
||||
*/
|
||||
protected function getStatus() {
|
||||
return (boolean) $this->entity->status;
|
||||
}
|
||||
}
|
||||
+1699
File diff suppressed because it is too large
Load Diff
+118
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Node translation handler for the entity translation module.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Node translation handler.
|
||||
*
|
||||
* Overrides default behaviours for Node properties.
|
||||
*/
|
||||
class EntityTranslationNodeHandler extends EntityTranslationDefaultHandler {
|
||||
|
||||
public function __construct($entity_type, $entity_info, $entity) {
|
||||
parent::__construct('node', $entity_info, $entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see EntityTranslationDefaultHandler::isRevision()
|
||||
*/
|
||||
public function isRevision() {
|
||||
return !empty($this->entity->revision);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see EntityTranslationDefaultHandler::getAccess()
|
||||
*/
|
||||
public function getAccess($op) {
|
||||
return node_access($op, $this->entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see EntityTranslationDefaultHandler::getTranslationAccess()
|
||||
*/
|
||||
public function getTranslationAccess($langcode) {
|
||||
return user_access('bypass node access') || parent::getTranslationAccess($langcode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the translation update status fieldset into a vartical tab.
|
||||
*/
|
||||
public function entityForm(&$form, &$form_state) {
|
||||
parent::entityForm($form, $form_state);
|
||||
|
||||
// Move the translation fieldset to a vertical tab.
|
||||
if (isset($form['translation'])) {
|
||||
$form['translation'] += array(
|
||||
'#group' => 'additional_settings',
|
||||
'#weight' => 100,
|
||||
'#attached' => array(
|
||||
'js' => array(drupal_get_path('module', 'entity_translation') . '/entity_translation.node-form.js'),
|
||||
),
|
||||
);
|
||||
|
||||
if (!$this->isTranslationForm()) {
|
||||
$form['translation']['name']['#access'] = FALSE;
|
||||
$form['translation']['created']['#access'] = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// Path aliases natively support multilingual values.
|
||||
if (isset($form['path'])) {
|
||||
$form['path']['#multilingual'] = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see EntityTranslationDefaultHandler::menuForm()
|
||||
*/
|
||||
protected function menuForm(&$form, &$form_state) {
|
||||
entity_translation_i18n_menu_form($form, $form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see EntityTranslationDefaultHandler::entityFormLanguageWidgetSubmit()
|
||||
*/
|
||||
function entityFormLanguageWidgetSubmit($form, &$form_state) {
|
||||
$this->updateFormLanguage($form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see EntityTranslationDefaultHandler::entityFormSubmit()
|
||||
*/
|
||||
public function entityFormSubmit($form, &$form_state) {
|
||||
if (!isset($form_state['values']['translation'])) {
|
||||
// Always publish the original values when we have no translations.
|
||||
$form_state['values']['translation'] = array('status' => TRUE);
|
||||
}
|
||||
$values = &$form_state['values']['translation'];
|
||||
|
||||
if (!$this->isTranslationForm()) {
|
||||
// Inherit entity authoring information for the original values.
|
||||
$values['name'] = $form_state['values']['name'];
|
||||
if (!empty($form_state['values']['date'])) {
|
||||
$values['created'] = $form_state['values']['date'];
|
||||
}
|
||||
}
|
||||
|
||||
parent::entityFormSubmit($form, $form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see EntityTranslationDefaultHandler::entityFormTitle()
|
||||
*/
|
||||
protected function entityFormTitle() {
|
||||
$type_name = node_type_get_name($this->entity);
|
||||
return t('<em>Edit @type</em> @title', array('@type' => $type_name, '@title' => $this->getLabel()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see EntityTranslationDefaultHandler::getStatus()
|
||||
*/
|
||||
protected function getStatus() {
|
||||
return (boolean) $this->entity->status;
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Taxonomy term translation handler for the entity translation module.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Taxonomy term translation handler.
|
||||
*/
|
||||
class EntityTranslationTaxonomyTermHandler extends EntityTranslationDefaultHandler {
|
||||
|
||||
public function __construct($entity_type, $entity_info, $entity) {
|
||||
parent::__construct('taxonomy_term', $entity_info, $entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see EntityTranslationDefaultHandler::entityForm()
|
||||
*/
|
||||
public function entityForm(&$form, &$form_state) {
|
||||
parent::entityForm($form, $form_state);
|
||||
|
||||
// Remove the translation fieldset when the deletion confirm form is being
|
||||
// displayed.
|
||||
if (isset($form_state['confirm_delete'])) {
|
||||
unset(
|
||||
$form[$this->getLanguageKey()],
|
||||
$form['source_language'],
|
||||
$form['translation'],
|
||||
$form['actions']['delete_translation']
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* User translation handler for the entity translation module.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* User translation handler.
|
||||
*/
|
||||
class EntityTranslationUserHandler extends EntityTranslationDefaultHandler {
|
||||
|
||||
public function __construct($entity_type, $entity_info, $entity) {
|
||||
parent::__construct('user', $entity_info, $entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see EntityTranslationDefaultHandler::entityForm()
|
||||
*/
|
||||
public function entityForm(&$form, &$form_state) {
|
||||
parent::entityForm($form, $form_state);
|
||||
$form['picture']['#multilingual'] = FALSE;
|
||||
$form['locale']['#multilingual'] = FALSE;
|
||||
$form['locale']['#title'] = t('Preferred language settings');
|
||||
}
|
||||
|
||||
/**
|
||||
* @see EntityTranslationDefaultHandler::getLanguageKey()
|
||||
*/
|
||||
public function getLanguageKey() {
|
||||
return 'entity_language';
|
||||
}
|
||||
}
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Translation handler factory for the Entity Translation module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class implementing the entity translation handler factory.
|
||||
*/
|
||||
class EntityTranslationHandlerFactory {
|
||||
|
||||
/**
|
||||
* A singleton instance of the factory.
|
||||
*
|
||||
* @var EntityTranslationHandlerFactory
|
||||
*/
|
||||
protected static $instance;
|
||||
|
||||
/**
|
||||
* Counter used to generate handler ids for new entities.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected static $newId = 1;
|
||||
|
||||
/**
|
||||
* Handlers cache.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $handlers = array();
|
||||
|
||||
/**
|
||||
* The last translation handler retrieved.
|
||||
*
|
||||
* @var EntityTranslationHandlerInterface
|
||||
*/
|
||||
protected $last;
|
||||
|
||||
/**
|
||||
* An array of translation handler retrieved by type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $lastByType = array();
|
||||
|
||||
/**
|
||||
* Returns the singleton instance of the translation handler factory.
|
||||
*
|
||||
* @return EntityTranslationHandlerFactory
|
||||
*/
|
||||
public static function getInstance() {
|
||||
if (!isset(self::$instance)) {
|
||||
self::$instance = new EntityTranslationHandlerFactory();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents the factory from being publicly instantiated.
|
||||
*/
|
||||
protected function __construct() {}
|
||||
|
||||
/**
|
||||
* Translation handler factory.
|
||||
*
|
||||
* @param $entity_type
|
||||
* The type of $entity; e.g. 'node' or 'user'.
|
||||
* @param $entity
|
||||
* The entity to be translated. A bundle name may be passed to instantiate
|
||||
* an empty entity.
|
||||
*
|
||||
* @return EntityTranslationHandlerInterface
|
||||
* A class implementing EntityTranslationHandlerInterface.
|
||||
*/
|
||||
public function getHandler($entity_type, $entity) {
|
||||
if (is_numeric($entity)) {
|
||||
$entities = entity_load($entity_type, array($entity));
|
||||
$entity = reset($entities);
|
||||
}
|
||||
elseif (is_string($entity)) {
|
||||
$entity = entity_create_stub_entity($entity_type, array(NULL, NULL, $entity));
|
||||
}
|
||||
|
||||
$id = $this->getHandlerId($entity_type, $entity);
|
||||
if (!isset($this->handlers[$entity_type][$id])) {
|
||||
$entity_info = entity_get_info($entity_type);
|
||||
$class = $entity_info['translation']['entity_translation']['class'];
|
||||
// @todo Remove the fourth parameter once 3rd-party translation handlers
|
||||
// have been fixed and no longer require the deprecated entity_id
|
||||
// parameter.
|
||||
$handler = new $class($entity_type, $entity_info, $entity, NULL);
|
||||
$handler->setFactory($this);
|
||||
$this->handlers[$entity_type][$id] = $handler;
|
||||
}
|
||||
|
||||
$this->last = $this->handlers[$entity_type][$id];
|
||||
$this->lastByType[$entity_type] = $this->last;
|
||||
$this->last->setEntity($entity);
|
||||
|
||||
return $this->last;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the translation handler identifier for the given entity.
|
||||
*
|
||||
* @param $entity_type
|
||||
* The type of the entity the translation handler will wrap.
|
||||
* @param $entity
|
||||
* The entity the translation handler will wrap.
|
||||
*/
|
||||
public function getHandlerId($entity_type, $entity) {
|
||||
if (!isset($entity->entity_translation_handler_id)) {
|
||||
list($id, $revision_id) = entity_extract_ids($entity_type, $entity);
|
||||
$revision_id = isset($revision_id) ? $revision_id : 0;
|
||||
$entity->entity_translation_handler_id = $entity_type . '-' . (!empty($id) ? 'eid-' . $id . '-' . $revision_id : 'new-' . self::$newId++);
|
||||
}
|
||||
return $entity->entity_translation_handler_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last translation handler retrieved.
|
||||
*
|
||||
* @param $entity_type
|
||||
* (optional) The entity type of the translation handler. Defaults to the
|
||||
* last one.
|
||||
*
|
||||
* @return EntityTranslationHandlerInterface
|
||||
* A class implementing EntityTranslationHandlerInterface.
|
||||
*/
|
||||
public function getLastHandler($entity_type = NULL) {
|
||||
if (isset($entity_type)) {
|
||||
return isset($this->lastByType[$entity_type]) ? $this->lastByType[$entity_type] : NULL;
|
||||
}
|
||||
return $this->last;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user