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.
In weblinks_blocks_block_view() we add a css file:
function weblinks_blocks_block_view($delta, $options = array()) {
drupal_add_css(drupal_get_path('module', 'weblinks_blocks') . '/weblinks_blocks.css');
However, it should be done using the #attached property. See also https://api.drupal.org/comment/44413#comment-44413
This issue was reported in #2429855: Blocks setting "Show description" not working as defined - credit to Gerhard for spotting the problem. It is unrelated to that problem so should be fixed separately, so that a proper record of the change can be made.
Comment | File | Size | Author |
---|---|---|---|
#11 | 2443235_11.attach_block_css.patch | 5.64 KB | jonathan1055 |
Comments
Comment #1
jonathan1055 CreditAttribution: jonathan1055 commentedIn weblinks_blocks_block_view() we currently put the generated content directly into $block['content'] in various place throughout the function, and doing it this way there is a default implication that this string is a markup value. However, to allow us to use the '#attached' property we need $block['content'] to be an array with key '#markup' holding the actual content. This requires minor changes to create
$content
instead of$block['content']
(and same with subject). Then only at the end, when we know there is some content, we can create the full $block array with the necessary keys.As a side-note, we also used to have
in weblinks_blocks_form_alter() but that has since been removed, as it is done in the main weblinks.module code. Maybe we should review all the places where css files are loaded.
Here's a patch, including some commented-out debug which you may wish to use.
Comment #2
GStegemann CreditAttribution: GStegemann commentedI will test the patch later today.
Yes. See also #2457353: Web Links main Links page information is displayed twice.
Comment #3
GStegemann CreditAttribution: GStegemann commentedI have tested your patch right now.
It works so far that blocks will be displayed correctly. But when attempting to display a block on a Web Links page (via More link) only the word 'Array' is displayed:
<div class="weblinkCat weblinkCat-depth-0"><fieldset class="collapsible form-wrapper"><legend><span class="fieldset-legend">Beliebt Drupal Links</span></legend><div class="fieldset-wrapper">Array</div></fieldset>
It looks like that the interface between weblinks_blocks_block_view() and weblinks_page is broken.
Comment #4
jonathan1055 CreditAttribution: jonathan1055 commentedYes you are right. It works fine for the term groups /weblinks/x but fails for the text strings such as /weblinks/recent and /weblinks/popular. I had forgotten that weblinks_page() for those urls re-uses the block output. The folloowing one-line change to add '#markup' fixes it.
I would like expand the automated testing to trap this, as it was a major problem introduced here which I should have noticed.
Comment #5
GStegemann CreditAttribution: GStegemann commentedStill not good. Now just a < character is displayed:
<div class="weblinkCat weblinkCat-depth-0"><fieldset class="collapsible form-wrapper"><legend><span class="fieldset-legend">Beliebt Links</span></legend><div class="fieldset-wrapper"><</div></fieldset>
That's the content of #markup:
<div class="item-list"><ul class="weblinks"><li class="weblinks weblinks-item weblinks-link-37 first"><div class="weblinks-link"><a href="http://www.drupalcenter.de/" class="weblinks-extra weblinks-link previewlink" target="_blank" title="Drupal Center">Drupal Center</a></div><div class="description"><p>Deutschsprachige Drupal Community <br /> </p> </div><div class="weblinks-click-stats">Clicked 8 times. Last clicked 7. März 2015 - 17:29</div></li> <li class="weblinks weblinks-item weblinks-link-72"><div class="weblinks-link"><a href="http://www.drupal-initiative.de/" class="weblinks-extra weblinks-link previewlink" target="_blank" title="Drupal Initiative e.V.">Drupal Initiative e.V.</a></div><div class="description"><p>Die Drupal e. V. ist ein gemeinnütziger Verein, der dabei hilft, Drupal in Deutschland bekannter zu machen.</p> </div><div class="weblinks-click-stats">Clicked 3 times. Last clicked 13. Januar 2015 - 13:50</div></li> <li class="weblinks weblinks-item weblinks-link-36 last"><div class="weblinks-link"><a href="https://www.drupal.org/" class="weblinks-extra weblinks-link previewlink" target="_blank" title="Drupal.org">Drupal.org</a></div><div class="description"><p>Community plumbing</p> </div><div class="weblinks-click-stats">Clicked 2 times. Last clicked 12. Februar 2015 - 10:25</div></li> </ul></div>
Comment #6
jonathan1055 CreditAttribution: jonathan1055 commentedOdd. It worked for me ok. Must be something to do with putting the #markup directly into the output. I think we should not be dealing with direct html here, it feels like we are doing thing to manually.
Comment #7
GStegemann CreditAttribution: GStegemann commentedAll-clear now. Somehow the patch was not fully applied. I guess due to all the patches the last days.
Sorry not catching this earlier.
Comment #8
jonathan1055 CreditAttribution: jonathan1055 commentedNow that I've added a couple of new tests in https://www.drupal.org/node/460622#comment-9767537 I'm going to re-queue thre patch, and it should fail.
Comment #11
jonathan1055 CreditAttribution: jonathan1055 commentedHere's the patch with #markup added (and some commented out debug removed). This should pass the new automated tests now.
Comment #12
GStegemann CreditAttribution: GStegemann commentedThanks. Tested and works.
Comment #14
jonathan1055 CreditAttribution: jonathan1055 commentedExcellent, thank you.