Reproduce:
- set up an input format with language sections support
- enable the language sections titles module from ls_extras
- see that unless an explicit title was provided in the node body, it is empty(!) on display
The cause for this is the overwriting of the filtered text with the title return value (which is empty if there was no title specified in the body):
function language_sections_filter($op, $delta = 0, $format = -1, $text = '') {
// ...
switch ($op) {
case 'process':
// ....
// Extract title if present.
if (function_exists('ls_titles_process')) {
$out = ls_titles_process('set', $out);
}
return $out;
// ...
}
I'm not sure even about the intention of this code, but it certainly looks bad to overwrite the filtered text body entirely with the return of the title found in that text.
Also, even if the body would have a title set, the current version of ls_titles will not save/return it with how the code is currently written. It will only save if the $id argument is passed (which is not done in the above code):
if ($id) $saved = compact('id', 'title', 'text');
return $saved[$part];
Finally, the whole ls_titles_process() code attempts to give the impression that it stores all kinds of title data in $saved, but as the above code shows, the array is overwritten with each invocation to the function, so there is not much of a point in having a static array there.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | return-original.patch | 433 bytes | gábor hojtsy |
Comments
Comment #1
andy inman commented"Finally, the whole ls_titles_process() code attempts to give the impression that it stores all kinds of title data in $saved ..."
Excuse me? My code doesn't attempt to give impressions. Admittedly, it may not actually work as intended, but it certainly doesn't pretend to be anything other than what it was designed for.
Perhaps you could offer a working patch to fix the behaviour you are complaining about?
FYI, the use of a static array is because the $op == 'process' code will get called twice when LS_Titles is in use. *If* there is a bug here it is in LS_Extras and not in Language Sections, so I'm closing this. Please re-post in the LS_Extras issue queue, thank you.
Comment #2
gábor hojtsy@netgenius: ok, that means that ls_titles_process() should return the processed text and NOT the title as it does currently? If that's the case, then maybe all of the bug belongs to ls_titles then.
Comment #3
gábor hojtsyMoving to the right module as per maintainer feedback.
Comment #4
gábor hojtsyHonestly the reason I did not provide a patch is because I don't see how you plan to process this text, the flow of the code is not at all clear to me. If we consider the caller has no issue, the minimal patch that is IMHO required is attached. You only save the data into $saved if $id was set, and in this case, the caller does not set the $id, so no data will be saved and therefore no data will be returned. The attached patch at least returns the data, even if it is not saved (I'm not sure how you intend to save the data if there is no $id). This will still require the data to be processed multiple times if this function is called multiple times without an $id.
Feedback welcome.
Comment #5
andy inman commentedI apologise, I probably jumped at you - I had just arrived home after more than four hours driving!
Thanks for the patch. However, now reading your comments and looking again I think I see what the underlying problem is - it's a version mismatch between Language Sections and LS Extras - if you look at language_sections-6.x-2.x-dev.tar.gz you will see (line 38 onwards) ...
... i.e. it has the ·$cache_id parameter in there - the released versions should be compatible (unless I made a mistake). So, please try the current (non-dev) releases of both modules, and if that doesn't work then the dev releases should work together.
Additional info:
I agree that the flow of the code is difficult to follow, and that's due to the way that it has to work - to keep titles processing in a separate module and keep the Language Sections input filter as simple as possible for people who do not want the titles functionality (the majority.) This in turn relates to the history of the module - the titles functionality was added in response to demand from a few users.
So, under normal circumstances (called directly from check_markup), if a title: line is included in the text, it must be removed from the text - that is why we have:
... which will (should!) simply return $out after removing the title: line, if present.
Comment #6
andy inman commentedI notice I already had the following on the LS Extras project page under the heading Development version
The current dev version includes a new module LS Search which addresses #361069: Only default language is indexed for search and needs the current dev release of Language Sections in order to work.
So hopefully its a case of RTFM :) but, if you can confirm that the released versions doe not work together, please let me know.
Comment #7
gábor hojtsy@netgenius: you can take a look at the source for the current latest released versions:
http://drupalcode.org/viewvc/drupal/contributions/modules/ls_extras/ls_t...
http://drupalcode.org/viewvc/drupal/contributions/modules/language_secti...
You can see that in the released versions, ls_titles_process() is called with ls_titles_process('set', $out), (ie. no $id is passed). Again, the released version of ls_titles.module does not store the value if there was no $id and will return $saved[$part] while $saved will be empty, so the node body is deleted. This bug report is about this issue. I think this hardly works as designed.
Looking at the CVS data, ls_titles did not change since the 1.8 release, so looks like this was a bug indeed with Language sections, as I've originally reported, right? Moving it back then. Also, marking as duplicate, rather then as designed, since this is an actual bug that you've seem to have fixed in the dev version via some other issue or your own work.
When is a new Language sections release expected so a bugfix can be rolled out?
Comment #8
gábor hojtsyAlso, while the actual issue at hand might be solved by passing on the cache_id, let me state once again that I consider it bad practice to have **optional** arguments on a function, but if you don't provide those, you get an empty response. Once again, I tried to explain these issues above, and even if the caller is fixed and everything works right, the API function itself looks weak.
Comment #9
andy inman commentedThanks for the info. Ok, investigated more and confirmed it's a bug in 1.8, details below.
As an aside, from a design perspective, the whole LS Titles concept is arguably a bit of a hack! I don't really like it, but added it in response to feedback from a few members of the community. I am focussed on *not* breaking Language Sections in order to support LS Titles - Language Sections has many users and LS Titles has very few. For the same reason, I think this issue belongs here and not in the Language Sections queue - Language Sections works fine for people who are not using LS Titles (and that's 95% of them.)
The ls_titles_process function is not meant to be a generic API, it's only intended for use internally by LS modules. Clearly it was intended to produce valid results when optional parameters are omitted -- they are optional to allow it to work with either the dev release or current release of Language Sections (but there is a bug...)
In LS Extras 1.7 we had:
i.e the $id parameter was added in 1.8 - that release was primarily to provide better Views support (added ls_node_title() function). That version also tried to provide some performance enhancements, which introduced the $id parameter. That change was supposed to be backward compatible with the existing Language Sections release (2.5), hence $id needed to be an optional parameter. Yes, looking now at the code, it doesn't work properly, and I probably made the mistake of testing with the dev version of Language Sections installed rather than the 2.5 release. So, unintentionally, LS Extras 1.8 is not compatible with Language Sections 2.5 because it fails to calculate the $id value if not passed by the caller. The bug was introduced in LS Extras 1.8. The two possible solutions are (1) Fix LS Extras or (2) Upgrade Language Sections. So for the short term, let's fix LS Extras rather than make an unnecessary new release of Language Sections which would only be relevant to a handful of users.
Proposed solution:
This should make it work the way it was originally intended, whereas I think your proposed patch may have undesired side-effects.
Again, IMHO this is an LS Extras issue, not Language Sections.
Comment #10
andy inman commentedComment #11
andy inman commentedNow fixed in cvs, and to be released as 1.9.
Comment #12
andy inman commentedFixed, tested and released as 1.9.