--- translatable-panes-1536944-45.patch 2012-12-06 13:22:48.476287867 -0600 +++ 1536944-ffp-entity-translation.patch 2012-12-06 13:15:18.196276339 -0600 @@ -1,60 +1,34 @@ -From 6bc5fe41c9b5cf12f090722b355d2013cb79c445 Mon Sep 17 00:00:00 2001 -From: jucallme -Date: Fri, 23 Nov 2012 10:40:33 -0300 -Subject: [PATCH] add translations and make the path attribute on the entity a - ---- - fieldable_panels_panes.info | 1 + - fieldable_panels_panes.install | 141 ++++++++++++++++++++- - fieldable_panels_panes.module | 102 +++++++++++++-- - .../translation.handler.fieldable_panels_panes.inc | 30 +++++ - plugins/content_types/fieldable_panels_pane.inc | 13 +- - 5 files changed, 268 insertions(+), 19 deletions(-) - create mode 100644 includes/translation.handler.fieldable_panels_panes.inc - diff --git a/fieldable_panels_panes.info b/fieldable_panels_panes.info -index 836d6b1..0587875 100644 +index 836d6b1..36dbee4 100644 --- a/fieldable_panels_panes.info +++ b/fieldable_panels_panes.info @@ -7,6 +7,7 @@ dependencies[] = "views" dependencies[] = "field_ui" files[] = includes/PanelsPaneController.class.php -+files[] = includes/translation.handler.fieldable_panels_panes.inc ++files[] = includes/translation.handler.fieldable_panels_pane.inc files[] = plugins/views/fieldable_panels_panes_handler_argument_bundle.inc files[] = plugins/views/fieldable_panels_panes_handler_field_bundle.inc files[] = plugins/views/fieldable_panels_panes_handler_field_delete_entity.inc diff --git a/fieldable_panels_panes.install b/fieldable_panels_panes.install -index e5f8747..9e718cd 100644 +index e5f8747..3c54648 100644 --- a/fieldable_panels_panes.install +++ b/fieldable_panels_panes.install -@@ -41,11 +41,6 @@ function fieldable_panels_panes_schema() { - 'type' => 'int', - 'size' => 'tiny', - ), -- 'path' => array( -- 'description' => 'The path the title should link to.', -- 'type' => 'varchar', -- 'length' => 255, -- ), - 'reusable' => array( - 'description' => 'Whether or not this entity will appear in the Add Content dialog.', - 'type' => 'int', -@@ -64,6 +59,13 @@ function fieldable_panels_panes_schema() { - 'description' => 'The category it will appear in the Add Content dialog under.', - 'type' => 'text', +@@ -96,6 +96,13 @@ function fieldable_panels_panes_schema() { + 'default' => '', + 'description' => 'The Universally Unique Identifier.', ), + 'language' => array( -+ 'description' => 'The language of this entity.', ++ 'description' => 'The {languages}.language of this entity.', + 'type' => 'varchar', -+ 'length' => 32, ++ 'length' => 12, + 'not null' => TRUE, + 'default' => '', + ), - 'view_access' => array( - 'type' => 'text', - 'size' => 'big', -@@ -210,3 +212,132 @@ function fieldable_panels_panes_update_7105() { + ), + 'primary key' => array('fpid'), + 'indexes' => array( +@@ -210,3 +217,19 @@ function fieldable_panels_panes_update_7105() { db_add_field('fieldable_panels_panes', 'link', array('type' => 'int', 'size' => 'tiny', 'description' => 'Whether or not this entity title will link to another page.')); db_add_field('fieldable_panels_panes', 'path', array('type' => 'varchar', 'length' => 255, 'description' => 'The path the title should link to.')); } @@ -62,317 +36,93 @@ index e5f8747..9e718cd 100644 +/** + * Add language column. + */ -+function fieldable_panels_panes_update_7107(&$sandbox) { -+ $table = 'fieldable_panels_panes'; -+ $field = 'language'; -+ -+ if (!db_field_exists($table, $field)) { -+ $schema = drupal_get_schema($table, TRUE); -+ db_add_field($table, $field, $schema['fields'][$field]); -+ -+ db_update($table) -+ ->fields(array($field => LANGUAGE_NONE)) -+ ->execute(); -+ -+ return t("Added $table.language field."); -+ } -+ -+ return t("$table.language field already exists, updated skipped."); -+} -+ -+/** -+ * Add new path field instance. -+ */ -+function fieldable_panels_panes_update_7108(&$sandbox) { -+ // make sure the new field is registered with drupal -+ field_info_cache_clear(); -+ -+ // add the new path field. -+ fieldable_panels_panes_install(); -+} -+ -+/** -+ * Migrate the path data into a field instance. -+ */ -+function fieldable_panels_panes_update_7109(&$sandbox) { -+ if (!isset($sandbox['progress'])) { -+ $sandbox['progress'] = 0; -+ $sandbox['current_id'] = 0; -+ $sandbox['max'] = db_query('SELECT COUNT(DISTINCT fpid) FROM {fieldable_panels_panes}')->fetchField() - 1; -+ } -+ // miragte all path data into the field. -+ $query = db_select('fieldable_panels_panes', 'f'); -+ -+ $query -+ ->condition('f.fpid', $sandbox['current_id'], '>') -+ ->condition('f.path', '', '<>') -+ ->fields('f', array('fpid', 'path')) -+ ->orderBy('f.fpid', 'ASC') -+ ->range(0, 50); -+ -+ $results = $query->execute(); -+ -+ if ($results->rowCount() > 0) { -+ foreach($results as $result) { -+ $entity = fieldable_panels_panes_load($result->fpid); -+ // The default is to enable this field but NOT to make it translatable -+ // As not every one will use that. So we can only set the default value -+ // Of UND. -+ if (isset($entity->bundle)) { -+ $entity->fieldable_panels_panes_path[LANGUAGE_NONE][0]['value'] = $result->path; -+ fieldable_panels_panes_save($entity); -+ } -+ $sandbox['current_id'] = $entity->fpid; -+ $sandbox['progress']++; -+ } -+ $sandbox['#finished'] = empty($sandbox['max']) ? TRUE : ($sandbox['progress'] / $sandbox['max']); -+ } -+ else{ -+ $sandbox['#finished'] = TRUE; -+ } -+} -+ -+/** -+ * Drop the old path off the entity. -+ */ -+function fieldable_panels_panes_update_7110(&$sandbox) { -+ // remove the old path field. -+ db_drop_field('fieldable_panels_panes', 'path'); -+} -+ -+/** -+ * Implements hook_install(). -+ */ -+function fieldable_panels_panes_install() { -+ $field = array( -+ 'field_name' => 'fieldable_panels_panes_path', -+ 'cadinality' => 1, -+ 'type' => 'text', -+ 'locked' => TRUE, -+ ); -+ -+ // During installation, the t() function is unavailable, so we use get_t() -+ // to store the name of the translation function. -+ $t = get_t(); -+ -+ field_create_field($field); -+ $field_instances = array( -+ 'field_fieldable_panels_panes_path' => array( -+ 'field_name' => 'fieldable_panels_panes_path', -+ 'label' => $t('Path'), -+ 'description' => $t('The path the title should link to.'), -+ 'required' => FALSE, -+ 'widget' => array( -+ 'type' => 'fieldable_panels_panes_path', -+ ), -+ 'display' => array( -+ 'default' => array( -+ 'label' => 'hidden', -+ 'type' => 'hidden', -+ ), -+ ), -+ 'settings' => array( -+ 'text_processing' => 0, -+ ), -+ ), -+ ); -+ -+ //create the instance -+ $entity_info = entity_get_info('fieldable_panels_pane'); -+ foreach ($field_instances as $field_instance) { -+ foreach ($entity_info['bundles'] as $bundle => $info) { -+ $field_instance['entity_type'] = 'fieldable_panels_pane'; -+ $field_instance['bundle'] = $bundle; -+ field_create_instance($field_instance); -+ } ++function fieldable_panels_panes_update_7106() { ++ // Make sure to add language field ++ if (!db_field_exists('fieldable_panels_panes', 'language')) { ++ db_add_field('fieldable_panels_panes', 'language', array( ++ 'description' => 'The {languages}.language of this entity.', ++ 'type' => 'varchar', ++ 'length' => 12, ++ 'not null' => TRUE, ++ 'default' => '', ++ )); + } +} diff --git a/fieldable_panels_panes.module b/fieldable_panels_panes.module -index ca14b2a..733befb 100644 +index ca14b2a..a82af8f 100644 --- a/fieldable_panels_panes.module +++ b/fieldable_panels_panes.module -@@ -50,7 +50,34 @@ function fieldable_panels_panes_entity_info() { - 'custom settings' => FALSE, - ), +@@ -26,6 +26,7 @@ function fieldable_panels_panes_entity_info() { + 'revision' => 'vid', + 'bundle' => 'bundle', + 'label' => 'admin_title', ++ 'language' => 'language', + 'uuid' => 'uuid', + 'revision uuid' => 'vuuid', ), -- -+ // Add title replacement support for translations. -+ 'field replacement' => array( -+ 'title' => array( -+ 'field' => array( -+ 'type' => 'text', -+ 'cardinality' => 1, -+ 'translatable' => TRUE, -+ ), -+ 'instance' => array( -+ 'label' => t('Title'), -+ 'required' => TRUE, -+ 'settings' => array( -+ 'text_processing' => 0, -+ ), -+ 'widget' => array( -+ 'weight' => -5, -+ ), -+ ), -+ ), -+ ), +@@ -56,6 +57,16 @@ function fieldable_panels_panes_entity_info() { + 'creation callback' => 'fieldable_panels_panes_create', + 'access callback' => 'fieldable_panels_panes_access', + 'save callback' => 'fieldable_panels_panes_save', ++ ++ // Entity translation support + 'translation' => array( + 'entity_translation' => array( -+ 'class' => 'EntityTranslationFieldablePanelsPanesHandler', ++ 'class' => 'EntityTranslationFieldablePanelsPaneHandler', + 'base path' => 'admin/structure/fieldable-panels-panes/view/%fieldable_panels_panes', + 'edit path' => 'admin/structure/fieldable-panels-panes/view/%fieldable_panels_panes/edit', + 'path wildcard' => '%fieldable_panels_panes', + ), + ), - // entity module callbacks - 'view callback' => 'entity_metadata_view_single', - 'creation callback' => 'fieldable_panels_panes_create', -@@ -577,10 +604,12 @@ function template_preprocess_fieldable_panels_pane(&$vars) { - * Add a class for our bundle to the normal panels pane theme. - */ - function fieldable_panels_panes_preprocess_panels_pane(&$vars) { -+ global $language; - if ($vars['pane']->type == 'fieldable_panels_pane') { - $entity = fieldable_panels_panes_load_entity($vars['pane']->subtype); -+ $items = field_get_items('fieldable_panels_pane', $entity, 'fieldable_panels_panes_path', $language->language); - if ($entity->link && !empty($vars['title'])) { -- $vars['title'] = l($vars['title'], $entity->path); -+ $vars['title'] = l($vars['title'], $items[0]['value']); - } - $vars['classes_array'][] = 'pane-bundle-' . ctools_cleanstring($entity->bundle, array('lower case' => TRUE)); - } -@@ -760,6 +789,12 @@ function fieldable_panels_panes_get_base_context($entity = NULL) { - */ + ), + ); + } +@@ -761,6 +772,13 @@ function fieldable_panels_panes_get_base_context($entity = NULL) { function fieldable_panels_panes_entity_edit_form($form, &$form_state) { $entity = $form_state['entity']; + + // Map these properties for entity translations. + $form['#entity_type'] = array( + '#type' => 'hidden', + '#value' => $entity->bundle, + ); + $form_state['fieldable_panels_pane'] = $form_state['entity']; - ++ // fixes a bug in wysiwyg // oh wysiwyg. We need a better way to address this. -@@ -788,12 +823,15 @@ function fieldable_panels_panes_entity_edit_form($form, &$form_state) { - '#id' => 'edit-link', - ); - -- $form['link']['path'] = array( -- '#type' => 'textfield', -- '#title' => t('Path'), -- '#description' => t('The path for this link. This can be an internal Drupal path such as %add-node or an external URL such as %drupal. Enter %front to link to the front page.', array('%front' => '', '%add-node' => 'node/add', '%drupal' => 'http://drupal.org')), -- '#dependency' => array('edit-link' => array(1)), -- '#default_value' => $entity->path, -+ $langcode = fieldable_panels_panes_get_lang_code($entity); -+ field_attach_form('fieldable_panels_pane', $entity, $form, $form_state, $langcode); -+ -+ // Shift the fieldable_panels_panes_path into the link fold and -+ // Make it dependent on link. -+ $form['fieldable_panels_panes_path']['#states'] = array( -+ 'visible' => array( -+ ':input#edit-link' => array('checked' => TRUE), -+ ), - ); - - $form['reusable'] = array( -@@ -859,8 +897,6 @@ function fieldable_panels_panes_entity_edit_form($form, &$form_state) { + // drupal_add_css('sites/all/libraries/ckeditor/skins/kama/editor.css'); +@@ -859,7 +877,12 @@ function fieldable_panels_panes_entity_edit_form($form, &$form_state) { '#default_value' => '', ); - field_attach_form('fieldable_panels_pane', $entity, $form, $form_state); -- - if (!empty($form_state['add submit'])) { - $form['actions'] = array( - '#type' => 'actions', -@@ -879,7 +915,26 @@ function fieldable_panels_panes_entity_edit_form($form, &$form_state) { - * Validate callback for the pane entity. - */ - function fieldable_panels_panes_entity_edit_form_validate($form, &$form_state) { -- field_attach_form_validate('fieldable_panels_pane', $form_state['entity'], $form, $form_state); -+ $entity = $form_state['entity']; -+ $langcode = fieldable_panels_panes_get_lang_code($entity); -+ field_attach_form_validate('fieldable_panels_pane', $entity, $form, $form_state); -+ if ($form_state['values']['link']) { -+ if (isset($form_state['values']['fieldable_panels_panes_path'][$langcode][0]['value']) -+ && !empty($form_state['values']['fieldable_panels_panes_path'][$langcode][0]['value'])) { -+ // Check that the link exists -+ $source = valid_url($form_state['values']['fieldable_panels_panes_path'][$langcode][0]['value'], TRUE); -+ if (!$source) { -+ $normal_path = drupal_get_normal_path($form_state['values']['fieldable_panels_panes_path'][$langcode][0]['value']); -+ $source = drupal_valid_path($normal_path); -+ } -+ if (!$source) { -+ form_set_error('fieldable_panels_panes_path', t('The path / url does not exist.')); -+ } -+ } -+ else { -+ form_set_error('fieldable_panels_panes_path', t('You have selected that the title links to a path please enter a valid path / url, or unselect "Make title a link".')); -+ } ++ $language = NULL; ++ if (function_exists('entity_language')) { ++ // entity_language() was added in Drupal 7.15. ++ $language = entity_language('fieldable_panels_pane', $entity); + } - } ++ field_attach_form('fieldable_panels_pane', $entity, $form, $form_state, $language); - /** -@@ -891,11 +946,11 @@ function fieldable_panels_panes_entity_edit_form_submit($form, &$form_state) { - // Copy hardcoded fields. - $entity->title = $form_state['values']['title']; - $entity->link = $form_state['values']['link']; -- $entity->path = $form_state['values']['path']; - $entity->reusable = $form_state['values']['reusable']; - $entity->category = $form_state['values']['category']; - $entity->admin_title = $form_state['values']['admin_title']; - $entity->admin_description = $form_state['values']['admin_description']; -+ $entity->fieldable_panels_panes_path = $form_state['values']['fieldable_panels_panes_path']; - - $entity->revision = $form_state['values']['revision']; - // Only set a log message if there was a new revision. This prevents -@@ -911,3 +966,26 @@ function fieldable_panels_panes_entity_edit_form_submit($form, &$form_state) { - drupal_set_message(t('The entity has been saved.')); - } - } -+ -+/** -+ * Determine what language to use. -+ */ -+function fieldable_panels_panes_get_lang_code($entity, $form = TRUE) { -+ // Provide support for translations -+ if (module_exists('entity_translation') -+ && entity_translation_enabled('fieldable_panels_pane')) { -+ $handler = entity_translation_get_handler('fieldable_panels_pane', $entity); -+ if ($form) { -+ $langcode = $handler->getFormLanguage(); -+ } -+ else { -+ $langcode = $handler->getLanguage(); -+ } -+ -+ } -+ else { -+ $langcode = entity_language('fieldable_panels_pane'); -+ } -+ -+ return $langcode; -+} -diff --git a/includes/translation.handler.fieldable_panels_panes.inc b/includes/translation.handler.fieldable_panels_panes.inc + if (!empty($form_state['add submit'])) { + $form['actions'] = array( +diff --git a/includes/translation.handler.fieldable_panels_pane.inc b/includes/translation.handler.fieldable_panels_pane.inc new file mode 100644 -index 0000000..c93444a +index 0000000..e2fd933 --- /dev/null -+++ b/includes/translation.handler.fieldable_panels_panes.inc -@@ -0,0 +1,30 @@ ++++ b/includes/translation.handler.fieldable_panels_pane.inc +@@ -0,0 +1,21 @@ +entity); + } -+ -+ protected function getEntityId() { -+ if (isset($this->entity->fpid)) { -+ return $this->entity->fpid; -+ } -+ return parent::getEntityId(); -+ } +} -diff --git a/plugins/content_types/fieldable_panels_pane.inc b/plugins/content_types/fieldable_panels_pane.inc -index daf9961..b0a0842 100644 ---- a/plugins/content_types/fieldable_panels_pane.inc -+++ b/plugins/content_types/fieldable_panels_pane.inc -@@ -88,6 +88,16 @@ function fieldable_panels_panes_fieldable_panels_pane_content_type_render($subty - 'query' => drupal_get_destination(), - ); - } -+ if (module_exists('entity_translation') -+ && entity_translation_enabled('fieldable_panels_pane') -+ && entity_translation_tab_access('fieldable_panels_pane', $entity)) { -+ $block->admin_links[] = array( -+ 'title' => t('Translate pane'), -+ 'alt' => t("Translate the values in this pane"), -+ 'href' => "admin/structure/fieldable-panels-panes/view/$entity->fpid/translate", -+ 'query' => drupal_get_destination(), -+ ); -+ } - - return $block; - } -@@ -295,8 +305,7 @@ function fieldable_panels_panes_load_entity($subtype_name) { - function _fieldable_panels_panes_load_entity($subtype_name) { - list($type, $id) = explode(':', $subtype_name); - if ($type == 'uuid' && module_exists('uuid')) { -- $ids = entity_get_id_by_uuid('fieldable_panels_pane', array($id)); -- if ($content = entity_load('fieldable_panels_pane', $ids)) { -+ if ($content = entity_uuid_load('fieldable_panels_pane', array($id))) { - $content = reset($content); - } - } --- -1.7.11.3 -