What is the difference between
function mythemes_preprocess_html(&$variables) { ... }
and
function mythemes_process_html(&$variables) { ... }
in drupal 7 template.php.
when must use preprocess functions and when must use process functions.
thanks.
They're effectively the same thing albeit called in different phases. Preprocess functions are called first and changes are made. Process functions are then called at a later phase and allow for changes to be made to alter any modifications introduced during the preprocess phase.
See http://drupal.org/node/223430 for more information.
More exactly, from Drupal API documentation:
If the implementation is a template file, several functions are called before the template file is invoked, to modify the $variables array. These fall into the "preprocessing" phase and the "processing" phase, and are executed (if they exist), in the following order (note that in the following list, HOOK indicates the theme hook name, MODULE indicates a module name, THEME indicates a theme name, and ENGINE indicates a theme engine name): (source: http://api.drupal.org/api/drupal/includes!theme.inc/function/theme/7)
And if you follow the link above, it will list, in order, the entire theme() progression, from process functions to preprocess functions to the template file itself.
Which stage of process do you want to affect, for this there are two options:
Preprocess function: It runs first.
Process function: Runs after all the preprocess functions have been
execute.
Related
Traditionally I have managed my Angular code like this
//File 1
angular.module('name',[])
//File 2
function TestController(){
}
TestController.prototype.// inherited stuff
angular.module('name').controller('testController',TestController);
This worked great and allowed me to partition my files easily. Now I try to upgrade to 1.3 and get the infamous...
Error: [ng:areq] Argument 'TestController' is not a function, got undefined
Of course this is due to this change which claims a desire to clean up the way people write code. What about this pattern is more complex? Is there a way to maintain this pattern without changing the global settings?
There is actually a comment on the page you linked to that had a fairly solid explanation.
Global controllers refer to your controllers being defined as function
on the window object. This means that they are openly available to
conflict with any other bit of JavaScript that happens to define a
function with the same name. Admittedly, if you post-fix your
controllers with ...Controller then this could well not happen but
there is always the chance, especially if you were to use a number of
3rd party libraries. It is much safer to put these controller
functions inside the safety of a module. You then have more control
over when and where this module gets loaded. Unfortunately controller
names are global across an individual Angular app and so you still
have the potential for conflict but at least you can't clash with
completely different code in the JavaScript global namespace.
So the idea is that global controller functions could conflict with any other global function in any javascript you use. So to eliminate the chance of a conflict with your own code or a third-party script, not using global controllers makes your code safer and more consistent.
As mentioned in the comments by #Brett, you can use IIFE around your prototyping. Here is an update of your plunk that uses that. The main change just looks like this.
(function() {
TestController.prototype.name = 'World'
})();
What comes to my mind is 2 things:
1) in that way functions wont be kept in memory more than they should.
2) if you minify your code, minifyer will have to generate new names for all global objects, which is sfine when you have small project, but will be a problem when it's not.
Also it should prevent tests to modify unnecessary data.
CakePHP has a global function called h. It's a convenience method for htmlspecialchars. CakePHP also has a utility called Sanitize, which has a method called html. Here is part of its description:
This method prepares user-submitted data for display inside HTML. This
is especially useful if you don’t want users to be able to break your
layouts or insert images or scripts inside of your HTML pages.
When should each be used? Is one better than the other?
Sanitize::html() is more versatile: it lets you strip the HTML completely (via remove option), and lets you specify the how it handles quoting.
See the source code:
h(): http://api.cakephp.org/2.3/source-function-h.html#160-199
Sanitize::html(): http://api.cakephp.org/2.3/source-class-Sanitize.html#83-122
EDIT:
h(): calls htmlspecialchars()
Sanitize::html(): calls htmlentities()
For discussion on differences, see: htmlentities() vs. htmlspecialchars()
I'm developing an Apache based application witch few custom modules.
I'd like to share some functionality in one module with others.
I need to wire them together during stratup phase.
I want to use GetModuleHandle + GetProcAddress (it will rununder Windows only) with a module name - but this will succeed only if the module is already loaded by Apache server.
Is there a way to configure the loading order of Apache modules.
I only need to control my modules - others are irrelevant.
Thank's in advance.
If you're trying to control the Apache hook calling order from the source of your module, you can try using APR_HOOK_FIRST, APR_HOOK_MIDDLE, and APR_HOOK_LAST. Or you can specifically name other modules to enforce ordering constraints. From the docs:
... "There are two mechanisms for doing this. The first, rather crude, method, allows us to specify roughly where the hook is run relative to other modules. The final argument control this. There are three possible values: APR_HOOK_FIRST, APR_HOOK_MIDDLE and APR_HOOK_LAST.
"All modules using any particular value may be run in any order relative to each other, but, of course, all modules using APR_HOOK_FIRST will be run before APR_HOOK_MIDDLE which are before APR_HOOK_LAST. Modules that don't care when they are run should use APR_HOOK_MIDDLE. These values are spaced out, so that positions like APR_HOOK_FIRST-2 are possible to hook slightly earlier than other functions. ...
"The other method allows finer control. When a module knows that it must be run before (or after) some other modules, it can specify them by name. The second (third) argument is a NULL-terminated array of strings consisting of the names of modules that must be run before (after) the current module. For example, suppose we want "mod_xyz.c" and "mod_abc.c" to run before we do, then we'd hook as follows ..." [example follows]
I am writing an Apache module and I have run into some confusion regarding the behavior of the directory configuration merge function.
In the source for mod_example, the parameters are labelled like this:
static void *x_merge_dir_config(apr_pool_t *p, void *parent_conf, void *newloc_conf);
But given directives like this:
<Location /path/>
MyOption value-from-path
</Location>
<Location />
MyOption value-from-root
</Location>
When this function is called as a result of an access to http://localhost/path/, the function is called with parent_conf coming from /path/ and newloc_conf coming from /, which is exactly the opposite of what I would expect based on the names of these parameters. I would describe "/" as the parent and "/blog/" as the child/subordinate/most specific path.
I'm trying to figure out what the real story is here. Is Apache using the word "parent" differently than I do? Has mod_example erroneously misnamed these parameters? Am I simply confused?
As I understand it the "parent"/"new" args have more to do with the order in which Apache applies configuration directives than the pathnames associated with those directives. As you know it starts with the per-server, then vhost, then Location sections, etc., with later directives in this list overriding earlier ones. And the job of the merge callback is to compute the result of overriding the stuff in "parent" with the stuff in "newloc".
If multiple Location sections match a request, they are applied in the order they appear in the config file. Therefore, when MyOption value-from-root is merged in, it is the "new" piece of configuration— it's being applied after value-from-path— so it is in the "newloc" arg, and the configuration computed up to that point, including value-from-path, is in "parent".
(As an aside, unless your module has an unusual merge behavior, this means you probably want to swap the order of the two Location sections. The second one, for root, will always apply, and will presumably prevent the first one from ever having a visible effect.)
I writing a module for Drupal 7. It must get current $node variable in one function, e.g. hook_init() or similar, and this variable should be accessible from another function. I found discussion about node_load(arg(1)) and the author of solution said that performance is no concern because of caching.
So, should I call node_load() in every function I need not being afraid of performance issues of are there any other ways to pass variables between module functions?
To be more exact: I've placed a block with module on pages with a certain node types and in hook_block_view function I need to access to current node object. I'm succeeded using node_load so far. But maybe there is a better way.
Thanks in advance!
In drupal 7 node_load() calls entity_load(), which caches the results, so if you call node_load() twice, it will be returned from cache.
Using node_load() is better solution than passing global variables between modules, especially if you use some third-party caching modules (APC, memcached or other). If you care about performance just try to use one of these modules (I prefer memcached).