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)); }
/** * Return an array of items for the field. */ function set_items($values, $row_id) { // In some cases the instance on the entity might be easy, see // https://drupal.org/node/1161708 and https://drupal.org/node/1461536 for // more information. if (empty($values->_field_data[$this->field_alias]) || empty($values->_field_data[$this->field_alias]['entity']) || !isset($values->_field_data[$this->field_alias]['entity']->{$this->definition['field_name']})) { return array(); } $display = array('type' => $this->options['type'], 'settings' => $this->options['settings'], 'label' => 'hidden', 'views_view' => $this->view, 'views_field' => $this, 'views_row_id' => $row_id); $entity_type = $values->_field_data[$this->field_alias]['entity_type']; $entity = $this->get_value($values, 'entity'); if (!$entity) { return array(); } $langcode = $this->field_language($entity_type, $entity); if (empty($langcode)) { $langcode = LANGUAGE_NONE; } $multifield_items = field_get_items($entity_type, $entity, $this->definition['field_name'], $langcode); if (is_array($multifield_items)) { array_walk($multifield_items, 'multifield_item_unserialize', multifield_extract_multifield_machine_name($this->multifield_info)); } else { $multifield_items = array(); } $render_array = array(); foreach ($multifield_items as $multifield_item) { $multifield = _multifield_field_item_to_entity(multifield_extract_multifield_machine_name($this->multifield_info), $multifield_item); $subfield_langcode = $this->field_language('multifield', $multifield); if (empty($render_array)) { $render_array = field_view_field('multifield', $multifield, $this->definition['subfield_name'], $display, $subfield_langcode); } else { $subfield_render_array = field_view_field('multifield', $multifield, $this->definition['subfield_name'], $display, $subfield_langcode); // Multifield subfields are always single value. $render_array[] = $subfield_render_array[0]; } } $items = array(); if ($this->options['field_api_classes']) { // Make a copy. $array = $render_array; return array(array('rendered' => drupal_render($render_array))); } foreach (element_children($render_array) as $count) { $items[$count]['rendered'] = $render_array[$count]; // field_view_field() adds an #access property to the render array that // determines whether or not the current user is allowed to view the // field in the context of the current entity. We need to respect this // parameter when we pull out the children of the field array for // rendering. if (isset($render_array['#access'])) { $items[$count]['rendered']['#access'] = $render_array['#access']; } // Only add the raw field items (for use in tokens) if the current user // has access to view the field content. if ((!isset($items[$count]['rendered']['#access']) || $items[$count]['rendered']['#access']) && !empty($render_array['#items'][$count])) { $items[$count]['raw'] = $render_array['#items'][$count]; } } return $items; }
/** * Override or insert variables into the node template. */ function intranet_preprocess_node(&$variables) { $node = $variables['node']; $field_items = field_get_items('node', $node, 'field_linktype'); $link_type = $field_items[0]['value']; if ($variables['view_mode'] == 'full' && node_is_page($variables['node'])) { $variables['classes_array'][] = 'node-full'; } if ($variables['type'] == 'cluster_of_links' && $link_type == 'All Applications') { $content_array = $variables['field_link_details']; $field_items1 = field_get_items('node', $node, 'field_link_details'); foreach ($field_items1 as $key => $value) { $multifield = _multifield_field_item_to_entity('field_link_details', $value); $subfield_link = field_get_items('multifield', $multifield, 'field_link'); $subfield_icon = field_get_items('multifield', $multifield, 'field_clustor_link_icon'); $link_url = $subfield_link[0]['display_url']; $link_title = $subfield_link[0]['title']; $img_path = $subfield_icon[0]['uri']; $image = array('style_name' => 'all_application', 'path' => $img_path, 'alt' => '', 'title' => ''); // link elements $text = theme('image_style', $image); // in your case it's an image $path = $link_url; $options = array('attributes' => array('target' => '_blank'), 'html' => true); $items[] = array('data' => l($text, $path, $options), 'id' => 'all_app_list_' . $key); } $attributes = array('id' => 'all-app-list'); $links_html = theme_item_list(array('items' => $items, 'type' => 'ul', 'title' => '', 'attributes' => $attributes)); $variables['all_applications_record'] = $links_html; $variables['theme_hook_suggestions'][] = 'node__teaser_all_app'; } if ($variables['type'] == 'cluster_of_links' && $link_type == 'Quick Links' && ($variables['view_mode'] == 'teaser' || $variables['view_mode'] == 'full')) { $variables['theme_hook_suggestions'][] = 'node__teaser_quick_links'; } if ($variables['type'] == 'cxo_messages' && $variables['view_mode'] == 'full') { $user = user_load($variables['user']->uid); if ($user->picture) { $variables['user_picture'] = theme_image_style(array('style_name' => 'cxo-message-user', 'path' => $user->picture->uri, 'attributes' => array('class' => 'avatar'), 'width' => "170", 'height' => "180")); } else { $variables['user_picture'] = theme_image_style(array('style_name' => 'cxo-message-user', 'path' => 'public://detail-user.png', 'attributes' => array('class' => 'avatar'), 'width' => "170", 'height' => "180")); } $variables['date'] = date("M j, Y", strtotime($variables['date'])); $variables['submitted'] = t('!username on !datetime', array('!username' => $variables['name'], '!datetime' => $variables['date'])); } //Applying cxo style to user image on award detail page for consistency. if ($variables['type'] == 'award' && $variables['view_mode'] == 'full') { if ($variables['field_user_identity'][0]['entity']->picture) { $variables['user_picture'] = theme_image_style(array('style_name' => 'cxo-message-user', 'path' => $variables['field_user_identity'][0]['entity']->picture->uri, 'attributes' => array('class' => 'avatar'), 'width' => "170", 'height' => "180")); } else { $variables['user_picture'] = theme_image_style(array('style_name' => 'cxo-message-user', 'path' => 'public://detail-user.png', 'attributes' => array('class' => 'avatar'), 'width' => "170", 'height' => "180")); } } if ($variables['type'] == 'units' && $variables['view_mode'] == 'full') { $variables['theme_hook_suggestions'][] = 'node__units'; } }