Changes in module_menu() aren't applying - drupal-6

I have a custom module called tf_partner. I just modified this to include another argument. Inside the module I have:
function tf_partner_menu()
{
//... more code.....
$items['partner/letters/word/replace/%/%/%/%'] = array(
'page callback' => 'tf_partner_replace_image',
'access callback' => TRUE,
'page arguments' => array(4, 5, 6, 7),
'type' => MENU_CALLBACK,
'file' => 'tf_partner_letters.inc.php',
);
//...more code
}
This is what it used to be ...
function tf_partner_menu()
{
//... more code.....
$items['partner/letters/word/replace/%/%/%'] = array(
'page callback' => 'tf_partner_replace_image',
'access callback' => TRUE,
'page arguments' => array(4, 5, 6),
'type' => MENU_CALLBACK,
'file' => 'tf_partner_letters.inc.php',
);
//...more code
}
function tf_partner_replace_image($aid, $letter, $position, $randstr)
{
echo "here"; //doesn't show up
}
The problem is when I try to go to the new url, it doesn't work and goes to /partner/letters/word. I already went to admin/build/modules, but still getting the problem. I checked the database (menu_router table) and it looks correct.
EDIT: Also, I created a new function similar to this and a new menu item. I started with 1 argument and added one at a time. It allowed me up to 3. When I added the 4th one, it didn't work anymore.

clear cache on admin/settings/performance
or by emptying cache_{name} tables in database.
code looks fine, I guess menu just didn't get rebuilt.

Related

How to make a block visible only for admin and teacher in moodle?

I think there are more than one way to make block invisible for students.
1.
Hide the block
2.
Assign role to block and set permission to block
But these are done by admin by change the settings. I need a way by code. How can I write the code to make the block invisible for student.
For activity I can make invisible the activity by changing db/access.php
'mod/questionbank:view' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_MODULE,
'legacy' => array(
//'guest' => CAP_ALLOW,
//'student' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),
Like this how can I make the block invisible for student by code.
EDIT
according to Davosmith's answer.
I put inside get_content function
if (!has_capability('blocks/blockname:view')) {
return null;
}
in blocks/blockname/block_blockname.php
and in my blocks/blockname/db/access.php contain:
'blocks/blockname:view' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_BLOCK,
'legacy' => array(
//'guest' => CAP_ALLOW,
//'student' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
// 'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
)
),
But it results in error page saying
Coding error detected, it must be fixed by a programmer: PHP catchable
fatal error
For any block, if get_contents returns null (and editing is off), the block will not be displayed.
So, put the following in the get_content function of your block (but put in a real capability that you define in db/access.php):
if (!has_capability('block/myblock:somecapability', $this->context)) {
return null;
}

Why am I getting a page not found error after creating a new menu item?

