I see that Scald has been integrated with Entity Translation. However, at present atom titles are not fields, so they cannot be edited and made translatable, and if I access the 'Translate' tab for an atom, it tells me that my atom has 'No translatable fields'.

I can think of a workaround, where a provider has a new field for the title, and then implements hook_preprocess to replace the title with the currently applicable title (avoiding caches). But it would be better if the Title module could be made to apply to atoms as well.

Is any work under way to make this happen, or should I attempt a patch for either Scald core or Title? Or would they cause other complexities so that it is better if I just try to create a workaround? Any suggestions welcome. Thanks.

Comments

martin_q’s picture

Assigned: Unassigned » martin_q

Answering my own question here, closer inspection of Title suggests I simply need to implement some of the functions in title.core.inc for Scald atoms, so I will try that out and report back.

martin_q’s picture

Status: Active » Needs review
StatusFileSize
new669 bytes

I have been able to integrate Scald with the Title module by adding a few elements to the scald atom's entity info (see attached patch), based on the (woefully undocumented) existing applications of the Title API in title.core.inc.

To translate Scald titles, you have to:

  • enable title and entity_translation modules
  • at admin/structure/scald/video/fields (etc), click to 'replace' the Title with a regular field instance.
  • at admin/config/regional/entity_translation, add Atoms to the Translatable Entity Types.
  • at admin/config/regional/language/configure you may wish to activate a way of detecting the language, such as by URL.
  • also of course at admin/config/regional/language ensure that there is more than one active language on the site.

There are a few things which are not yet quite right, though.

1. When adding new translations of an atom, the form has to be submitted twice, before Drupal redirects to "View" the atom (though it is saved with the first Submit).

2. Deleting translations of atoms is not currently possible - the 'delete' link on the Translate tab will delete the whole atom.

3. When translations of a translatable atom are saved (including the source version, i.e. the original atom), the following notices are shown:

    Notice: Undefined index: scald_thumbnail in EntityTranslationDefaultHandler->entityFormLanguageWidgetSubmit() (line 1278 of /home/mq/KM/www/drupal-7.16/sites/all/modules/entity_translation/includes/translation.handler.inc).
    Notice: Undefined index: scald_authors in EntityTranslationDefaultHandler->entityFormLanguageWidgetSubmit() (line 1278 of /home/mq/KM/www/drupal-7.16/sites/all/modules/entity_translation/includes/translation.handler.inc).
    Notice: Undefined index: scald_tags in EntityTranslationDefaultHandler->entityFormLanguageWidgetSubmit() (line 1278 of /home/mq/KM/www/drupal-7.16/sites/all/modules/entity_translation/includes/translation.handler.inc).
    Notice: Undefined index: title_field in EntityTranslationDefaultHandler->entityFormLanguageWidgetSubmit() (line 1278 of /home/mq/KM/www/drupal-7.16/sites/all/modules/entity_translation/includes/translation.handler.inc).
    Notice: Undefined index: title_field in EntityTranslationDefaultHandler->entityFormLanguageWidgetSubmit() (line 1283 of /home/mq/KM/www/drupal-7.16/sites/all/modules/entity_translation/includes/translation.handler.inc).

I was able to change line 1278 from

      $previous_langcode = $form[$field_name]['#language'];

to

      $previous_langcode = $form['atom0'][$field_name]['#language'];

and line 1283 from

        $form_state['values'][$field_name][$form_langcode] = $form_state['values'][$field_name][$previous_langcode];

to

        $form_state['values']['atom0'][$field_name][$form_langcode] = $form_state['values']['atom0'][$field_name][$previous_langcode];

which solved the problem for atoms, but is obviously not a solution because it would break entity translation for everything else. The question here is, is this a bug in entity_translation or in scald?

