Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Blocks configuration: the setting "Show description" does not work as defined.
"No" works. But "Teaser" not: even when selected the full description is shown in the block. Apart from the random block: there is the setting fully ignored. This block displays the links always with no description.
Comment | File | Size | Author |
---|---|---|---|
#15 | 2429855_15.block_description_settings.patch | 2.77 KB | jonathan1055 |
Comments
Comment #1
GStegemann CreditAttribution: GStegemann commentedMore things to be checked:
In weblinks_blocks_block_view we add a css file.
However, how we do it is wrong. To have JS/CSS be attached to a block when caching is on, the #attached property should be used. See also https://api.drupal.org/comment/44413#comment-44413
Next we might have a problem with the added parameter $option to pass the limit to a block. On my test site the amount of links for the random blocks seems to be fixed at 5. Or the evaluation of the limit should be reversed.
See also https://api.drupal.org/comment/48768#comment-48768
Comment #2
GStegemann CreditAttribution: GStegemann commentedRegarding the random block $limit problem: after running more tests it turns out to be likely a caching issue or will be in effect after a certain amount of cron runs.
Comment #3
jonathan1055 CreditAttribution: jonathan1055 commentedRegarding the limit I think it is working ok, at least it is corect for other blocks. The Random one is slightly different in that the content is not refreshed until the time is up, so it may not relect your desired setting until the next rebuild.
Thanks for noticing the css attachment. Yes, we'll do that.
Comment #4
jonathan1055 CreditAttribution: jonathan1055 commentedDone some investigation and I've found that the teaser display problem is created in function theme_weblinks_block_item() where we derive our own summary value:
This probably worked in Drupal6 but in D7 if a separate summary value has been entered for the node there is a 'summary' key value in the $items[0] array. Hence we should check if this exists and use it as the input to text_summary in preference to $items[0]['value'].
Function text_summary() can take a third parameter which is the trim length. The default is taken from variable 'teaser_length' which seems to be maintained for backwards compatibility but is no longer used, reading through the update functions in node.install. The old default was 600 but this is no longer configurable like it was in D6. It must be in the field config settings somewhere. Anyway, that's half of the problem discovered.
I think the Random block behaves in the same way as the others - for testing it is better to have the 'update every' value blank so that the content is refreshed as soon as the settings are changed.
Comment #5
GStegemann CreditAttribution: GStegemann commentedI have found sample code in the documentation of text_summary and can check how to apply it in theme_weblinks_block_item(). There is also described how to determine the trim length.
You are probably right. I will perform more tests.
Comment #6
jonathan1055 CreditAttribution: jonathan1055 commentedHere's a patch which addresses the teaser problem. The trim length is recovered using
I have also done the work on the css #attached problem, but I think it is better to review these two things separately. Although they do not really affect each other, it just makes the patch look more complex. Two of the changes in this patch are to split up creating arrays and returning them. This is better practice as it allows debugging to check the values before return.
Comment #7
GStegemann CreditAttribution: GStegemann commentedThanks. I have tested the patch and it works.
But before I mark it as RTBC I want that you review the similar implementation in weblinks_weblinks_preprocess which I wrote during the port to D7:
Yes, it is better to handle these two things separately. And to store return values into variables before returning from a function is also OK.
Comment #8
jonathan1055 CreditAttribution: jonathan1055 commentedI have created a separate issue #2443235: Add block css using the #attached property
Comment #9
jonathan1055 CreditAttribution: jonathan1055 commentedThanks for drawing that to my attention. OK, comparing the two implementation, the differences are:
$field_langcode = field_language('node', $node, 'body'
which is good. This is marked as a @TODO in theme_weblinks_block_item() so I could add that to the patchI also noticed that in weblinks_weblinks_preprocess() the variable $sanitize is only set where we have a body field, which is fine. But given that it is always 1 the variable is never going to be used when it is not 1, so it can be removed, and the following code simplified by removing the conditional tests.
Comment #10
GStegemann CreditAttribution: GStegemann commentedYou're welcome.
My answers:
Regarding variable 'sanitize': I copied the code from somewhere and left it in to be able to optionally turning sanitization on or off. But you're right: this option is really not needed.
Comment #11
jonathan1055 CreditAttribution: jonathan1055 commentedHere is a patch (with debug) to show my work so far.
1. I have added the $langcode support
2. I've catered for the body field being deleted (but not actually tested this yet)
3. I have used _text_sanitize()
4. Always trim the text for teaser, even if using the separte summary field. This involved making a temporary array to pass to _text_sanitize() but it works well.
Maybe some more work to do, but thought you should see (and check) the direction of the work so far.
Comment #12
GStegemann CreditAttribution: GStegemann commentedThanks. I will test your patch later.
But one question: why did you remove the 'div' and the class 'description'? Just for testing or for a specific reason?
Comment #13
jonathan1055 CreditAttribution: jonathan1055 commentedThat was an error, sorry! I had previously added the lines
after the switch, so that if we need to adjust the html or classes then it is is all done in one place, to be consistent. I had some editting problems yesterday and those lines got deleted by mistake. Here's an updated patch.
Comment #14
GStegemann CreditAttribution: GStegemann commentedI've tested the patch now. I think it works.
The only thing which does not look pretty is the formatting of the Link Description. See https://www.drupal.org/files/issues/d7_weblinks_blocks_popular_2406139_8.... The left margin is too far left. I already corrected the class names in the Blocks css.
And your debug code caused a notice: Notice: Undefined variable: field_langcode in theme_weblinks_block_item() (line 292 of /var/www/html/cm7/sites/all/modules/weblinks/contribs/weblinks_blocks/weblinks_blocks.module).
Comment #15
jonathan1055 CreditAttribution: jonathan1055 commentedYes I know that the styling is untidy - we discovered that in #2406139: Last click time and click count doubled or trebled up in title and it is going to be fixed in that issue as mentioned here
Based on your comment, are you happy if I commit the attached patch? It is the same apart from all debug removed and the output returned via variable
$output
not directly in thereturn
statement.Comment #16
GStegemann CreditAttribution: GStegemann commentedYes, please commit. Thanks.
Comment #19
jonathan1055 CreditAttribution: jonathan1055 commentedThank you for your testing. We are making really good progress now.