Drupal 7

Программно переводим ноды


$nodes->title_field[$lang][0]['value'] = $translate_node_title;

$handler = entity_translation_get_handler('node', $nodes);

$translation = array(
'translate' => 0,
'status' => 1,
'language' => $new_lang_second,
'source' => $nodes->language,
);

$handler->setTranslation($translation, $nodes);

node_save($nodes);

The code has been tested and works

Запуск Batch операций по cron в фоне

Для того что бы запустить batch операцию в фоновом режиме по крону:

function MY_MODULE_cron() {
// функция пакетной операции, любое название
MY_MODULE_unprogressive_batch();
}

The code has been tested and works

Передаем аргументы в форму drupal7

drupal_get_form('mymodule_form',$arg_first,$arg_second);

function mymodule_form($form,&$form_state,$arg_first,$arg_second){

$form['mymodule_xxx'] = array(
'#title' => $arg_first,
'#type' => 'checkboxes',
'#options' => array_keys($arg_second),
'#attributes' => array('class' => array('ctools-auto-submit')),

);

The code has been tested and works

Кешируем данные drupal

//Cache query node types
$cache_key = 'name_key_xxx';
$cache_value = cache_get($cache_key);

if (!empty($cache_value)){
$data = $cache_value->data;
}
else{
$query = db_query("SELECT *
FROM node;");
foreach ($query as $key => $row){
$nodes[] => $row->nid;
}

}
cache_set($cache_key, $data, 'cache', REQUEST_TIME + 60 * 60*24);

The code has been tested and works

Связать commerce product с нодой програмно

function commerce_display_product_create_method($product){
$node = new stdClass();
$node->type = 'product_display';
node_object_prepare($node);

$node->title = $product->title;
$node->language = LANGUAGE_NONE;

$node->field_product['und'][0]['product_id'] = $product->product_id;
node_save($node);
}

The code has been tested and works

Добавляем исчезающий текст в форму Drupal7

/**
* Implements hook_form_FORM_ID_alter(): search_block_form.
*/
function THEMENAME_form_search_block_form_alter(&$form, &$form_state) {
$form['search_block_form']['#attributes']['placeholder'] = 'Поиск по сайту';
}

The code has been tested and works

Getting the node ID of a page making a $.post request

function mymodule_node_view($node, $view_mode, $langcode) {
if ($view_mode == 'full') {
$setting = array('mymodule' => array('currentNid' => $node->nid));
drupal_add_js($setting, 'setting');
}
}


Then on the client side you'll have access to it through Drupal.settings:

var currentNid = Drupal.settings.MYMODULE.currentNid;

The code has been tested and works

Pages

Subscribe to RSS - Drupal 7