4. A note on the side: entity translation does not yet work on taxonomy fields of scald atoms (i.e. authors and tags). If this is enabled, the following errors occur upon submitting an atom:

    Notice: Undefined index: field in field_widget_field() (line 578 of /home/mq/KM/www/drupal-7.16/modules/field/field.form.inc).
    Warning: Invalid argument supplied for foreach() in taxonomy_autocomplete_validate() (line 1750 of /home/mq/KM/www/drupal-7.16/modules/taxonomy/taxonomy.module).
    PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '))' at line 2: SELECT base.tid AS tid, base.vid AS vid, base.name AS name, base.description AS description, base.format AS format, base.weight AS weight, v.machine_name AS vocabulary_machine_name FROM {taxonomy_term_data} base INNER JOIN {taxonomy_vocabulary} v ON base.vid = v.vid WHERE (base.name LIKE :db_condition_placeholder_0 ESCAPE '\\') AND (base.vid IN ()) ; Array ( [:db_condition_placeholder_0] => auteur1 ) in DrupalDefaultEntityController->load() (line 191 of /home/mq/KM/www/drupal-7.16/includes/entity.inc).

I presume the later errors are a result of the problem described in the first notice, but I could not really work out the problem. I discovered I was out of my depth in terms of how entity widgets work.

martin_q’s picture

StatusFileSize
new2.31 KB

Aaargh! I wish I had checked that patch before posting it. As a git noob I obviously did the wrong diff. Correct patch now attached. My apologies.

jcisio’s picture

Title: Translatable Titles (integration with Title module, or workaround) » Integration with Title module
Version: 7.x-1.1 » 7.x-1.x-dev
Status: Needs review » Needs work

So, the ET integration (and its problem) aside, let's concentrate to Title integration in this issue. Patch looks great and it works. It really love to see that we could have some tests for it (with or without the locale module).

shortspoken’s picture

I just tested the Title module integration and it works good. Although when replacing the title field the original content does not get copied into the new title_field.

And I can confirm that it needs two clicks when saving a new translation. Any suggestions how to get rid of this @jcisio?

Tested with Scald 1.3, Drupal 7.34, Title 7.x-1.0-alpha7 and Entity Translation 7.x-1.0-beta4

nagy.balint’s picture

Actually the dev version of the title module and ET module should be used.
Because both had a lot of changes since the last stable version, but mostly the title module where the last stable version was 2 years ago.

In the dev of title i get the following two errors with this patch:
Warning: Invalid argument supplied for foreach() in title_field_sync_get() (line 492 of /sites/all/modules/contrib/title/title.module).
Warning: Illegal string offset 'title' in title_entity_label() (line 130 of /sites/all/modules/contrib/title/title.module).

nagy.balint’s picture

StatusFileSize
new2.34 KB

Here is a new patch for the title module dev version.

The functions return value has changed slightly, however so far i cant create a translation it goes to a bad request. So remains needs work.

nagy.balint’s picture

StatusFileSize
new2.56 KB

Here is another patch that solves the broken translation add/edit links.

Because the following edit path will not work:
'edit path' => 'atom/%scald_atom/edit/%ctools_js',

As we cannot manage translations in the ctools modal anyways. And on the atom page tabs, the %ctools_js placeholder will never be solved.

Its still not ready, i will need to do some more tests on a fresh site.

nagy.balint’s picture

So far it works fine and It seems i dont have issue number 1 where i would need to double save when adding a translation.

So far the problems are :
1. Cant change the title
2. Deleting translation does not work.

nagy.balint’s picture

As far as I can see the issue with 2. is that the entity form does not have a delete button, and so entity translation cannot override the button to be the translation delete button.

nagy.balint’s picture

StatusFileSize
new4.99 KB

The patch attached will also solve the translation deletion issue, by adding a delete translation button.

This also required to implement our own handler extending the default handler.

Now the only thing left to fix is to be able to change the title. Likely an error somewhere in the code at sync.

nagy.balint’s picture

+1 issue i found is that
if 'edit path' => 'atom/%scald_atom/edit/%ctools_js',
Then the ctools edit pages works
if its the new value 'edit path' => 'atom/%scald_atom/edit',
then the links on the translate tab works.

So will need to find some solution to make both work.

Maybe with path schemes but not sure yet how to set that up.

nagy.balint’s picture

StatusFileSize
new4.86 KB

The attached patch works better.
It fixes the issue with the %ctools_js, although not sure if it can be considered as a clean solution.

Also fixes the issue with the title not updating.

However the title field still seems to act up when there is no translation is added, and the user changes the default language value while changing the title.

