I'm using kartik mpdf extension to print a report. Problem is, in print view css code displaying and in footer debug toolbar code too. Please guide me how to remove that.
i'm using following code.
$content = $this->render('print', ['modelPatientTest' => $modelPatientTest]);
$pdf = new Pdf([
'mode' => Pdf::MODE_CORE, // leaner size using standard fonts
'content' => $content,
'format' => Pdf::FORMAT_A4,
'options' => [
'title' => 'Test Report',
],
'methods' => [
'SetHeader' => [''],
'SetFooter' => ['{PAGENO}|'],
]
]);
return $pdf->render();
As Debug toolbar should be active only in a development environment, put at the top of your controller's action this code:
if(YII_DEBUG === true || YII_ENV === "dev") {
Yii::$app->getModule('debug')->instance->allowedIPs = [];
}
(Edited thanks to #Gubberrr comment below)
Just change
'mode' => Pdf::MODE_CORE,
to
'mode' => Pdf::MODE_UTF8,
Related
I have this code snippet from a symfonycasts video tutorial:
#[Route('/')]
public function homepage(): Response
{
$tracks = [
['song' => 'Gangsta\'s Paradise', 'artist' => 'Coolio'],
['song' => 'Waterfalls', 'artist' => 'TLC'],
['song' => 'Creep', 'artist' => 'Radiohead'],
['song' => 'Kiss from a Rose', 'artist' => 'Seal'],
['song' => 'On Bended Knee', 'artist' => 'Boyz II Men'],
['song' => 'Fantasy', 'artist' => 'Mariah Carey'],
];
var_dump($tracks);
return $this->render('home/homepage.html.twig', [
'Heyyyy' => 'Waaasssup',
'tracks' => $tracks,
]);
}
I know that i should not use a var_dump but i wanted to try anyway and it actually displays the dump on the browser page but i don't get how...
I thought that the content of the final page would only be the content's value from the Response object that is returned by the render() method? So how can the var_dump content be displayed on the final page?
Am i missing something? Thanks.
I tried to understand... and it led to nothing!
#Jakumi is right, the PHP Interpreter will prepend the dumped output before anything else in the response content.
See the php documentation for more information about var_dump().
It also states, that you can control the output by using the Output Control of php. (see PHP Output Control)
We've a Drupal 9 installation and are trying to add a pager using the pagerer module for articles entityQuery, the aim is to list tagged articles in a tag page, but it’s not working. It returns null.
When we dump the data without the pager, using default drupal query, it returns the data of all tagged articles properly.
The code is added in the theme file themeName_preprocess_page hook and being called in page--page.html.twig template file.
Here’s our code:
$query = \Drupal::entityQuery('node')
->condition('status', 1)
->condition('type', 'article');
->pager(2);
$nids = $query->sort('created', 'DESC')
->execute();
if($nids):
$nodesNews = \Drupal\node\Entity\Node::loadMultiple($nids);
$pathNews = base_path();
$pager = [
'articles_data' => $nodesNews,
'results' => [
'#theme' => 'news_pagination',
'#items' => $nodesNews,
'#path' => $pathNews,
'#tag' => $tag
],
'pager' => [
'#type' => 'pager',
'#quantity' => 5
],
];
return $pager;
endif;
And here is the code that calls the query:
<div>
{{ articles_data }}
{{ pager }}
</div>
The above code returns only one page in the navigation and we’ve 10 articles, so given that we set 2 articles per page, the output should be 5 pages instead of 1.
Also articles_data attribute returns null. Could you please help me to find what’s wrong with the code? Happy to share more information as needed, thank you.
Just reading the docs for this module here,
it would seem that you are missing at least the #theme and #style keys in your render array for the pager.
A more likely to succeed version of the above render array would be
$pager = [
'articles_data' => $nodesNews,
'results' => [
'#theme' => 'news_pagination',
'#items' => $nodesNews,
'#path' => $pathNews,
'#tag' => $tag
],
'pager' => [
'#type' => 'pager',
'#theme' => 'pagerer_base',
'#style' => 'standard',
'#config' => [
'display_restriction' => 0,
],
'#quantity' => 5
],
];
I'm using kartik mpdf extension and trying to style the pdf using "cssFile" property.
But any font I want to set (even from Web Safe Fonts or my oun font-face) don't effect the content of pdf file.
Any help?
I thank you should configure cssFile and cssInline in kartik,
For example in PDF controller you have
public function actionPdf()
{
$pdf = new Pdf([
'mode' => Pdf::MODE_CORE,
'format' => Pdf::FORMAT_A4,
'orientation' => Pdf::ORIENT_PORTRAIT,
'destination' => Pdf::DEST_BROWSER,
'content' => $contents,
'filename' => 'Filename',
'cssFile' => '#vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.css',
'cssInline' => '.modal-footer{text-align:left;}div.modal-body{padding:0px;}',
'options' => ['title' => 'Devis'],
'methods' => [
'SetFooter'=>[$footer],
]
]);
Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;
$headers = Yii::$app->response->headers;
$headers->add('Content-Type', 'application/pdf');
return $pdf->render();
}
And you should go to this file in vendor folder to do what you want in css #vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.css
And the required style (for exemple color: #fff !important) you should do that in this ligne 'cssInline' => '.modal-footer{text-align:left;}div.modal-body{padding:0px;}',
he asked how change font-family in pdf file.
Names of basic fonts are located in config_font.php.
You can add custom fonts in this file.
Example
$this->fontdata = array( ... "pompadur" => array( 'R' => "Pompadur.ttf", ), ... )
paste to your html: style="font-family: Pompadur"
I'm writing a views display plguin, I defined it as follows in mymodule.views.inc
function mymodule_views_plugins() {
$plugins['style']['mymodule_articles_list'] = array(
'title' => t('mymodule Articles Listing'),
'help' => t('Display Articles using citation'),
'path' => drupal_get_path('module', 'mymodule'),
'handler' => 'mymodule_articles_list_style_plugin',
'uses row plugin' => TRUE,
'uses options' => TRUE,
'uses grouping' => FALSE,
'type' => 'normal',
'use pager' => FALSE,
'use ajax' => FALSE,
'theme' => 'mymodule_articles_list'
);
return $plugins;
}
I created class and theme functions. When I select 'mymodule Articles Listing' while created view I get error
Display "Master" has an invalid style plugin. Display "Page" has an
invalid style plugin.
Upate 1
While running in devel execute php
$style_plugin = views_get_plugin('style','mumodule_articles_list');
does not return any thing, which means there is something wrong with definition
The first error is returned from views_plugin_display::validate(), which executes the following code.
$style = $this->get_plugin();
if (empty($style)) {
$errors[] = t('Display "#display" has an invalid style plugin.', array('#display' => $this->display->display_title));
}
The code that views_plugin_display::get_plugin() executes when it is called without arguments is practically the following one.
$name = $this->get_option('style_plugin');
$plugin = views_get_plugin('style', $name);
if (!$plugin) {
return;
}
That code fails when views_get_plugin() doesn't find the plugin definition for $name, which could happen when it doesn't find the file containing the handler, or the name returned from views_plugin_display::get_option() is wrong.
I've constructed a custom module to create a form. Now I'm stuck on the theming. I already have a CSS stylesheet for the form, since my company is part of the government and they have a preset branding. So I wanted to change the HTML used by the default form theme functions of Drupal thus implementing the correct style.
But only the form-tag of the form gets rendered. The fieldset and elements are not rendered. When the theme functions are removed the default theming kicks in and the form renders normally (but of course without the requested theming).
What I have tried so far:
Added a hook_theme function to add theme functions
function publicatieaanvraagformulier_theme() {
return array(
'publicatieaanvraagformulier_form' => array(
'arguments' => array("element" => NULL)
),
'publicatieaanvraagformulier_fieldset' => array(
'arguments' => array("element" => NULL)
),
'publicatieaanvraagformulier_form_element' => array(
'arguments' => array(
"element" => NULL,
"value" => NULL
)
)
);
}
Added ['#theme'] to the form-element, fieldset-element and the form-elements
$form['#theme'] = "publicatieaanvraagformulier_form";
$form['groep'] = array(
'#title' => t("Please fill in your details"),
'#type' => "fieldset",
'#theme' => "publicatieaanvraagformulier_fieldset"
);
$form['groep']['organisatie'] = array(
'#title' => t("Organization"),
'#type' => "textfield",
'#attributes' => array("class" => "text"),
'#theme' => "publicatieaanvraagformulier_form_element"
);
Added the actual theme function based on the default ones in form.inc
function theme_publicatieaanvraagformulier_form($element) {
function theme_publicatieaanvraagformulier_fieldset($element)
function theme_publicatieaanvraagformulier_form_element($element, $value)
I haven't included the code of these functions because even with the default themefunctions code, they don't work. Therefor I assume they are not the source of the problem.
The form is called
//Get the form
$form = drupal_get_form('publicatieaanvraagformulier');
//Add messages
$errors = form_get_errors();
if (!empty($errors)) {
$output .= theme("status_messages","error");
}
//Show form
$output .= $form;
return $output;
I haven't found similar 'complicated' examples of theming a form, but have pieced together the former from books and online searches.
Hopefully someone has an answer to this problem (point out the mistake I made).
Greetings
Jeroen