hook_menu() - an unexpected behaviour (longer path issue) - drupal

I am initializing a number of items via hook_menu (Drupal 6)
...
$items['webtv/block/%/playlist/edit/%'] = array(
...
'page arguments' => array('webtv_playlist_form', 2, 5),
...
);
$items['webtv/block/%/playlist/edit/%/filter/new'] = array(
...
'page arguments' => array('webtv_playlist_param_form', 2, 5),
...
);
$items['webtv/block/%/playlist/edit/%/filter/%'] = array(
...
'page arguments' => array('webtv_playlist_param_form', 2, 5, 7),
...
);
return $items;
First entry is a parent entry and works fine. The following two are child entries. These last two menu entries remain invalid and redirects to parent page view. I fixed it with a small modification by eliminating first wild card '%/' mark from the path definitions.
Means:
$items['webtv/block/%/playlist/edit/%/filter/%']
to
$items['webtv/block/playlist/edit/%/filter/%']
and
$items['webtv/block/%/playlist/edit/%/filter/new']
to
$items['webtv/block/playlist/edit/%/filter/new']
Please help me out what I am doing wrong by adding a wild card? Is more than two wild card are invalid?

It is not mentioned sufficiently in the documentation, but there is a limit on the number of path elements you can use for a Drupal menu callback - see the MENU_MAX_PARTS constant.
For Drupal 6, this limit is seven, which your second and third path exceeded. Both of your fixes bring the element count down to seven, which is why those work.

I have fixed the issue without excepting first wild card as I mentioned it. But I could not found any logical reason.
$items['webtv/block/%/playlist/edit/%/filter/%']
to
$items['webtv/block/%/playlist/edit/%/%']
and
$items['webtv/block/%/playlist/edit/%/filter/new']
to
$items['webtv/block/%/playlist/edit/%/new']

Related

Symfony Unit Testing - Set Value for Javascript Rendered Elements

In Unit Testing, How can I set a value to the Select box options in which drop down options are rendered from Javascript ?
When I set a value, I am getting Invalidargument exception.
Note: Form is a general HTML Form
Referred links: symfony unit tests: add/modify form action
Thanks for # Matteo comments.
In Unit testing,
For setting values for the Select box, which are not available in the Drop down,
Use Posting the data instead of submitting the form,
$this->client->request('POST', $postUrl, $formValueArray);
$formValueArray = array('data' => 'value');
or
$formValueArray = array(
'myform' => array(
'data' => 'value'
))
);
Note: It can be used to set all the form fields which are not available in the forms.

Lucene.Net.Search.BooleanQuery+TooManyClauses: System error

