protected function completeCSVertical()
 {
     $order_line = field_get_items('commerce_order', $this->datasources["order"], 'commerce_line_items');
     $line_item_ids[] = $order_line[0]['line_item_id'];
     $line_item = commerce_line_item_load_multiple($line_item_ids);
     $product_ids = array();
     $tmp = field_get_items('commerce_line_item', $line_item[0], 'commerce_product');
     $product_ids[] = $tmp[0]['product_id'];
     $products = commerce_product_load_multiple($product_ids);
     $item = $products[0];
     if (property_exists($item, "csmdd32")) {
         $datosCS["CSMDD32"] = $item->csmdd32[LANGUAGE_NONE][0]["value"];
     }
     return array_merge($this->getMultipleProductsInfo(), $datosCS);
 }
 protected function getMultipleProductsInfo()
 {
     $order_lines = field_get_items('commerce_order', $this->datasources["order"], 'commerce_line_items');
     $line_item_ids = array();
     foreach ($order_lines as $order_line) {
         $line_item_ids[] = $order_line['line_item_id'];
     }
     $line_items = commerce_line_item_load_multiple($line_item_ids);
     $product_ids = array();
     $cant_prod = array();
     foreach ($line_items as $line_item) {
         $tmp = field_get_items('commerce_line_item', $line_item, 'commerce_product');
         $cant_prod[$tmp[0]['product_id']] = round($line_item->quantity);
         $product_ids[] = $tmp[0]['product_id'];
     }
     $products = commerce_product_load_multiple($product_ids);
     $code = array();
     $description = array();
     $name = array();
     $sku = array();
     $total = array();
     $quantity = array();
     $unit = array();
     foreach ($products as $item) {
         $code[] = $this->getCategoryArray($item);
         if (!empty($item->description)) {
             $desc = $item->description;
         } else {
             $desc = $item->title;
         }
         $desc = strip_tags($desc);
         $desc = TodoPago\Sdk::sanitizeValue($desc);
         $desc = substr($desc, 0, 50);
         $description[] = $desc;
         $name[] = substr($item->title, 0, 250);
         $sku[] = substr(empty($item->sku) ? $item->product_id : $item->sku, 0, 250);
         $total[] = number_format(commerce_currency_amount_to_decimal($item->commerce_price[LANGUAGE_NONE][0]["amount"], $item->commerce_price[LANGUAGE_NONE][0]["currency_code"]) * $cant_prod[$item->product_id], 2, ".", "");
         $quantity[] = $cant_prod[$item->product_id];
         $unit[] = number_format(commerce_currency_amount_to_decimal($item->commerce_price[LANGUAGE_NONE][0]["amount"], $item->commerce_price[LANGUAGE_NONE][0]["currency_code"]), 2, ".", "");
     }
     $productsData = array('CSITPRODUCTCODE' => join("#", $code), 'CSITPRODUCTDESCRIPTION' => join("#", $description), 'CSITPRODUCTNAME' => join("#", $name), 'CSITPRODUCTSKU' => join("#", $sku), 'CSITTOTALAMOUNT' => join("#", $total), 'CSITQUANTITY' => join("#", $quantity), 'CSITUNITPRICE' => join("#", $unit));
     return $productsData;
 }
Esempio n. 3
0
/**
 * Override or insert variables into the node template.
 */