nagy.balint’s picture

Status: Needs work » Needs review

Putting needs review to trigger the bots.

nagy.balint’s picture

Status: Needs review » Needs work

The other issue the patch has, is that when creating new atoms, the current code prefills the title, however it wont prefill the new title field.

nagy.balint’s picture

To fix the prefill i added the following form alter in scald.module

/*
 * Implements hook_form_FORM_ID_alter().
 * In case the title module is used the title field has to be populated from the title
 * attribute when the user comes from the add step.
 */
function scald_form_scald_atom_add_form_options_alter(&$form, &$form_state, $form_id) {
  if (module_exists('title') && module_exists('entity_translation')) {
    $scald = $form_state['scald'];
    if (isset($scald['type'])) {
      // Setting default values for each created atom
      foreach($form as $key => $data) {
        if (strpos($key, 'atom') === 0) {
          if (!empty($form[$key]['title']['#default_value'])) {
            $langcode = $form['language']['#value'];
            $form[$key]['title_field'][$langcode][0]['value']['#default_value'] = $form[$key]['title']['#default_value'];
          }
        }
      }
    }
  }
}

And the following addition in the ScaldAtom construct after the values array definition

    if (module_exists('entity_translation')) {
      unset($values['language']);
      $handler = entity_translation_get_handler('scald_atom',(object) $values);
      $langcode = $handler->getLanguage();
      $values['language'] = $langcode;
    }

Unfortunately even though this seems right and the atom then correctly gets created by the default language specified in entity translation settings, the atom created this way is not possible to translate :( Because when i try to add a new translation it will just overwrite the original language version.

nagy.balint’s picture

Okey the bug is not related to the code in #16

It is related to the fix in #13 where i replaced the %ctools_js out from the getEditPath in the handler.
Apparently if %ctools_js is in the entity info originally and since getEditPath does not run in all cases, then adding a new translation will not work, cause ET cannot attach itself to the edit page...

No idea why is it soo difficult to make it work.

Maybe it has something to do with the entity not being entity api based.

nagy.balint’s picture

I think I'm postponing this until after 1.4, as i see no point including title integration when the ET integration is such a mess...

nagy.balint’s picture

Title: Integration with Title module » Integration with ET and Title module
mr.york’s picture

StatusFileSize
new2.23 KB
new6.45 KB

Fixed ET generated url and attached #16 code.

mr.york’s picture

Status: Needs work » Needs review
jcisio’s picture

Assigned: martin_q » jcisio

I'll review this patch.

jcisio’s picture

Assigned: jcisio » Unassigned
StatusFileSize
new6.44 KB
new3.5 KB

I've removed the most annoying customization from Title (the sync set/get part). With our workaround sync_set, we lost backward compatibility e.g. $atom = scald_atom_load(1);$atom->title = 'Test title';scald_atom_save($atom); won't work (thanks to @DeFr). Now everything is OK in my test. Plupload integration still works, too.

I'm waiting for another round of feedback and then commit this patch.

nagy.balint’s picture

I will have a look tomorrow.

jcisio’s picture

Status: Needs review » Needs work

I've read the patch again and just found that in scald_form_scald_atom_add_form_options_alter() we need to adjust the check in the same way as in title_field_replacement_info() of the last patch. module_exists('title') is not enough and title_field is hardcoded which is not always correct. I can't test right now so I'm not making another patch until this weekend.

nagy.balint’s picture

It seems to me that even the title_field_replacement_info() is not enough. Because it is possible that I enabled the title replacement for a specific bundle only, like image, but did not enable it for videos lets say.

nagy.balint’s picture

Status: Needs work » Needs review
StatusFileSize
new6.55 KB
new1.98 KB

Something like this should solve those issues.

jcisio’s picture

Status: Needs review » Fixed

That's exactly it! I've rewrite the if condition because with the helper function from Title, we can write it shorter. Committed and pushed. Thanks all for this collaborative work!

  • jcisio committed 67edfee on 7.x-1.x
    Issue #2211409 by nagy.balint, martin_q, jcisio, mr.york, shortspoken:...
jcisio’s picture

StatusFileSize
new1.2 KB

The interdiff for reference.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.