I am trying to search with the below params, and I am wondering why some cause this exception to be thrown.
Only a few params are not working. All others are working.
?q=220v+0+ph => Not working
?q=220v+1+ph => Not working
?q=220v+2+ph => Not working
?q=220v+3+ph => Not working
?q=220v+4+ph => Working
?q=220v+5+ph => Working
?q=220v+6+ph => Working
?q=220v+7+ph => Working
?q=220v+8+ph => Working
?q=220v+9+ph => Working
I am checking the center character. It is not working only in the cases of 0, 1, 2 and 3.
Query: {+(title:480v* content:480v title:3* content:3 title:ph* content:ph)
One or more of your wildcard queries is generating too many term matches. Wildcard queries are rewritten by enumerating all of the matching terms, and create a set of primitive queries matching them, combined in a BooleanQuery.
For instance, the query title:foo*, could be rewritten to title:foobar title:food title:foolish title:footpad, in an index containing those terms.
By default, a BooleanQuery allows a maximum of 1024 clauses. If you have over 1024 different terms in the index matching title:0*, for instance, that is likely your problem.

Drupal 7 block configuration module

I have problems implementing module in drupal 7.
Whole module initially shows block with links to the five latest nodes made by current user, and in the configuration section user can change number of nodes that are shown.
I did manage to implement block that shows five latest nodes made by current user but I'm not managing to make block configuration work correctly.
First I made configuration form which looks like this:
function latest_posts_block_configure($delta = ''){
$form = array();
if($delta == 'latest_posts'){
$form['latest_posts'] = array(
'#type' => 'select',
'#title' => t('Number of recent content items to display'),
'#default_value' => variable_get('latest_posts', 3),
'#options' => drupal_map_assoc(array(2, 3, 4, 5, 6, 7, 8, 9, 10)),
);
)
return $form
}
This block configuration form works fine, but I don't know how to implement hook_block_save (that should (I guess) apply options chosen in configuration form).
My idea is to take the value selected from the form and to put it into sql query that extracts nodes but since I'm drupal beginner I am still struggling with it.
Can anyone help me?
http://api.drupal.org/api/drupal/modules%21block%21block.api.php/function/hook_block_save/7 could give you a hint. Then you may use the variable you set in configuration in your query.

How to register a wildcard url in Drupal with the hook_menu?

I'm starting to work with Drupal and I'm really confused as how to create a hook_menu function that allows you to register a URL with 1 or 2 different values, that can be hidden and not displayed in the breadcrumbs.
Any help on this would be much appreciated. Even an example.
Not sure about the breadcrumbs bit, but I think you're looking for wildcard (%) and auto-loader wildcard (%mymodule_entity) components in the path.
From the hook_menu() page...
Wildcards within paths also work with integer substitution. For example, your module could register path 'my-module/%/edit'. When path 'my-module/foo/edit' is requested, integer 1 will be replaced with 'foo' and passed to the callback function. Note that wildcards may not be used as the first component.
$items['my-module/%/edit'] = array(
'page callback' => 'mymodule_abc_edit',
'page arguments' => array(1),
);
Registered paths may also contain special "auto-loader" wildcard components in the form of '%mymodule_abc', where the '%' part means that this path component is a wildcard, and the 'mymodule_abc' part defines the prefix for a load function, which here would be named mymodule_abc_load().
$items['my-module/%mymodule_abc/edit'] = array(
'page callback' => 'mymodule_abc_edit',
'page arguments' => array(1),
);

What is a user category exactly?

I wanted to add a tab to the user edit page ie user/%/edit/foo, and was using the twitter module as a model. After much spelunking and stepping through with a debugger, I realised that I needed to add a hook_user function in my module so that the %user_category part of the menu router path would work.
It's now functioning as expected, but I don't really have a solid idea of what I just did, and haven't found a good explanation anywhere.
Can anyone explain to me what it's about?
user_category_loads fails if given a category that does not exist, which happens at user/uid/edit/not_a_category, and it passes that category for access checks to user/uid/edit/is_a_category and thus access to those is set to false, so bam, wonky menu :'(.
When you use %user_category it means that user_category_load function is called with that argument (the uid).
The function is defined in the user module. These functions serve as a validation, if False it return FALSE, it will result in a 404, but if it return something else, like a user object, that will be passed to whatever callback function / form is run for that url.
In your case, you could probably have used %user instead which would have called user_load which is more simple, and you wouldn't have needed to do all the extra stuff to make user_category_load pass.
Summary
So user_category_load does two things.
Check that the category exist so you just can't do user/%/edit/foo.
Caches the user object.
After much trial and error, I was able to get a page working as a child of the user/%/edit path using code like this:
<?php
/**
* Implementation of hook_menu().
*/
function noc_profile_privacy_menu() {
return array(
'user/%user_category/edit/privacy' => array(
'title' => 'Portfolio privacy',
'page callback' => 'drupal_get_form',
'page arguments' => array('noc_profile_privacy_form', 1),
'access callback' => 'content_profile_page_access',
'access arguments' => array('profile', 1),
'type' => MENU_LOCAL_TASK,
'load arguments' => array('%map', '%index'),
),
);
}
/**
* Implementation of hook_user().
*/
function noc_profile_privacy_user($op, &$edit, &$account, $category = NULL) {
if ($op === 'categories') {
return array(array(
'name' => 'privacy',
'title' => t('Profile privacy'),
'weight' => 0,
));
}
}
Note that the 'name' key of what I'm returning in hook_user() is the same as what comes after user/%user/category/edit in my hook_menu() definition. I believe that is key. You will also get an error if you omit the 'load arguments' item, with exactly that value.
So I believe what the user category is is the 'privacy' in my case - the bit after edit in the path of the menu item definition.
Is this an unnecessary complication? Yes, so it seems.
Edit: I see my co-worker hefox beat me to replying to this question. I wouldn't have been able to figure all of this out without Fox's help, so mad props to the Fox.

Resources