function jeugdwerksupport_preprocess_node(&$variables)
{
    $node = $variables['node'];
    // Add template suggestions
    if (!$variables['page']) {
        if ($variables['teaser']) {
            $variables['theme_hook_suggestions'][] = 'node__' . $variables['node']->type . '__teaser';
            $variables['theme_hook_suggestions'][] = 'node__' . $variables['node']->nid . '__teaser';
            $variables['theme_hook_suggestions'][] = 'node__teaser';
        }
    }
    // Add class 'node-full'
    if ($variables['view_mode'] == 'full' && node_is_page($node)) {
        $variables['classes_array'][] = 'node-full';
    }
    // Set custom date format
    $variables['date'] = format_date($node->created, 'custom', 'F jS Y');
    // Add summary variable
    if ($variables['view_mode'] == 'full') {
        $items = field_get_items('node', $node, 'body', $node->language);
        if ($items) {
            // If there's a single summary, just set the summary variable
            if (count($items) == 1) {
                $variables['summary'] = $items[0]['summary'];
            } else {
                foreach ($items as $item) {
                    $variables['summary'][] = $item['summary'];
                }
            }
        }
    }
}
Esempio n. 4
0
function gavias_laikafood_format_comma_field($field_category, $node, $limit = NULL)
{
    if (module_exists('i18n_taxonomy')) {
        $language = i18n_language();
    }
    $category_arr = array();
    $category = '';
    $field = field_get_items('node', $node, $field_category);
    if (!empty($field)) {
        foreach ($field as $item) {
            $term = taxonomy_term_load($item['tid']);
            if ($term) {
                if (module_exists('i18n_taxonomy')) {
                    $term_name = i18n_taxonomy_term_name($term, $language->language);
                    // $term_desc = tagclouds_i18n_taxonomy_term_description($term, $language->language);
                } else {
                    $term_name = $term->name;
                    //$term_desc = $term->description;
                }
                $category_arr[] = l($term_name, 'taxonomy/term/' . $item['tid']);
            }
            if ($limit) {
                if (count($category_arr) == $limit) {
                    $category = implode(', ', $category_arr);
                    return $category;
                }
            }
        }
    }
    $category = implode(', ', $category_arr);
    return $category;
}
Esempio n. 5
0
 /**
  * {@inheritdoc}
  */
 function entityFindCandidate($entity, $entity_type, $distinction_key)
 {
     $items = field_get_items($entity_type, $entity, $this->fieldKey);
     if (is_array($items) && !empty($items)) {
         return $this->fieldFindCandidate($items);
     }
 }
 protected function queryLoad($ids)
 {
     $multifields = multifield_get_fields();
     foreach (array_keys($multifields) as $field_name) {
         $query = new EntityFieldQuery();
         if ($ids) {
             $query->fieldCondition($field_name, 'id', $ids, 'IN');
         } else {
             $query->fieldCondition($field_name, 'id', 0, '>');
         }
         if ($results = $query->execute()) {
             $pseudo_entities = array();
             $field = field_info_field($field_name);
             foreach ($results as $entity_type => $entities) {
                 // Simply doing an entity load on the entities with multifield values
                 // will cause the cacheSet() from multifield_field_load() to get
                 // invoked.
                 $entities = entity_load($entity_type, array_keys($entities));
                 foreach ($entities as $entity) {
                     if ($items = field_get_items($entity_type, $entity, $field_name)) {
                         foreach ($items as $item) {
                             $pseudo_entities[$item['id']] = _multifield_field_item_to_entity($field['type'], $item);
                         }
                     }
                 }
             }
             $this->cacheSet($pseudo_entities);
         }
     }
     return array_intersect_key($this->entityCache, drupal_map_assoc($ids, $ids));
 }
Esempio n. 7
0
function ns_theme_dynamic_formatters_style($variables)
{
    $output = '<div class="dynamic-formatters-group promo-group clearfix">';
    $i = 0;
    foreach ($variables['rows'] as $id => $row) {
        $additional = $variables['view']->result[$id]->additional_info;
        if (isset($additional['requiredcontext_entity:taxonomy_term_2'])) {
            $term = $additional['requiredcontext_entity:taxonomy_term_2']->data;
            $width = field_get_items('taxonomy_term', $term, 'field_ns_ch_web_width');
            $width = $width[0]['value'];
            $grid = '';
            $no_margin = '';
            if ($i > 0) {
                $grid = 'grid-' . intval($width / 2);
                if ($i % 2 == 0) {
                    $no_margin = 'omega';
                } else {
                    $no_margin = 'alpha';
                }
            }
        }
        $output .= '<div class="promo promo-' . $i . ' ' . $grid . ' ' . $no_margin . ' clearfix">' . $row . '</div>';
        $i++;
    }
    return $output . '</div>';
}
Esempio n. 8
0
function getRelatedPosts($ntype, $nid)
{
    $nids = db_query("SELECT n.nid, title FROM {node} n WHERE n.status = 1 AND n.type = :type AND n.nid <> :nid ORDER BY RAND() LIMIT 0,2", array(':type' => $ntype, ':nid' => $nid))->fetchCol();
    $nodes = node_load_multiple($nids);
    $return_string = '';
    if (!empty($nodes)) {
        foreach ($nodes as $node) {
            $field_image = field_get_items('node', $node, 'field_image_blog');
            $return_string .= '<li class="item content-in col-md-6"><div class="widget-post-wrap">';
            $return_string .= '<div class="thumb"><a href="' . url("node/" . $node->nid) . '">';
            $return_string .= '<img src="' . file_create_url($node->field_image['und'][0]['uri']) . '" alt="' . $node->title . '">';
            $return_string .= '</a></div>';
            $return_string .= '<div class="article-content-wrap">';
            $return_string .= '<h4 class="title"><a href="' . url("node/" . $node->nid) . '">';
            $return_string .= $node->title . '</a></h4>';
            $return_string .= '<div class="excerpt">' . substr($node->body['und'][0]['value'], 0, 100) . '...' . '</div>';
            $return_string .= '<div class="meta-bottom">';
            /*			$return_string .= '<div class="post-cat"><span><i class="fa fa-folder"></i></span>'.strip_tags(render($content['field_blog_category']),'<a>').'</div>';*/
            $return_string .= '<div class="post-date"><span><i class="fa fa-clock-o"></i></span>' . format_date($node->created, 'custom', 'M j,Y') . '</div>';
            $return_string .= '<div class="meta-comment"><span><i class="fa fa-comments-o"></i></span><a href="' . url("node/" . $node->nid) . '">' . $node->comment_count . '</a></div>';
            $return_string .= '</div></div>';
            $return_string .= '<a class="bk-cover-link" href="' . url("node/" . $node->nid) . '"></a></div>';
            $return_string .= '</li>';
        }
    }
    return $return_string;
}
Esempio n. 9
0
function jollyness_format_comma_field($field_category, $node, $limit = NULL)
{
    $category_arr = array();
    $field = field_get_items('node', $node, $field_category);
    if (!empty($field)) {
        foreach ($field as $item) {
            $term = taxonomy_term_load($item['tid']);
            if ($term) {
                if (module_exists('i18n_taxonomy')) {
                    $term_name = i18n_taxonomy_term_name($term, $node->language);
                } else {
                    $term_name = $term->name;
                }
                $category_arr[] = l($term_name, 'taxonomy/term/' . $item['tid']);
            }
            if ($limit) {
                if (count($category_arr) == $limit) {
                    $category = implode(', ', $category_arr);
                    return $category;
                }
            }
        }
    }
    $category = implode(', ', $category_arr);
    return $category;
}
Esempio n. 10
0
function noreg_preprocess_node__sale_ad(&$variables)
{
    // All node types but page
    if ($variables['elements']['#view_mode'] != 'page') {
        // Litter
        if ($field_litter = field_get_items('node', $variables['node'], 'field_litter_id')) {
            $node_litter = node_load($field_litter[0]['target_id']);
            // Birthdate
            if ($field_litter_birthdate = field_get_items('node', $node_litter, 'field_birthdate')) {
                $variables['litter_birthdate'] = field_view_value('node', $node_litter, 'field_birthdate', $field_litter_birthdate[0], array('settings' => array('format_type' => 'custom_short')));
            }
            // Price per young
            if ($field_litter_price_per_young = field_get_items('node', $node_litter, 'field_price_per_young')) {
                $variables['litter_price_per_young'] = field_view_value('node', $node_litter, 'field_price_per_young', $field_litter_price_per_young[0]);
            }
            // Animal
            if ($field_animal = field_get_items('node', $node_litter, 'field_animal_id')) {
                $node_animal = node_load($field_animal[0]['target_id']);
                // Breed
                if ($field_breed = field_get_items('node', $node_animal, 'field_breed_id')) {
                    $variables['animal_breed'] = field_view_value('node', $node_animal, 'field_breed_id', $field_breed[0]);
                }
            }
        }
        // User
        if ($node_creator = ha_user_get_raw_information($variables['user']->uid)) {
            // Location
            if (isset($node_creator['location'])) {
                $variables['user_location'] = $node_creator['location'];
            }
        }
    }
}
 /**
  * Implements EditMetadataGeneratorInterface::generate().
  */
 public function generate($entity_type, $entity, array $instance, $langcode, $view_mode)
 {
     $field_name = $instance['field_name'];
     // Early-return if user does not have access.
     $access = $this->accessChecker->accessEditEntityField($entity_type, $entity, $field_name);
     if (!$access) {
         return array('access' => FALSE);
     }
     // Early-return if no editor is available.
     if (!_edit_is_extra_field($entity_type, $field_name)) {
         $display = field_get_display($instance, $view_mode, $entity);
         $formatter_type = field_info_formatter_types($display['type']);
         $items = field_get_items($entity_type, $entity, $field_name, $langcode);
         $items = $items === FALSE ? array() : $items;
         $editor_id = $this->editorSelector->getEditor($formatter_type, $instance, $items);
     } else {
         // @see hook_edit_extra_fields_info()
         $extra = edit_extra_field_info($entity_type, $field_name);
         if (isset($extra['view mode dependent editor'][$view_mode])) {
             $editor_id = $extra['view mode dependent editor'][$view_mode];
         } else {
             $editor_id = $extra['default editor'];
         }
     }
     if (!isset($editor_id)) {
         return array('access' => FALSE);
     }
     // Gather metadata, allow the editor to add additional metadata of its own.
     if (!_edit_is_extra_field($entity_type, $field_name)) {
         $label = $instance['label'];
     } else {
         $label = edit_extra_field_info($entity_type, $field_name, 'label');
     }
     list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
     $metadata = array('label' => check_plain($label), 'access' => TRUE, 'editor' => $editor_id, 'aria' => t('Entity @type @id, field @field', array('@type' => $entity_type, '@id' => $id, '@field' => $label)));
     if (!_edit_is_extra_field($entity_type, $field_name)) {
         $editor = edit_editor_get($editor_id);
         if (!empty($editor['metadata callback'])) {
             if ($editor['file']) {
                 require_once $editor['file path'] . '/' . $editor['file'];
             }
             if (function_exists($editor['metadata callback'])) {
                 $custom_metadata = $editor['metadata callback']($instance, $items);
                 if (count($custom_metadata)) {
                     $metadata['custom'] = $custom_metadata;
                 }
             }
         }
         // Allow the metadata to be altered.
         $context = array('entity_type' => $entity_type, 'entity' => $entity, 'field' => $instance, 'items' => $items);
         drupal_alter('edit_editor_metadata', $metadata, $editor_id, $context);
     }
     return $metadata;
 }
Esempio n. 12
0
function ssd_preprocess_node(&$variables)
{
    $node = $variables['node'];
    $variables['title'] = check_plain($node->title);
    if ($node->type == 'article') {
        // Get only the first body summary for a module.
        $body = field_get_items('node', $node, 'body');
        $variables['summary'] = field_view_value('node', $node, 'body', $body[0], 'teaser');
        $variables['metadata'] = field_view_field('node', $node, 'field_metadata', 'default');
    }
}
 public function fieldView($node, $field, $view_mode = 'default')
 {
     if (!$node instanceof NodeInterface) {
         return '';
     }
     if (!field_get_items('node', $node, $field)) {
         return '';
     }
     $output = field_view_field('node', $node, $field, $view_mode);
     return drupal_render($output);
 }
Esempio n. 14
0
function fj16_preprocess_node(&$vars)
{
    if ($vars['node']->type !== 'fj16_news_article') {
        return;
    }
    $user = user_load($vars['node']->uid);
    if ($user && $user->uid !== 0) {
        $name = field_get_items('user', $user, 'field_name')[0]['value'];
        $vars['user_realname'] = check_plain($name);
    }
}
Esempio n. 15
0
 public function field_view_values($entity_type, $entity, $field_name, $display = array(), $langcode = NULL)
 {
     $items = field_get_items($entity_type, $entity, $field_name);
     if ($items) {
         $output = array();
         foreach ($items as $item) {
             $output[] = field_view_value($entity_type, $entity, $field_name, $item, $display, $langcode);
         }
         return $output;
     }
 }
 /**
  * Implements Drupal_RichSnippets_SchemaPreprocessorAbstract::getSchemaFields().
  */
 public function getSchemaFields($schema)
 {
     $schema_fields = array();
     $rdf_mappings = rich_snippets_get_rdf_schema_mappings($this->_entityType, $this->_bundle);
     if (!empty($rdf_mappings[$schema])) {
         foreach ($rdf_mappings[$schema] as $field_name) {
             $items = field_get_items($this->_entityType, $this->_entity, $field_name);
             $schema_fields[$field_name] = $items ? $items : array();
         }
     }
     return $schema_fields;
 }
/**
 * Notification to modules that a goal is completed.
 *
 * @param int $goal_id
 *   Goal being completed.
 * @param int $uid
 *   UserID of user completing the goal.
 */
function hook_goals_completed_goal($goal_id, $uid)
{
    if (field_info_instance('goal', 'goal_userpoints', 'goal_bundle') && function_exists('userpoints_userpointsapi')) {
        $goals = entity_load('goal', array($goal_id));
        $goal = $goals[$goal_id];
        $point_array = field_get_items('goal', $goal, 'goal_userpoints');
        $points = $point_array[0]['value'];
        if ($points) {
            $params = array('uid' => $uid, 'points' => $points, 'description' => t('Goal @goal completed.', array('@goal' => $goal->title)));
            userpoints_userpointsapi($params);
        }
    }
}
/**
 * Modify an event's raw data.
 *
 * This hook is invoked after Date iCal has gathered all the data it will use
 * to build an event object.
 *
 * @param array $event
 *   A reference to an associative array containing the event's raw data.
 * @param object $view
 *   The view object that is being executed to render the iCal feed.
 * @param array $context
 *   Depending on whether this event is being constructed using the Fields or
 *   Entity plugins, this context array will have different keys and values.
 *
 *   Entity Plugin:
 *   - 'entity_type': The type of entity being rendered (e.g. 'node').
 *   - 'entity': The fully loaded entity being rendered.
 *   - 'language': The language code that indicates which translation of field
 *     data should be used.
 *
 *   Fields Plugin:
 *   - 'row': The full Views row object being converted to an event.
 *   - 'row_index': The index into the query results for this view.
 *   - 'language': The language code that indicates which translation of field
 *     data should be used.
 *   - 'options': The Fields plugin options.
 */
function hook_date_ical_export_raw_event_alter(&$event, $view, $context)
{
    // Example: adding a comment to an event from a simple
    // textfield called 'field_comment' (using the Entity plugin).
    if ($comments = field_get_items($context['entity_type'], $context['entity'], 'field_comment', $context['language'])) {
        foreach ($comments as $comment) {
            $event['comment'] = check_plain($comment['value']);
        }
    }
    // Example: Retrieving information from additional fields in the View (using
    // the Fields plugin).
    $event['comment'] = $view->style_plugin->get_field($context['row_index'], 'field_comment');
}
Esempio n. 19
0
 /**
  * {@inheritdoc}
  *
  * @todo Update to new query API.
  */
 public function match(ContactInterface $contact, $property = 'value')
 {
     $results = array();
     $field_item = 'value';
     $field = field_get_items('crm_core_contact', $contact, $rule->field_name);
     $needle = isset($field[0]['value']) ? $field[0]['value'] : '';
     if (!empty($needle)) {
         $query = new EntityFieldQuery();
         $query->entityCondition('entity_type', 'crm_core_contact')->entityCondition('bundle', $contact->type)->entityCondition('entity_id', $contact->contact_id, '<>')->fieldCondition($rule->field_name, $field_item, $needle, $rule->operator);
         $results = $query->execute();
     }
     return isset($results['crm_core_contact']) ? array_keys($results['crm_core_contact']) : $results;
 }
Esempio n. 20
0
/**
 * Modify a structured event before it is rendered to iCal format.
 *
 * This hook is invoked after the Date iCal module has generated its
 * representation of the event and allows you to modify or add to the
 * representation. Use this hook to set values of iCal fields that are supported
 * but have no values mapped into them by default.
 *
 * @param $event
 *   An associative array representation of the iCal event. This will be used by
 *   the Date iCal rendering system to create an entry in an iCal feed.
 * @param $view
 *   The view object that is being executed to render the iCal feed.
 * @param $context
 *   An associative array of context, with the following keys and values:
 *   - 'entity_type': The type of entity being rendered, 'node', 'user' etc.
 *   - 'entity': The fully loaded entity being rendered.
 *   - 'language': The language code that indicates which translation of field
 *     data should be used.
 */
function hook_date_ical_feed_event_render_alter(&$event, $view, $context)
{
    // Simple example adding the location to a rendered event from a simple
    // textfield called 'field_location'.
    $entity_type = $context['entity_type'];
    $entity = $context['entity'];
    $language = $context['language'];
    if ($locations = field_get_items($entity_type, $entity, 'field_location', $language)) {
        foreach ($locations as $location) {
            $event['location'] = check_plain($location['value']);
        }
    }
}
/**
 * Implements hook_commerce_node_checkout_line_item_alter
 *
 * Allows modules to interact with the line item to be added to the cart
 * before it is saved. Modules can't use hook_commerce_line_item_alter or
 * other entity alter functions because they don't have the $node object or
 * the associated (selected) product in scope which this hook does.
 *
 * @param object $line_item
 *   The commerce line item about to be added to the cart
 * @param object $product
 *   The commerce product option selection by the node author
 * @param object $node
 *   The node object created by the author
 */
function hook_commerce_node_checkout_line_item_alter(&$line_item, $product, $node)
{
    // Load the interval field from the product.
    $interval = field_get_items('commerce_product', $product, 'commerce_node_checkout_expire');
    if ($interval && !empty($interval['0'])) {
        // We have an expiry field - apply it.
        $due_date_obj = new DateObject('now');
        if (interval_apply_interval($due_date_obj, $interval)) {
            // Update the expiry field on the line item.
            $line_item->commerce_node_checkout_expires[LANGUAGE_NONE][0]['value'] = $due_date_obj->format('U');
        }
    }
}
Esempio n. 22
0
function lt_preprocess_node(&$vars)
{
    $node = $vars['node'];
    if (module_exists('ibtimes_bizutv_field')) {
        $widget_id = variable_get('bizutv_widget_id', '68497');
        //188008
        $field = field_get_items('node', $node, 'field_bizutv_video');
        $video_id = !empty($field[0]['bizutv_nid']) ? $field[0]['bizutv_nid'] : NULL;
        if ($widget_id && $video_id) {
            $vars['bizutv_video'] = theme('ibtimes_bizutv_field_video', array('widget_id' => $widget_id, 'video_id' => $video_id));
        }
    }
    $image_styles = array();
    $vars['image_style'] = 'large';
    switch ($vars['view_mode']) {
        case 'full':
            $image_styles = array('large');
            break;
        case 'teaser':
            $image_styles = array('medium', 'large');
            break;
        case 'featured_teaser':
            $image_styles = array('featured');
            break;
        case 'image_teaser':
            $image_styles = array('small');
            break;
        case 'lead_teaser':
            $image_styles = array('featured');
            break;
        case 'small_teaser':
            $image_styles = array('medium');
            break;
        case 'image_title':
            $image_styles = array('featured');
            break;
        case 'large_sidebar':
            $image_styles = array('thumbnail');
            break;
        case 'sidebar':
            $image_styles = array('thumbnail');
            break;
        case 'sublead':
            $image_styles = array('mini');
            break;
    }
    if (count($image_styles)) {
        ibtmedia_image_node_variables($node, $vars['view_mode'], $vars, $image_styles);
    }
}
 /**
  * Override the sensitivity control to create a simple select with default value 
  * set by user profile.
  */
 protected static function get_control_sensitivity($auth, $args, $tabAlias, $options)
 {
     // Obtain the default value for the user.
     global $user;
     $user = user_load($user->uid);
     $field_values = field_get_items('user', $user, 'field_icpveg_permission');
     $default_value = $field_values[0]['value'];
     if ($default_value == 0) {
         // Where Drupal stores 0, we want the Warehouse field to be NULL to indicate
         // no blurring of detail.
         $default_value = '';
     }
     return data_entry_helper::select(array_merge(array('fieldname' => 'occurrence:sensitivity_precision', 'label' => lang::get('ICPVeg Sensitivity'), 'lookupValues' => array('50000' => lang::get('ICPVeg Sensitivity 50km')), 'blankText' => lang::get('ICPVeg Sensitivity blankText'), 'default' => $default_value), $options));
 }
Esempio n. 24
0
/**
 * Allows to prevent unpublication of a scheduled node.
 *
 * @param object $node
 *   The scheduled node that is about to be unpublished.
 *
 * @return bool
 *   FALSE if the node should not be unpublished. TRUE otherwise.
 */
function hook_scheduler_allow_unpublishing($node)
{
    $allowed = TRUE;
    // Prevent unpublication of competition entries if not all prizes have been
    // claimed.
    if ($node->type == 'competition' && ($items = field_get_items('node', $node, 'field_competition_prizes'))) {
        $allowed = (bool) count($items);
        // If unpublication is denied then inform the user why.
        if (!$allowed) {
            drupal_set_message(t('The competition will only be unpublished after all prizes have been claimed by the winners.'));
        }
    }
    return $allowed;
}
 /**
  * This function is for get reference product from recurring entity
  * @return bool|Recurring
  */
 public function getCommerceRecurringRefProductValues()
 {
     $recurring_entity = $this->getEntity();
     $ref_product = field_get_items('commerce_recurring', $recurring_entity, 'commerce_recurring_ref_product');
     if (!empty($ref_product) && isset($ref_product[0]['target_id'])) {
         $product_id = $ref_product[0]['target_id'];
         $product = commerce_product_load($product_id);
         $product_class = Utils::makeTitleCase($product->type);
         $field_class = "RedTest\\entities\\CommerceProduct\\" . $product_class;
         $product_obj = new $field_class($product_id);
         return new Response(TRUE, $product_obj, "");
     } else {
         return new Response(FALSE, NULL, 'Reference product not available.');
     }
 }
 /**
  * Constructor for the Add to cart form. Provide $nid as the id of the
  * product display node. Other optional arguments are product reference field
  * name, view mode of the product display node and language of the product
  * display node. If optional arguments are not provided, their default values
  * are assumed, which are "field_product", "default" and "en" respectively.
  *
  * @param int $nid
  *   Product display node id.
  */
 public function __construct($nid)
 {
     $args = func_get_args();
     array_shift($args);
     $field_name = array_shift($args);
     $view_mode = array_shift($args);
     $language = array_shift($args);
     if (is_null($field_name)) {
         $field_name = 'field_product';
     }
     if (is_null($view_mode)) {
         $view_mode = 'default';
     }
     if (is_null($language)) {
         $language = 'en';
     }
     $node = node_load($nid);
     $instance = field_info_instance('node', $field_name, $node->type);
     $display = field_get_display($instance, $view_mode, $node);
     $settings = array_merge(field_info_formatter_settings($display['type']), $display['settings']);
     $field_product = field_get_items('node', $node, $field_name);
     $product_id = $field_product[0]['product_id'];
     $products = commerce_product_load_multiple(array($product_id));
     $type = !empty($settings['line_item_type']) ? $settings['line_item_type'] : 'product';
     $line_item = commerce_product_line_item_new(commerce_product_reference_default_product($products), $settings['default_quantity'], 0, array(), $type);
     $line_item->data['context']['product_ids'] = array_keys($products);
     $line_item->data['context']['add_to_cart_combine'] = !empty($settings['combine']);
     $line_item->data['context']['show_single_product_attributes'] = !empty($settings['show_single_product_attributes']);
     $cart_context = array('entity_type' => 'node', 'entity_id' => $nid, 'display' => 'default', 'language' => $language);
     $cart_context['class_prefix'] = $cart_context['entity_type'] . '-' . $nid;
     $cart_context['view_mode'] = $cart_context['entity_type'] . '_' . $view_mode;
     $entity_uri = entity_uri($cart_context['entity_type'], $node);
     $arguments = array('form_id' => commerce_cart_add_to_cart_form_id(array($product_id)), 'line_item' => $line_item, 'show_quantity' => $settings['show_quantity']);
     // Add the display path and referencing entity data to the line item.
     if (!empty($entity_uri['path'])) {
         $arguments['line_item']->data['context']['display_path'] = $entity_uri['path'];
     }
     $arguments['line_item']->data['context']['entity'] = array('entity_type' => $cart_context['entity_type'], 'entity_id' => $cart_context['entity_id'], 'product_reference_field_name' => $field_name);
     // Update the product_ids variable to point to the entity data if we're
     // referencing multiple products.
     if (count($arguments['line_item']->data['context']['product_ids']) > 1) {
         $arguments['line_item']->data['context']['product_ids'] = 'entity';
     }
     parent::__construct($arguments['form_id'], $arguments['line_item'], $arguments['show_quantity'], $cart_context);
     $this->cart_context = $cart_context;
     $this->arguments = $arguments;
 }
Esempio n. 27
0
/**
 * Implements hook_preprocess_page().
 */
function os2web_core_theme_preprocess_page(&$variables)
{
    $node = NULL;
    if (isset($variables['node']) && !empty($variables['node']->nid)) {
        $node = $variables['node'];
    }
    // If display children is been set, so get the children nodes..
    if ($node && ($display_children = field_get_items('node', $node, 'field_os2web_base_field_children'))) {
        if ($node->type == 'os2web_base_contentpage' && $display_children[0]['value'] == 1) {
            $children = syddjurs_special_content_get_children();
            if ($children) {
                $children_render = syddjurs_special_content_render_children($children);
                $variables['page']['content']['content']['content']['system_main']['nodes'][$node->nid]['node_children'] = array('node_children' => array('#markup' => drupal_render($children_render)), '#theme_wrappers' => array('container'), '#attributes' => array('class' => array('node-children')), '#weight' => 10);
            }
        }
    }
}
 /**
  * Finds all the users that are allowed to be assigned to the issue.
  *
  * @return array
  *   An array of users that can be assigned to the issue this selector is
  *   attached to. The array contains and is indexed by user ID (uid). If
  *   there are no allowed users or we hit some other error, the array will
  *   be empty.
  */
 protected function getAllowedAssignees()
 {
     $return = array();
     if ($this->entity) {
         $settings = $this->field['settings'];
         if ($project_field_items = field_get_items($this->entity_type, $this->entity, $settings['handler_settings']['project_field'])) {
             $referenced_project_id = $project_field_items[0]['target_id'];
             if ($referenced_project_id) {
                 $projects = entity_load('node', array($referenced_project_id));
                 $this->project = $projects[$referenced_project_id];
             }
         }
         $project_field_items = field_get_items($this->entity_type, $this->entity, $this->field['field_name']);
         $current = isset($project_field_items[0]) ? $project_field_items[0]['target_id'] : NULL;
         $return = project_issue_assigned_choices($this->entity, $this->project, $current);
     }
     return $return;
 }
 /**
  * Displays the bean.
  */
 public function view($bean, $content, $view_mode = 'default', $langcode = NULL, $test = NULL)
 {
     // There's no point in displaying the button if amazon js was not included.
     if (($js = commerce_cba_javascript_file()) && isset($bean->order) && ($order = $bean->order)) {
         if (!empty($order->commerce_cba_amazon_order_ids)) {
             $content['bean'][$bean->delta]['#attached']['library'] = array(array('commerce_cba', 'amazon_widgets'));
             $order_ids = field_get_items('commerce_order', $order, 'commerce_cba_amazon_order_ids');
             foreach ($order_ids as $order_id) {
                 $html_id = drupal_html_id('OrderDetailsWidget');
                 // @TODO: Add height and width.
                 $data = array('commerce_cba' => array($html_id => array('html_id' => $html_id, 'widget_type' => 'OrderDetailsWidget', 'merchantId' => variable_get('cba_merchant_id', ''), 'orderId' => $order_id['value'])));
                 $content['bean'][$bean->delta][$html_id]['#attached']['js'][] = array('data' => $data, 'type' => 'setting');
                 $content['bean'][$bean->delta][$html_id]['#type'] = 'container';
                 $content['bean'][$bean->delta][$html_id]['#attributes'] = array('id' => $html_id);
             }
         }
     }
     return $content;
 }
Esempio n. 30
-1
/**
 * Define some variables for use in theme templates.
 */
function redcrackle_process_page(&$variables)
{
    $tid = arg(2);
    // Assign site name and slogan toggle theme settings to variables.
    $variables['disable_site_name'] = theme_get_setting('toggle_name') ? FALSE : TRUE;
    $variables['disable_site_slogan'] = theme_get_setting('toggle_slogan') ? FALSE : TRUE;
    // Assign site name/slogan defaults if there is no value.
    if ($variables['disable_site_name']) {
        $variables['site_name'] = filter_xss_admin(variable_get('site_name', 'Drupal'));
    }
    if ($variables['disable_site_slogan']) {
        $variables['site_slogan'] = filter_xss_admin(variable_get('site_slogan', ''));
    }
    if (!empty($tid) && arg(1) == 'term') {
        $term = taxonomy_term_load($tid);
        // Unset the default content
        //unset($variables['page']['content']);
        taxonomy_term_load($tid);
        $field_image = field_get_items('taxonomy_term', $term, 'field_image');
        $uri = !empty($field_image[0]['uri']) ? $field_image[0]['uri'] : '';
        $alt = !empty($field_image[0]['alt']) ? $field_image[0]['alt'] : '';
        if (!empty($uri)) {
            $variables['image_url'] = theme('image_style', array('path' => $uri, 'style_name' => 'large', 'alt' => $alt));
        }
        $variables['description'] = $term->description;
        $variables['theme_hook_suggestions'][] = 'page__taxonomy__services';
    }
}