In my module file I created a new menu item
function xmlproject_menu()
{
$items = array();
//more items here
$items['system/xml/cfa/initialize/%/%/%/%/%'] = array(
'page callback' => 'xmlproject_initialize_cf',
'page arguments' => array(4, 5, 6, 7, 8,),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
function xmlproject_initialize_cf($session_id, $cart_id, $pid, $rid, $partner_id)
{
//some code here
}
I have tried going to admin/build/modules, devel/menu/reset, and admin/settings/performance to clear the cache. I can see the menu item in the database (menu_router).
When I go to http://example.com/system/xml/cfa/initialize/1/2/3/4/5 I am getting "Page not found".
You code seems all dandy, but I suppose your page callback "xmlproject_initialize_cf" should actually return something.
Try this:
function xmlproject_initialize_cf($session_id, $cart_id, $pid, $rid, $partner_id)
{
// Your Code
return 'Hello world!';
}
Is the modules name "xmlproject"?
Does not seems anything wrong with your code.
Just curious, why you have kept the last element of array as 'empty' (a comma after number 8)
'page arguments' => array(4, 5, 6, 7, 8,),
Also, there is additional empty item in the array (extra comma after MENU_CALLBACK)
'type' => MENU_CALLBACK,
As you see in your database number_part column that contains Number of parts in router path,sets to 7(maximum available part),but your parts of menu callback is 9.Which is more than MENU_MAX_PARTS available in drupal 6. this is why you're getting Page not found
Just reduce your menu item size and you are good to go.for example:
$items['initialize/%/%/%/%/%'] = array(
'page callback' => 'xmlproject_initialize_cf',
'page arguments' => array(4, 5, 6, 7, 8),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);

How to set sort order while add attribute programmatically

I want to set sort order in attribute. In mysql file i m used this
$installer->addAttribute('customer','badge', array(
'label' => 'Badge',
'type' => 'text', //backend_type
'input' => 'multiselect', //frontend_input
'backend' => 'eav/entity_attribute_backend_array',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'source' => 'marketplace/eav_entity_attribute_source_badge', // Goes to Step 2
'visible' => true,
'required' => false,
'default' => '',
'frontend' => '',
'unique' => false,
'note' => '',
'sort_order' => 10
));
Mage::getSingleton('eav/config')
->getAttribute('customer', 'badge')
->setData('used_in_forms', array('customer_account_create','customer_account_edit','customer_address_edit','checkout_onepage_register','checkout_onepage_register_guest','checkout_onepage_billing_address','adminhtml_customer','checkout_onepage_shipping_address','checkout_multishipping_register'))
->save();
but it not worked how to set sort order for this attribute
when you add attribute programmatically that time you have to set order like this
Mage::getSingleton('eav/config')
->getAttribute('customer', 'badge')
->setSortOrder(100)
->setData('used_in_forms', array('customer_account_create','customer_account_edit','customer_address_edit','checkout_onepage_register','checkout_onepage_register_guest','checkout_onepage_billing_address','adminhtml_customer','checkout_onepage_shipping_address','checkout_multishipping_register'))
->save();
'sort_order' is not worked
Or
You have to use position instead of sort_order.
'position' => 20
From Mage_Customer_Model_Resource_Setup
/**
* Prepare customer attribute values to save in additional table
*
* #param array $attr
* #return array
*/
protected function _prepareValues($attr)
{
$data = parent::_prepareValues($attr);
$data = array_merge($data, array(
'is_visible' => $this->_getValue($attr, 'visible', 1),
'is_system' => $this->_getValue($attr, 'system', 1),
'input_filter' => $this->_getValue($attr, 'input_filter', null),
'multiline_count' => $this->_getValue($attr, 'multiline_count', 0),
'validate_rules' => $this->_getValue($attr, 'validate_rules', null),
'data_model' => $this->_getValue($attr, 'data', null),
'sort_order' => $this->_getValue($attr, 'position', 0)
));
return $data;
}
You can create a new upgrade.php in your app/local/NAMESPACE/NAME/sql/NAME_setup folder with the code below:
<?php
// This installer scripts update a product attribute to Magento programmatically.
$model = Mage::getModel('catalog/resource_eav_attribute');
$model->loadByCode(4, 'color');
// Create attribute:
// We create a new installer class here so we can also use this snippet in a non-EAV setup script.
$installer = Mage::getResourceModel('catalog/setup', 'catalog_setup');
$installer->startSetup();
if ($model) {
$model->setPosition(3)
->save();
}
// Done:
$installer->endSetup();
And don't forget to update config.xml in app/local/NAMESPACE/NAME/etc/
folder with the code below:
<config>
<modules>
<Namespace_Name>
<version>0.0.2</version>
</Namespace_Name>
</modules>
<global>
<resources>
<name_setup>
<setup>
<module>Namespace_Name</module>
</setup>
</name_setup>
</resources>
</global>
</config>

Pass arguments to a view in Drupal 6 via custom module

I'm using Drupal 6 to run a gallery I've created. I need to take a parameter from the AJAX request lets say "food" and pass that argument to a view I've created (Views 2) where "food" is a taxonomy term that I am using to get the data I want in return. Everything is working just fine and in my module's method for loading the view I can load the entire view because in the settings you have 'if no argument get all values', but I can't seem to pass arguments to it. Here is the method...
function ajax_methods_menu()
{
$items = array();
$items['admin/settings/ajax_methods'] = array(
'title' => t('AJAX Methods settings.'),
'description' => t('Define settings for the AJAX Methods'),
'page callback' => 'drupal_get_form',
'page arguments' => array('ajax_methods_admin'),
'access arguments' => array('access administration pages'),
'type' => MENU_NORMAL_ITEM
);
$items['gateway'] = array(
'title' => 'AJAX Gateway',
'page callback' => 'ajax_methods_get_items',
'type' => MENU_CALLBACK,
'access arguments' => array('access content')
);
return $items;
}
function ajax_methods_get_items($args)
{
$content = views_get_view('All_Images');
return drupal_json(array('status' => 0, 'data' => $content->preview('default')));
exit;
}
In looking at the documentation views_get_view() doesn't seem to allow for arguments although I believe they are being passed to my ajax_methods_get_items() method. Thanks for reading!
Got it figured out, I needed to add
return arg(1);
seems to be working pretty well.

Drupal Profile alter: hook_form_alter

After reviewing some posts here and elsewhere, I still can't seem to manually add a select field to the profile. (I need the select list to be populated with a SQL query, not supported with core profile module.)
So far, I am trying two different ways: hook form alter ($form_id == 'user-register' & hook user ($op == 'register') -- but I can't even get the field to appear in the registration form.
function accountselect_user($op, &$edit, &$account, $category = NULL) {
if ($op == 'register'){
$fields['account_select'] = array(
'#type' => 'fieldset',
'#title' => t('Your Security Question')
);
$fields['account_select']['account_name'] = array(
'#type' => 'select',
'#default_value' => 'Select',
'#description' => t('Select a verification question in case you forget your password'),
'#options' => array(t('Select One'),
t('Where you attended Elementry School'), t('Your Best Man'))
);
return $fields;
}
Here is the hook form alter attempt
function accountselect_form_alter(&$form, $form_state, $form_id){
if($form_id == 'user-register') {
$form['account_select']['account_name'] = array(
'#type' => 'select',
'#title' => t('Account'),
'#description' => t('Enter the account to which the contact belongs.'),
'#options' => array(t('Account1'),t('account2'), t('account3')),
'#default_value' => $edit ['Account']
);
}
return $fields;
}
Sorry Guys, the code here is correct. I did a little debugging when the module was first enabled. I thought I had successfully fixed the problem, but what really happened is that the module became disabled. So, no matter what was in there, it would have had no effect....
No worries, I've punched myself in the face for the stupid question....

Resources