Is it possible to use queryContent from a custom module with #nuxt/content v2? - nuxtjs3

I am creating a custom module to create some hook code that runs at 'build:done' lifecycle. I've tried this with a raw hook and with my current custom module, but neither makes the queryContent function available (it's always undefined), which I need to parse markdown files. Is there no way of getting the queryContent from a module or hook?
I also tried direct importing queryContent it but it is not actually exported so I get export errors. Also tried grabbing $content but it's not available on v2.

Related

Using using dynamically

I want to use modules dynamically and I know their name, but creating a module and then applying using like this:
using PyPlot
a = Module(:Plots)
using a
will yield an excpetion telling me that a is not definied. Which is a very unintuitive error message, since when you do this on the repl you can use 'a' afterwards. Just in combination with using it tells you that it is not defined.
The error message is emitted by Base.require, so you should use using Main.a or using .a instead:
require(module::Symbol)
This function is part of the implementation of using / import, if a module is not already
defined in Main. It can also be called directly to force reloading a module, regardless of
whether it has been loaded before (for example, when interactively developing libraries).
...
When searching for files, require first looks for package code under Pkg.dir(), then tries paths
in the global array LOAD_PATH. require is case-sensitive on all platforms, including those with
case-insensitive filesystems like macOS and Windows.
Or just use module keyword to define a module on the fly:
module A
...
end
using A
For an existing module, you could also dynamically use it via eval(using module-name).

Can we use PHP inbuilt function inside Twig File in Symfony

Hi Can anyone Please let me know can we use php inbuilt function inside a twig file.if not then why.
What is the way then to access php inbuilt function inside a twig file.
Because in a application in 100 of time we need to check many conditions basis of php inbuilt function.I have tried in_array() function to check multiple vaslue selected in a multiple dropdown list but i am getting error Is_array() not defined.
Please help
Thanks
As #DonCallisto Said, There is some PHP equivalent function exists in twig not all. So you cant call a php function from twig template. You may have to use a existing equivalent or need to create one if not exists.
Why?
One of the main reason is SoC. Template is for presentation layer of your application. So twig made available tools(filter,functions, global variables) to do that.
Know the differences
Though you have date function in twig. its not the same date function you have in php. To achieve a similar functionality you may have to use same or different approach in twig then php. for instance you can achieve php's in_array functionality using the twig's Containment Operator
What is the way
Now come to last part of your question:
What is the way then to access php inbuilt function inside a twig file?
I think you already know the short answer from #DonCallisto. You can create your own extension. And define what function you needed. Or if you are crazy enough to access all php builtin function from your template, you can use this Extension. It will allow you to call any php functions by prefixed with php_. for example if you like to call in_array function, then you can call like php_in_array() from your template.
Happy coding!
Twig have some php builtin functions equivalent. For instance in_array() php function is in twig function. Check it out
If you don't find some builtin, you need to write your own twig exstension

module_invoke_all not returning all modules

I'm creating a module wich provides a separate node overview page for each content type.
My problem lies in trying to recreate the node operations dropdown.
In the node module this is done by calling the module_invoke_all function with the 'node_operations' hook.
This returns an array of all modules that implement the 'node_operations' hook.
In my case the following two modules: 'node' and 'nodewords'.
When I call module_invoke_all('node_operations') in my module, it returns only the 'nodewords' module, not the 'node' module.
This is because the 'node_node_operations' function does not exist.
Can anyone explain this behavior?
It looks like the hook is in node.admin.inc, which is not automatically included. See http://api.drupal.org/api/drupal/modules--node--node.admin.inc/function/node_node_operations/7
This is imho a bug, you should look if there already is an issue and if not, create a new one.
Anyway, as a workaround, you can include the node.admin.inc file like this before calling the hook:
<?php
module_load_include('inc', 'node', 'node.admin');
?>
(Yeah, weird syntax ;))

using module_invoke_all to submit a form question

here is more detailed explanation:
i am using the ubercart module with the file download feature module (the uc_file module ).
i have created a product class (which is a new content-type as far as the drupal system) and add a cck file field to it.
what i want to achive is the following behavior:
once a user saves a new node of my product class, i want the uploaded file to be added as a file download feature to the product class automatically.
i know i can hack the function uc_file_feature_form_submit($form, &$form_state), do what it does in my module code, but i rather ivoke it since i'll have easier life with future changes to the uc_file module (since i am calling it's function, i dont care if it will change in the future).
so, to invoke the uc_file_feature_form_submit function i need to build fake $form, &$form_state parameters, i know i can print_r those arrays, and build it from there, the thing is that there are a lot of data in those arrays that is not mandatory, i was wondering what are those mandatory fields that i have to build on my own.
thank you...
Short answer: Look at the submit function you are trying to invoke. The form values that it's using are the ones you need.
Long answer . . . need more info before I can give a better answer.
You can use drupal_execute() to programatically execute a form. I am not sure if it works with files though.

Find a list of modules that 'altered' a specific form in Drupal

Is there a trick, addon or patch that allows me to find out what modules altered a specfic form?
A list of all hook_form_alters is not too hard to achieve. But I want to list only those that actually changed my form.
Modules can alter a form trough a generic modulename_form_alter() and modulename_form_FORMID_alter() it would be nice if both are taken into consideration.
The drupal_prepare_form function calls all hook_form_alter functions. In this function, there is no storage for any modules that implement hook_form_alter. However, there is a container ($data) there that pulls all the alter functions then is applied with drupal_alter. Getting this data would require modifying this file (ref: line 543 in /includes/form.inc in Drupal 6.19).

Resources