Drupal Profile alter: hook_form_alter - drupal-6

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....

Related

How to apply extension hook in expressionengine

I'm working on expressionengine v2 and i have followed the docs at their site to make extension hooks, i've created a file in third party folder and install that from cp(control panel). Now i don't know how to call that function using hook just to show some text.
$hooks = array(
'after_channel_entry_insert' => 'after_channel_entry_insert',
'before_channel_entry_update' => 'before_channel_entry_update'
);
foreach ($hooks as $hook_name => $method_name) {
$data[] = array(
'class' => __CLASS__,
'method' => $method_name,
'hook' => $hook_name,
'settings' => serialize($this->settings),
'priority' => 10,
'version' => $this->version,
'enabled' => 'y'
);
}
//insert data in extension table
ee()->db->insert_batch('extensions', $data);
//now i want to call this function on hook
function after_channel_entry_insert($data = '') {
die('after_channel_entry_insert');
}

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;
}

Restrict sonata_type_model_list to 1 context

I am trying to allow users to select from existing images in the system and have context set like the provided example and this works. How can I stop the users from selecting from any other context type?
$form->add('image', 'sonata_type_model_list', array(), array('link_parameters' => array('context' => 'news')))
Not tested but I just stumbled over the parameter: hide_context
$form->add('image', 'sonata_type_model_list', array(), array(
'link_parameters' => array(
'context' => 'news',
'hide_context' => true
)
))
Maybe you want to give it a try?

Magento - custom product option don't show in order

I'm try to add custom option to product programmatically whyle add him to cart. I'm use:
$a_options = array(
'options' => array(
'label' => 'Glove Size',
'value' => $attr_value ,
)
);
$item->addOption(new Varien_Object(
array(
'product' => $item->getProduct(),
'code' => 'additional_options',
'value' => serialize($a_options)
)
));
$quote->addItem($item);
This is shows option for product in cart and during checkout process, but don't show option in order information.
I also tried:
$item->getProduct()->addCustomOption('additional_options', $attr_value );
Try to show them via attributes - didn't help.
$params = array('product' => '1919','qty' => 1,
'options' => array(
'glove_size' => $gloves_id,
),);
$cart->addProduct('1919', $params);
Magento version is 1.5
I haven't check that in 1.5 version but the below code will work in 1.7.2 version:
For viewing the custom options you need set options in order items.That can be done through by calling an event sales_convert_quote_item_to_order_item
<sales_convert_quote_item_to_order_item>
<observers>
<jrb_setcustomoption_observer>
<type>singleton</type>
<class>jrb_setcustomoption/observer</class>
<method>salesConvertQuoteItemToOrderItem</method>
</jrb_setcustomoption_observer>
</observers>
</sales_convert_quote_item_to_order_item>
Set the details options in your observer
public function salesConvertQuoteItemToOrderItem(Varien_Event_Observer $observer)
{
$quoteItem = $observer->getItem();
if ($additionalOptions = $quoteItem->getOptionByCode('additional_options')) {
$orderItem = $observer->getOrderItem();
$options = $orderItem->getProductOptions();
$options['additional_options'] = unserialize($additionalOptions->getValue());
$orderItem->setProductOptions($options);
}
}
For More details you can find in this article:
Magento - custom product option don't show in order
Thanks to Vinai

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.

Resources