Drupal

Unlimited cardinality pre-populate fields

I am trying to solve this and my only issue is that I want to keep this field as unlimited cardinality with fields in Field Collection already displayed to the user when they create the other reference node. function module_form_alter(&$form, &$form_state, $form_id) { if($form_id == ‘form_name’) { $reference_query = new EntityFieldQuery(); $reference_query->entityCondition(’entity_type’, ‘node’) ->entityCondition(’bundle’, ‘reference’) ->propertyOrderBy(’created’, ‘DESC’) ->range(0, 1); $reference_result = $reference_query->execute(); $reference_nid = array_keys($reference_result[’node’]); $reference_refer = node_load($reference_nid);   $items_count = count($reference_refer->field_field_name[’und’]); $field_name = ‘field_field_name’; $form_theme = $form[$field_name][’und’][’#theme’]; // Remove delete and add more buttons $form[$field_name][’und’][0][’remove_button’][’#access’] = FALSE; $form[$field_name][’und’][’add_more’][’#access’] = FALSE; $items = &$form_state[’field’][$field_name][’und’];   if ($items_count > 1 and $items[’items_count’] != $items_count) { $items[’items_count’] = $items_count; $items[’field’][’cardinality’] = $items_count; […]

Tags:

Posted in Drupal | Comments Off on Unlimited cardinality pre-populate fields

Drupal Views tutorials

Views getting started Web Developer Looks at Drupal Views: Power and Flexibility from www.htmlgoodies.com Using Drupal 6 Views To Create Offset Recent Posts from www.glennburks.com Creating a CCK and Views powered Drupal site from www.davidnewkerk.com Using Views 2 in Drupal 6 to replace the Tracker module from davidherron.com Tutorial: Simple news view with drupal from www.webdo.me Create administration pages with Views 2 from zugec.com How to create a simple news archive in Drupal from drupalsn.com Alphabetical Sorting of Drupal Nodes Using Views from www.ostraining.com Views Theming Rewriting Drupal Views Output for Custom Theming & CSS from highrockmedia.com Theming Views 2 – The Basics from group42.ca Drupal 6: How to quickly theme a view ? from stackoverflow.com Drupal views theming – rows in tables from www.maybeor.com Theming Views on Drupal 6 (the simple way) from www.appnovation.com Theming […]

Posted in Drupal | Comments Off on Drupal Views tutorials

Search in Chinese / Japanese

in search.module change $keys = str_replace(“*”, “%”, $keys); to $keys = ‘%’.str_replace(“*”, “%”, $keys).’%’;

Posted in Drupal | No Comments »

Feeds Node Processor

Allow User Name and Email case ‘user_name’: if ($user = user_load_by_name($value)) { $target_node->uid = $user->uid; } break; case ‘user_mail’: if ($user = user_load_by_mail($value)) { $target_node->uid = $user->uid; } break;case ‘user_name’: if ($user = user_load_by_name($value)) { $target_node->uid = $user->uid; } break; case ‘user_mail’: if ($user = user_load_by_mail($value)) { $target_node->uid = $user->uid; } break; public function getMappingTargets() { $targets[’user_name’] = array( ‘name’ => t(’LID’), ‘description’ => t(’The Drupal LID of the node author.’), ); $targets[’user_mail’] = array( ‘name’ => t(’User email’), ‘description’ => t(’The Drupal email address of the node author.’), );public function getMappingTargets() { $targets[‘user_name’] = array( ‘name’ => t(‘LID’), ‘description’ => t(‘The Drupal LID of the node author.’), ); $targets[‘user_mail’] […]

Posted in Drupal | Comments Off on Feeds Node Processor

Feeds User Processor

protected function entitySave($account) { if ($this->config[’defuse_mail’]) { $account->mail = $account->mail . ‘_test’; } $account->roles = $account->roles + array_filter($this->config[’roles’]); //bikim user_save($account, (array) $account); if ($account->uid && !empty($account->openid)) { $authmap = array( ‘uid’ => $account->uid, ‘module’ => ‘openid’, ‘authname’ => $account->openid, ); if (SAVED_UPDATED != drupal_write_record(’authmap’, $authmap, array(’uid’, ‘module’))) { drupal_write_record(’authmap’, $authmap); } } } protected function entitySave($account) { if ($this->config[‘defuse_mail’]) { $account->mail = $account->mail . ‘_test’; } $account->roles = $account->roles + array_filter($this->config[‘roles’]); //bikim user_save($account, (array) $account); if ($account->uid && !empty($account->openid)) { $authmap = array( ‘uid’ => $account->uid, ‘module’ => ‘openid’, ‘authname’ => $account->openid, ); if (SAVED_UPDATED != drupal_write_record(‘authmap’, $authmap, array(‘uid’, ‘module’))) { drupal_write_record(‘authmap’, $authmap); } } } protected function entityLoad(FeedsSource $source, […]

Posted in Drupal | Comments Off on Feeds User Processor

Create augmentative user id

email_registration.module if (empty($names)) { $new_name = ‘CUSTOM-NUMBER-FOR-USER-ID’; if ((bool) db_query("SELECT 1 FROM {users} WHERE uid <> :uid AND LOWER(name) = LOWER(:new_name)", array(’:uid’ => $account->uid, ‘:new_name’ => $new_name))->fetchField()) { $name_idx = db_query_range("SELECT SUBSTRING_INDEX(name,’X’,-1) FROM {users} WHERE name REGEXP :search ORDER BY CAST(SUBSTRING_INDEX(name,’X’,-1) AS UNSIGNED) DESC", 0, 1, array(’:search’ => ‘^’ . $new_name . ‘[0-9]+$’))->fetchField(); $new_name .= sprintf(’%010u’,($name_idx + 1)); } }if (empty($names)) { $new_name = ‘CUSTOM-NUMBER-FOR-USER-ID’; if ((bool) db_query("SELECT 1 FROM {users} WHERE uid <> :uid AND LOWER(name) = LOWER(:new_name)", array(‘:uid’ => $account->uid, ‘:new_name’ => $new_name))->fetchField()) { $name_idx = db_query_range("SELECT SUBSTRING_INDEX(name,’X’,-1) FROM {users} WHERE name REGEXP :search ORDER BY CAST(SUBSTRING_INDEX(name,’X’,-1) AS UNSIGNED) DESC", 0, 1, array(‘:search’ => ‘^’ . $new_name . […]

Posted in Drupal | No Comments »

User Custom Field in Node

Case[Node] node.tpl.php $node_author = user_load($node->uid); $user_lid = field_get_items(’user’, $node_author, ‘field_user_id’); $user_photo = field_get_items(’user’, $node_author, ‘field_user_photo’);$node_author = user_load($node->uid); $user_lid = field_get_items(‘user’, $node_author, ‘field_user_id’); $user_photo = field_get_items(‘user’, $node_author, ‘field_user_photo’); <div class="node-photo"> <?php if ($user_photo): ?> <img src="<?php print image_style_url(’50×50′, $user_photo[0][‘uri’]); ?>" /> <?php endif; ?> </div><div class="node-photo"> <?php if ($user_photo): ?> <img src="<?php print image_style_url(’50×50′, $user_photo[0][‘uri’]); ?>" /> <?php endif; ?> </div> <div class="node-lid"> <?php render($user_lid[0][‘value’]) ?> </div><div class="node-lid"> <?php render($user_lid[0][‘value’]) ?> </div> Case[Comment] comment.tpl.php $comment_author = user_load($comment->uid); $user_lid = field_get_items(’user’, $comment_author, ‘field_user_id’); $user_photo = field_get_items(’user’, $comment_author, ‘field_user_photo’);$comment_author = user_load($comment->uid); $user_lid = field_get_items(‘user’, $comment_author, ‘field_user_id’); $user_photo = field_get_items(‘user’, $comment_author, ‘field_user_photo’); <div class="comment-photo"> <div class="comment-photo"> <?php if ($user_photo): ?> <img src="<?php print image_style_url(’50×50′, […]

Posted in Drupal | Comments Off on User Custom Field in Node