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.
Please can explain how to use "PHP Code Before Output" and "PHP Code After Output"?
Is there a way to access to the field content?
thanks
Comments
Comment #1
vegansupreme CreditAttribution: vegansupreme commentedfield content is
$content
Other variables that can be accessed are:
I think you can also access $border.
Additionally, you can use TCPDF and PHP functions.
For more info check out Views PDF Documentation under "Render Settings"
Comment #2
leonano CreditAttribution: leonano commentedThanks vegansupreme.
$content is the view of the field? In my case is a field collection, so has different fields into the content, can I access all value by $content->title for example? Or is the html result of the field formatter?
Let me explain:
I have a field collection and in PDF every field of this collection is printed with great space before and after.
I print out this collection on node with a panel view of 3 column, but is not possible with PDF?
Comment #3
vegansupreme CreditAttribution: vegansupreme commentedI believe it is the html result of the field formatter. To reduce that extra space, you could strip div tags under field rewriting. TCPDF doesn't always handle divs nicely.
As far as columns, this can be done, start reading around #21 #1345182: Positioning Field Output for Columns
Also If you want to experiment with 7.x-2.x you could try the branch in comment #75 I'm looking for feedback, thought it's still pretty rough.
Comment #4
sander-martijn CreditAttribution: sander-martijn commentedI came here because I assumed what vegansupreme said - but I don't think it's true. I did exactly that, but if I don't put
tags around it then the field contents just become whatever is written (in my case as a test I am using "$content .= ' ' . $h;" which in theory should output the field plus the height. If I do I get nothing output and in the admin I'm seeing:
Notice: Undefined variable: h in eval() (line 2 of /path/site.com/modules/php/php.module(80) : eval()'d code).
Notice: Undefined variable: content in eval() (line 2 of /path/site.com/modules/php/php.module(80) : eval()'d code).
fyi what I'm hoping for is that the height will give me an indicator of whether the content has wrapped to two lines or not and adjust the positioning accordingly.
Comment #5
vegansupreme CreditAttribution: vegansupreme commentedYou must check the 'bypass php_eval' checkbox and NOT use
<?php
tags for any of that to work. This was a "feature" that was introduced after those instructions were written.$h is the height that's specified in the field position, if you leave that field blank, it will probably just be blank. I've yet to figure out auto height. You might be able to do what you need with
$this->y
instead.Comment #6
killua99 CreditAttribution: killua99 commented