Commit d6d95289 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Add a warning when a pieform element fails to add data to <head> tag



If a pieform is built after a call to the smarty function, elements
that a pieform element wants to put into <head> (usually js files)
may be omitted and it can be hard to track down the cause of these
errors.

This patch will produce a warning (intended for the programmer) if a
pieform element that defines the _get_headdata() function is built
after the smarty function has already been called.

Change-Id: Icf120242f521d4324548ac84228fea54d75eab8c
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent b584959f
......@@ -1400,6 +1400,11 @@ EOF;
$element['helphtml'] = '<span class="help"><a href="" title="' . Pieform::hsc($element['help']) . '" onclick="return false;">?</a></span>';
}
}
// Issue a warning if this element wants to add something in the <head> tag, and it's too late to do that.
if (defined('PIEFORM_GOT_HEADDATA') && function_exists('pieform_element_' . $element['type'] . '_get_headdata')) {
log_warn('Pieform element ' . $this->name . '_' . $element['name'] . ' wants to add headdata to the page, but it\'s too late. Build your form before generating the page.');
}
}/*}}}*/
/**
......
......@@ -85,6 +85,7 @@ function smarty($javascript = array(), $headers = array(), $pagestrings = array(
if (function_exists('pieform_get_headdata')) {
$headers = array_merge($headers, pieform_get_headdata());
define('PIEFORM_GOT_HEADDATA', 1);
}
// Insert the appropriate javascript tags
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment