In Drupal I am working with a view that takes a couple of arguments; the nid argument is just passes along to the next page, but the other three arguments it uses to retrieve content. The problem seems to be that the view uses all arguments to retrieve content, which obviously doesn't work since the presence of nid will always return one single row.
So how do i perform the search (retrieve the content pages) using the three arguments while leaving nid intact as it needs to be passed to another page?
If I understand correctly, the first argument is a nid, and you want that argument to have no effect on the outcome of the view (no filtering)?
If so, adjust the Validator options for the first (nid) argument.
Set Validator to PHP Code.
Leave PHP validate code blank and the argument will always be considered invalid.
Set Action to take if argument does not validate to Display all values.
This will have the effect of ignoring the first argument.
Related
I'm wondering what would be the best way to allow a block to send out a specific amount of Redstone output conditionally. While looking through other blocks that gave a Redstone output, I noticed that they were mostly using the getWeakPower() method. However, I noticed that this was a Deprecated method and my IDE formats the method with a strikethrough. Additionally, I also found another method named getStrongPower() (also Deprecated). Which one of these two method would be best to override or would there be a better way to set the Redstone output of a block.
Although these blocks have the #Deprecated annotation to them, the JavaDoc comment states that "Implementing/overriding is fine". These getWeakPower() and getStrongPower() methods are only flagged as being deprecated in the net.minecraft.block.Block class because they are not meant to be accessed from the Block class, instead they are supposed to be accessed from the net.minecraft.block.BlockState class as that will contain the most up to date state of a given block instance.
It seems that most blocks which use Redstone functionality override the getWeakPower() method to control the Redstone output of the block by returning a specific value from 0 to 15 from the method. It’s also possible to separately control the output of each side (only output on one side or different outputs on each side), by using the Direction parameter passed into the method to determine the returned value.
Note: You must override the canProvidePower() method to return true. Otherwise, neighboring blocks will not check the block for a Redstone output and the desired functionality won’t work.
How can I affect the delta parameter value? Where it can be set?
I'm beginner with Drupal but know my way around PHP and other CMS apps e.g. Joomla. I've working on my first drupal module and need to create a module with multiple blocks. I know how to switch based on the $op parameter but the $delta value seems always to be the default value set in the function declaration.
How can I select which block to process and display? Can $delta be set so that when using modules subnavigation is uses delta to switch to another block view?
Thanks in advance.
hook_block() is used for defining a and displaying blocks. You define the delta when you are producing the data for $op='list' this is passed back to the hook when it it is called for $op='view'.
the $delta argument will therefore be whatever you define. If you define the keys in your list array as red, green and blue that is what will be passed if the block is displayed.
Maby looking at the example will help you.
I want to use a view to select nodes in a content type field. This view must receive an argument that is another field of the content type.
Can someone explain me how to pass the argument from the field to the view?
Excuse my poor english
You might be able to use the Views Arguments Extras module. It will allow the argument of the view to come from a cck field. Some more details about this module (from its project page):
This module contains a group of view handlers and plugins that add the following options:
Argument Default Current Node CCK
allows for cck field values of the current node to be loaded as default arguments
Argument Default Request Params
allows for get and post params as default values
Argument Order Sort
a sort handler, that allows for the order of items to be based on their order in a multi-value argument
I believe you can use the argument validation to validate the argument, and at that point you are free to change the $handler->argument value before it is passed in to Views.
If you just want to change what the view displays based on the value of a CCK field, the easiest way I have found is to embed a view into the template using views_embed_view(). Something like this in your template file would work I think:
//Use the dsm function to print out your $node object
//to get the name of the field you want to pass as an arg
//like this: dsm($node);
//Assuming that the value of that field is in $node->cck_field['0']:
print views_embed_view('name_of_view', 'name_of_display', $node->cck_field['0'];
views_embed_view() only needs the first argument, the name of the view, to work. It will return the HTML for the default display of the named view. We pass it a specific display as a second argument. Anything after the second argument gets passed into the view as an argument, so we pass in the value of the field as an argument to the view. See this link for some documentation on how the function works.
In a legacy MFC CHttpServer based web server, we have a command parsing map something like this:
BEGIN_PARSE_MAP(MyHttpServer, CHttpServer)
ON_PARSE_COMMAND(MyPage, MyHttpServer, ITS_I4 ITS_I4 ITS_I4 ITS_I4 ITS_PSTR ITS_PSTR ITS_PSTR ITS_I4)
ON_PARSE_COMMAND_PARAMS("intParam1=11 intParam2=12 intParam3=13 intParam4=14 strParam5=s5 strParam6=s6 strParam7=s7 intParam8=18")
END_PARSE_MAP(MyHttpServer)
This defines a page accessible at http://host/path/dllname.dll?MyPage that accepts up to 8 parameters named intParam1, intParam2, intParam3, intParam4, strParam5, strParam6, strParam7, and intParam8.
The calling applications can invoke the page with the parameters in a named fashion like this:
http://host/path/dllname.dll?MyPage?intParam4=32&strParam7=somestring
But the way MFC command parsing maps work, they can also call it with unnamed parameters as long as they are provided in the order defined by the map:
http://host/path/dllname.dll?MyPage?21&22&23&24&string5&string6&string7&28
I would like to replace this old code with an ASP.Net page, but we have existing calling applications that will not be changed that invoke the page using both styles of parameter passing, named and unnamed.
I can easily manage the necessary URL rewriting to allow an ASP.Net page to respond to the URL as given above, replacing the path/dllname.dll? MyPage portion with the path to an .aspx page or .ashx handler.
The problem comes in when trying to handle the unnamed parameters in an equivalent fashion to the old MFC parameter parser. Request.QueryString treats all the unnamed parameters as being named with null and Request.QueryString[null] returns a comma-separated list of the values. This is pretty close to workable, but should one of the parameters actually contain a comma, this encoding falls apart because the extra comma is not escaped and splitting the string on the commas will end up with too many parameters.
In classic ASP, I believe Request.QueryString(...) returned a collection of all the parameters that were identically named. There seems to be no equivalent to that in ASP.Net that I can find.
As a secondary issue, the MFC command parsing map had some pretty convoluted logic for dealing with a mixture of named and unnamed parameters. Although the callers of the page in question will not be mixing their usage in this way, I am interested in perhaps duplicating the logic for completeness sake. Can anyone confirm that MFC's behavior was essentially the following?
Process all parameters in the URL from left to right, using & as separator.
If named (has an equal sign), apply the value to the parameter with the corresponding name, regardless of its position. If that parameter already assigned a value, error.
If unnamed, apply the value to the parameter at the nth position in the command parsing map, where n is the number of already processed unnamed parameters plus 1. If that parameter was already assigned a value, error.
Apply default values from command parsing map to any parameters not assigned above
If any parameters from command parsing map have not been assigned a value, error.
One more interesting note, it appears that Request.QueryString.ToString() will nearly reconstitute the original parameters on the URL, but it always moves the parameters with identical names to be together, including the unnamed parameters I am concerned with here.
Not sure if solves your problem, but you could try using Request.PathInfo. This will give you everything entered after the page, which you could then parse manually using something like a regex.
For example, if you had the URL:
http://host/path/dllname.dll?MyPage?21&22&23&24&string5&string6&string7&28
The Request.PathInfo property would return:
?MyPage?21&22&23&24&string5&string6&string7&28
Processing this into a set of values that you can work with could also be problematic as you've got both named and un-named parameters, but this should be achievable using regular expressions and/or splitting the string.
I found that Request.QueryString has a GetValues() method. This returns an array of strings and solves the problem of a comma being embedded within one of the values. It'll be even easier to use than having to split the results of Request.QueryString[null].
I still have a bit of work to use this to implement an MFC-like mapping of URL parameters that handles both named and unnamed parameters.
I have a Panel page, which I have given a path of: books/travel-books/%city/%country/%page. The help text underneath the field says "The URL path to get to this page. You may create named placeholders for variable parts of the path by using %name for required elements and !name for optional elements. For example: "node/%node/foo", "forum/%forum" or "dashboard/!input". These named placeholders can be turned into contexts on the arguments form.", so I have named my arguments appropriately.
So now in my code, I need to get the values of those arguments. I've seen arg(0), but that requires me knowing which index the argument has. Is there anyway to access it by the name I gave it in the path? Something like arg('city')??
The reason being, that I need to have similar path arguments on many pages, and need to access the values of these in my module. But the arguments may be in different places for another page. For instance, another page might be at: flights/%city/%country. Then I want to access the city argument within the same function, but it is at a different index.
Can anyone help?
you can check for arg(0) first, see whether it is 'books', 'flights', whatever... then associate names accordingly. do it as a helper function in a custom module and call it before referencing (wherever you're referencing it).
The text that you quoted from the panels help text is referring to what panels call context.
Panels
Panels has a great use if you want to aware of what context a certain piece of content is being viewed. Fx if you had several shops with different products, you might want to control which blocks in a sidebar would be displayed, based on the shop that the product belonged to.
This is essential what context is in panels and what the named placeholdes are used for. You can be default add different kinds of context, fx nodes, users, taxonomy terms. You can then use the different pieces of context if various ways.
If panels default options is not enough, you can also create your own plugins to panels to make it handle your special cases. But it requires a lot of time to learn how panels work.
Other solutions
Using panels might not be the easiest option for you, it depends what you are aiming for. But if you don't need to make pages that is aware of the context, this would probably be a lot easier to do with views and theming. Views can handle arguments in urls very well, and it is a lot simpler to both style and configure.
In Drupal 7 you can get the arguments from hook_content_type_render
function <your plugin name>_content_type_render($subtype, $conf, $panel_args, $context) {
$block = new StdClass;
$block->title = t('test');
$block->content = 'test panel arg: '.$panel_args[0];
return $block;
}
Custom panel tutorial