/** * Map taxonomy term ids to their paths. * * This allows override of the default taxonomy/term/[tid] path for terms. As an * example, this can be used to set the menu trail to a view where these terms * are used, a specific node and so on. * * If you don't want to provide mappings for some terms then just skip them and * Taxonomy Menu Trails will use default path for these terms. * * Results from multiple implementations are merged together. * * @param array $tids * The list of taxonomy term ids. * @param string $entity_type * The type of entity passed to the next argument. * @param object $entity * The entity object, e.g. node. * @param array $settings * The taxonomy menu trails settings for this entity type. * * @return null|array * List of mappings. Keys are tids and values can be: * - string: single term path. * - array: list of paths sorted by preference (the most preferred path should * be the first). */ function hook_taxonomy_menu_trails_get_paths($tids, $entity_type, $entity, $settings) { // It is safe to load the same list of terms multiple times, because results // are saved in static cache. $terms = taxonomy_term_load_multiple($tids); $paths = array(); foreach ($terms as $term) { if ($term->tid == 987) { // Specific term mapped to node and custom path. When selection method is // first/last the first path existing in menu wins. So, node path will be // preferred in this case. $paths[$term->tid] = array('node/23', 'some/path'); continue; } switch ($term->vid) { case 123: // Some specific vocabulary mapped to a view. $paths[$term->tid] = 'path/to/my/view' . $term->tid; break; case 456: // Skip vocabulary. Terms will be mapped to default path. break; default: // Map the rest to some default view. $paths[$term->tid] = 'path/to/default/view/' . $term->tid; } } return $paths; }
public function genresProcess($tids) { $genres = taxonomy_term_load_multiple($tids); if (empty($genres)) { return NULL; } $element = []; foreach ($genres as $genre) { $path = entity_uri('taxonomy_term', $genre); $element[] = array('name' => entity_label('taxonomy_term', $genre), 'path' => url($path['path'], $path['options'])); } return $element; }
/** * @param string $roles * User roles, separated by comma. * @param TableNode $fields * | Field machine name or label | Value | * * @throws \EntityMetadataWrapperException * When user object cannot be saved. * @throws \Exception * When required fields are not filled. * * @example * Then I am logged in as a user with "CRM Client" role and filled fields * | Full name | Sergey Bondarenko | * | Position | Developer | * | field_crm_user_company | Propeople | * * @Given /^(?:|I am )logged in as a user with "([^"]*)" role(?:|s)(?:| and filled fields:)$/ * * @user @api */ public function createDrupalUser($roles, TableNode $fields = null) { $user = $this->createUserWithRoles($roles); if ($fields) { $entity = self::entityWrapper($user->uid); $required = self::getUserEntityFields('required'); // Fill fields. Field can be found by name or label. foreach ($fields->getRowsHash() as $field_name => $value) { $field_info = self::getUserEntityFieldInfo($field_name); if (empty($field_info)) { continue; } $field_name = $field_info['field_name']; switch ($field_info['type']) { case 'taxonomy_term_reference': // Try to find taxonomy term by it name. $terms = taxonomy_term_load_multiple([], ['name' => $value]); if (!$terms) { throw new \InvalidArgumentException(sprintf('Taxonomy term "%s" does no exist.', $value)); } $value = key($terms); break; } $entity->{$field_name}->set($value); // Remove field from $required if it was there and filled. if (isset($required[$field_name])) { unset($required[$field_name]); } } // Throw an exception when one of required fields was not filled. if (!empty($required)) { throw new \Exception(sprintf('The following fields "%s" are required and has not filled.', implode('", "', $required))); } $entity->save(); } $this->loginUser(); }
/** * Implements theme_preprocess_node(). */ function cuemail_preprocess_node(&$vars) { $vars['theme_hook_suggestions'][] = 'node__' . $vars['type'] . '__' . $vars['view_mode']; $url = url('node/' . $vars['nid'], array('absolute' => TRUE, 'alias' => TRUE, 'https' => FALSE)); $vars['node_url'] = $url; if ($vars['type'] == 'newsletter') { if (!empty($vars['content']['field_newsletter_intro_image'])) { $vars['content']['field_newsletter_intro_image'][0]['#image_style'] = 'email_medium'; } $list = array(); foreach ($vars['content']['field_newsletter_section']['#items'] as $key => $item) { $key_2 = key($vars['content']['field_newsletter_section'][$key]['entity']['field_collection_item']); $articles = $vars['content']['field_newsletter_section'][$key]['entity']['field_collection_item'][$key_2]['field_newsletter_articles']['#items']; foreach ($articles as $article) { $node = node_load($article['target_id']); $list[] = $node->title; } } $newsletter_logo_image_style_uri = image_style_path('medium', $vars['newsletter_logo_uri']); if (!file_exists($newsletter_logo_image_style_uri)) { image_style_create_derivative(image_style_load('medium'), $vars['newsletter_logo_uri'], $newsletter_logo_image_style_uri); } $image_info = image_get_info($newsletter_logo_image_style_uri); $vars['newsletter_logo_width'] = round($image_info['width'] * 0.46333); $vars['newsletter_logo_height'] = round($image_info['height'] * 0.46333); $vars['content']['list'] = theme('item_list', array('items' => $list, 'type' => 'ul', 'attributes' => array('class' => array('bullet-list')))); } if ($vars['type'] == 'article') { if (!empty($vars['content']['field_article_thumbnail'][0])) { $vars['content']['field_article_thumbnail'][0]['#path']['options']['absolute'] = TRUE; } if ($vars['view_mode'] == 'email_feature') { $vars['content']['field_article_thumbnail'][0]['#image_style'] = 'email_feature_thumbnail'; } if (isset($vars['field_article_categories'])) { foreach ($vars['field_article_categories'] as $tid) { if (isset($tid['tid'])) { $tids[] = $tid['tid']; } } } if (isset($tids)) { $terms = taxonomy_term_load_multiple($tids); foreach ($terms as $term) { if (isset($term->name)) { $tag = $term->name; if ($term->field_category_display[LANGUAGE_NONE][0]['value'] == 'show') { if (!empty($term->field_category_term_page_link)) { $new_tags[] = l($tag, $term->field_category_term_page_link[LANGUAGE_NONE][0]['url'], array('absolute' => TRUE, 'alias' => TRUE, 'https' => FALSE)); } else { $new_tags[] = $tag; } } } } $markup = implode(' ', $new_tags); unset($vars['content']['field_article_categories']); $vars['content']['field_article_categories'][0]['#markup'] = '<p>' . $markup . '</p>'; } } }
/** * Save specified taxonomy terms to vocabulary * * @param mixed $name * A string or an array of strings * @param int|string $voc * (optionally) Vocabulary id/name * * @return mixed * Fetched and inserted tids */ public static function setTaxonomyTerms($name, $voc = 0) { if (!is_numeric($voc)) { $voc = self::getVidFromName($voc); } if (!is_array($name)) { $name = array($name); } $tids = array(); $existing = self::getTaxonomyIdByName($name, $voc); if (!empty($existing)) { $existing = taxonomy_term_load_multiple($existing, array('vid' => $voc)); foreach ($existing as &$term) { $tids[drupal_strtolower($term->name)] = $term->tid; $term = NULL; } } unset($existing); foreach ($name as &$term) { if (!isset($tids[drupal_strtolower($term)])) { $t = new stdClass(); $t->vid = $voc; $t->name = $term; taxonomy_term_save($t); $tids[$t->name] = $t->tid; $t = NULL; $term = NULL; } } return $tids; }
public function actionHome() { if (!isset($_POST['tid'])) { $tree = taxonomy_get_tree(2, 23, 50); $tid = $tree[0]->tid; } else { $tid = $_POST['tid']; } //专题推送 $query = new EntityFieldQuery(); $result = $query->entityCondition('entity_type', 'taxonomy_term')->fieldCondition('field_lanmu', 'tid', $tid)->execute(); $sorders = array(); if (isset($result['taxonomy_term'])) { $termids = array_keys($result['taxonomy_term']); $terms = taxonomy_term_load_multiple($termids); foreach ($terms as $key => $term) { if ($term->field_zorder['und'][0]['value']) { $sorders[$term->field_zorder['und'][0]['value']] = $term->tid; } //$sorders[$term->field_field_zorder['und'][0]['value']]=$key; } } $query = new EntityFieldQuery(); if (isset($_POST['lastnewsid'])) { $query->entityCondition('entity_type', 'node')->fieldCondition('field_lanmu', 'tid', $tid)->fieldCondition('field_show', 'value', 1)->propertyCondition('status', 1)->propertyCondition('nid', $_POST['lastnewsid'], '<')->propertyOrderBy('sticky', 'DESC')->propertyOrderBy('vid', 'DESC')->range(0, 20); } else { $query->entityCondition('entity_type', 'node')->fieldCondition('field_lanmu', 'tid', $tid)->fieldCondition('field_show', 'value', 1)->propertyCondition('status', 1)->propertyOrderBy('sticky', 'DESC')->propertyOrderBy('vid', 'DESC')->range(0, 20); } $result = $query->execute(); $count = 1; $newslists = array(); if (isset($result['node'])) { $news_items_nids = array_keys($result['node']); $nodes = node_load_multiple($news_items_nids); foreach ($nodes as $node) { if (!isset($_POST['lastnewsid'])) { while (array_key_exists($count, $sorders)) { $key = $sorders[$count]; $term = $terms[$key]; $special['newstype'] = 4; //专题 $special['specialtype'] = $term->field__leix['und'][0]['value']; $special['specialid'] = $term->tid; $special['specialtitle'] = $term->name; $special['specialimag'] = str_replace("public://", BigImg, $term->field_tux['und'][0]['uri']); if ($term->field_link) { $special['speciallink'] = $term->field_link['und'][0]['value']; } array_push($newslists, $special); $count = $count + 1; } } if ($node->type == 'multi') { $newslist['newstype'] = 2; //多图 $newslist['newstitle'] = $node->title; $newslist['newsid'] = $node->nid; $pics = array(); $field_tups = $node->field_tup['und']; foreach ($field_tups as $field_tup) { $pic = new pic(); $pic->pic = $field_tup['uri']; $pic->pic = str_replace("public://", BigImg, $pic->pic); array_push($pics, $pic); } $newslist['newspics'] = $pics; array_push($newslists, $newslist); } else { if ($node->type == '_url') { $url_news['newstype'] = 3; //url链接新闻 $url_news['newstitle'] = $node->title; $url_news['newsid'] = $node->nid; $url_news['newsicon'] = $node->field_tux['und'][0]['uri']; $url_news['newsicon'] = str_replace("public://", BigImg, $url_news['newsicon']); $url_news['newslink'] = $node->field_link['und'][0]['value']; array_push($newslists, $url_news); } else { $normal_news['newstype'] = 1; //普通新闻 $normal_news['newstitle'] = $node->title; $normal_news['newsid'] = $node->nid; $field_image = $node->field_image; $normal_news['newsicon'] = $field_image['und'][0]['uri']; $normal_news['newsicon'] = str_replace("public://", ThumbnailImg, $normal_news['newsicon']); $field_fubiaoti = $node->field_fubiaoti; $normal_news['newssubtitle'] = $field_fubiaoti['und'][0]['value']; $normal_news['newslabel'] = $node->field_label['und'][0]['value']; $normal_news['comment_count'] = $node->comment_count; array_push($newslists, $normal_news); } } $count = $count + 1; } } else { if (!isset($_POST['lastnewsid'])) { foreach ($terms as $key => $term) { $special['newstype'] = 4; //专题 $special['specialtype'] = $term->field__leix['und'][0]['value']; $special['specialid'] = $term->tid; $special['specialtitle'] = $term->name; $special['specialimag'] = str_replace("public://", BigImg, $term->field_tux['und'][0]['uri']); if ($term->field_link) { $special['speciallink'] = $term->field_link['und'][0]['value']; } array_push($newslists, $special); } } } if (isset($_POST['lastnewsid'])) { $easyhome = new easyhome(); $easyhome->error_code = 0; $easyhome->newslist = $newslists; $jsonObj = CJSON::encode($easyhome); echo $jsonObj; } else { $homepage = new Homepage(); $homepage->newslist = $newslists; //首页轮播图 $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'node')->propertyCondition('status', 1)->fieldCondition('field_lanmu', 'tid', $tid)->propertyCondition('promote', 1, '=')->propertyOrderBy('vid', 'DESC')->range(0, 5); $result = $query->execute(); if (isset($result['node'])) { $news_items_nids = array_keys($result['node']); $topnodes = node_load_multiple($news_items_nids); } $topbanners = array(); // echo count($nodes); foreach ($topnodes as $key => $node) { $topbanner = new topbanner(); if ($node->type == 'multi') { $topbanner->toptype = 2; } else { if ($node->type == '_url') { $topbanner->toptype = 3; $topbanner->toplink = $node->field_link['und'][0]['value']; } else { $topbanner->toptype = 1; } } $field_image = $node->field_image; $topbanner->topimag = $field_image['und'][0]['uri']; $topbanner->topimag = str_replace("public://", BigImg, $topbanner->topimag); $topbanner->toptitle = $node->title; $topbanner->topid = $node->nid; array_push($topbanners, $topbanner); } $homepage->topbanner = $topbanners; $homepage->error_code = 0; $jsonObj = CJSON::encode($homepage); echo $jsonObj; } }
public function checkTaxonomyAutocompleteItems($field_name, $testClass, $values) { $current_tids = call_user_func(array($this, "get" . Utils::makeTitleCase($field_name))); if (!is_array($current_tids)) { $term = taxonomy_term_load($current_tids); $testClass->assertEquals($values, $term->name, "Values of the " . $field_name . " do not match."); } else { $terms = taxonomy_term_load_multiple($current_tids); $term_labels = array(); foreach ($terms as $tid => $term) { $term_labels[] = $term->name; } $testClass->assertEquals($values, $term_labels, "Values of the " . $field_name . " do not match."); } }
/** * Implementing hook_preprocess_html() */ function jjamerson_lc_preprocess_html(&$variables) { /* Override head title on unique site sections: */ global $_bss_section_information; $site_section = false; if (isset($_bss_section_information['tid'])) { $site_section_tid = $_bss_section_information['tid']; $site_section = taxonomy_term_load($site_section_tid); } if (isset($node['language'])) { $lang = $node['language']; } else { $lang = 'und'; } if ($site_section && isset($site_section->field_base_url['und'][0]['value'])) { // Check to see if this is the homepage of the site section. If so, just use the site section name. // If not, use the current page title + the site section name. if (drupal_get_path_alias() === $site_section->field_base_url['und'][0]['value']) { $variables['head_title'] = $site_section->name; if (empty($site_section->field_standalone['und'][0]['value'])) { $variables['head_title'] .= ' | Berklee College of Music'; } } else { if (isset($site_section->field_standalone['und'][0]['value']) && $site_section->field_standalone['und'][0]['value']) { $variables['head_title'] = $variables['head_title_array']['title'] . ' | ' . $site_section->name; } } } /* Override title on front page, because for some reason a pipe is being inserted into it */ if ($variables['is_front']) { $variables['head_title'] = 'Berklee College of Music'; } /* Add classes related to workbench moderation */ if (isset($variables['page']['content']['system_main']['nodes'])) { $nodes = $variables['page']['content']['system_main']['nodes']; if (count($nodes) === 2) { $not_really_the_node = current($nodes); $node = $not_really_the_node['#node']; if (isset($node->workbench_moderation['published']) && $node->workbench_moderation['published']->vid === $node->vid) { $workbench_moderation = $node->workbench_moderation['published']; } else { if (isset($node->workbench_moderation)) { $workbench_moderation = $node->workbench_moderation['current']; } } if (isset($workbench_moderation) && $workbench_moderation->state) { $variables['classes_array'][] = 'workbench-state-' . $workbench_moderation->state; if ($workbench_moderation->published) { $variables['classes_array'][] = 'workbench-published'; } else { $variables['classes_array'][] = 'workbench-unpublished'; } } } } /* Add tags on node as classes: */ if (isset($variables['page']['content']['system_main']['nodes'])) { $nodes = $variables['page']['content']['system_main']['nodes']; if (count($nodes) === 2) { $not_really_the_node = current($nodes); if (isset($not_really_the_node['#node'])) { $node = $not_really_the_node['#node']; if (isset($node->field_isotope_tags[$lang]) && count($node->field_isotope_tags[$lang])) { $tids = array(); foreach ($node->field_isotope_tags[$lang] as $tid) { $tids[] = $tid['tid']; } try { $tags = taxonomy_term_load_multiple($tids); foreach ($tags as $tag) { $tag_name = strtolower($tag->name); $tag_name = preg_replace('/[^a-z0-9 -]+/', '', $tag_name); $tag_name = preg_replace('/\\s/', '-', $tag_name); $tag_name = 'tagged-' . $tag_name; $variables['classes_array'][] = " {$tag_name}"; } } catch (Exception $e) { // do nothing } } } } } if (isset($site_section->field_base_url) && isset($site_section->field_banner_image_large[$lang][0]['uri']) && $site_section->description) { $site_section_home = $site_section->field_base_url[$lang][0]['value']; if (drupal_get_path_alias() == $site_section_home) { $variables['classes_array'][] = "lead-page"; } } /* Add a class to landing pages if the call-to-action field is empty: */ if (isset($node) && $node->type === 'landing' && count($node->field_call_to_action) === 0) { $variables['classes_array'][] = 'empty-call-to-action'; } /* Add a class to distinguish the Directory's starting page: */ if (function_exists('apachesolr_search_page_load')) { $directory_search = apachesolr_search_page_load('directory'); // Get the path from the page info $directory_path = $directory_search['search_path']; if ($directory_path === current_path()) { $variables['classes_array'][] = 'directory-front'; } } /* Add the site section TID */ global $_bss_section_information; if ($_bss_section_information) { $variables['classes_array'][] = 'section-' . $_bss_section_information['tid']; } if (isset($_GET['content-only'])) { $variables['classes_array'][] = 'content-only-display'; } if (isset($_GET['render-only'])) { $variables['classes_array'][] = 'render-only render-only-' . $_GET['render-only']; unset($variables['classes_array']['logged-in']); } if (isset($_GET['iframed'])) { $variables['classes_array'][] = 'iframed'; $target = array('#type' => 'markup', '#markup' => '<base target="_blank" />'); drupal_add_html_head($target, 'jjamerson_lc-iframe-target'); } /* Check for user testing variables and set a timestamp array variable */ $user_testing = false; if (isset($_GET['user-testing'])) { $user_testing = true; $_SESSION['berklee-user-testing']['last-used'] = time(); } elseif (isset($_SESSION['berklee-user-testing']['last-used'])) { $user_testing_seconds = 1200; // 20 minutes if (time() - $_SESSION['berklee-user-testing']['last-used'] > $user_testing_seconds) { unset($_SESSION['berklee-user-testing']); } } if (isset($_GET['htln']) || isset($_GET['hide-top-left-nav']) || isset($_SESSION['berklee-user-testing']['hide-top-left-nav'])) { $variables['classes_array'][] = 'hide-top-left-nav'; if ($user_testing) { $_SESSION['berklee-user-testing']['hide-top-left-nav'] = true; } } if (isset($_GET['hct']) || isset($_GET['hide-campus-tools']) || isset($_SESSION['berklee-user-testing']['hide-campus-tools'])) { $variables['classes_array'][] = 'hide-campus-tools'; if ($user_testing) { $_SESSION['berklee-user-testing']['hide-campus-tools'] = true; } } if (isset($_GET['hs']) || isset($_GET['hide-search']) || isset($_SESSION['berklee-user-testing']['hide-search'])) { $variables['classes_array'][] = 'hide-search'; if ($user_testing) { $_SESSION['berklee-user-testing']['hide-search'] = true; } } if (isset($_GET['hli']) || isset($_GET['hide-login']) || isset($_SESSION['berklee-user-testing']['hide-login'])) { $variables['classes_array'][] = 'hide-login'; if ($user_testing) { $_SESSION['berklee-user-testing']['hide-login'] = true; } } if (isset($_GET['hap']) || isset($_GET['hide-apply']) || isset($_SESSION['berklee-user-testing']['hide-apply'])) { $variables['classes_array'][] = 'hide-apply'; if ($user_testing) { $_SESSION['berklee-user-testing']['hide-apply'] = true; } } }
<strong><?php echo render($content['field_title']); ?> </strong> <?php echo render($content['description']); ?> </div> </li> </a> </ul> <?php $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'taxonomy_term')->propertyCondition('vid', $term->vid)->propertyOrderBy('weight'); $result = $query->execute(); if ($terms = taxonomy_term_load_multiple(array_keys($result['taxonomy_term']))) { ?> <ol class="bjqs-markers h-centered"> <?php foreach ($terms as $_term) { $uri = entity_uri('taxonomy_term', $_term); ?> <li><?php echo l($_term->name, $uri['path'], $uri['options']); ?> </li> <?php } ?> </ol> <?php
function build_json($markerCluster, $options) { $array_types = array(); $typologies = null; if ($options['typology'] != null) { $array_types = explode(',', $options['typology']); $typologies = taxonomy_term_load_multiple($array_types); } else { // load taxonomy 'store_typology' $taxonomies_vocab = taxonomy_vocabulary_get_names(); $typoTaxoVID = $taxonomies_vocab['store_typology']->vid; // Load store types (taxonomy vid=2) $type_options = array(); $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'taxonomy_term', '=')->propertyCondition('vid', $typoTaxoVID, '='); $result = $query->execute(); if (!empty($result)) { $typologies = taxonomy_term_load_multiple(array_keys($result['taxonomy_term'])); } } $json = array(); global $base_url; $path_icon_cluster = $base_url . '/' . drupal_get_path('module', 'storelocator_ws') . "/images/"; $index = 0; $count = 0; if ($options['macro'] != null && $options['macro'] == 'true') { foreach ($markerCluster->clusters as $cluster) { if (count($cluster->markers) > 1) { $json['results'][] = buildClusterMarkers($cluster, $index, $path_icon_cluster); $index++; $count += count($cluster->markers); } else { //print_r(count($cluster->getMarkers())); $json['results'][] = buildSimpleMarkers(reset($cluster->markers), $typologies); $count++; } } } else { foreach ($markerCluster->markers as $marker) { //print_r(count($cluster->getMarkers())); $json['results'][] = buildSimpleMarkers($marker, $typologies); $count++; } } $json['count'] = $count; return $json; }
function ardent_taxonomy_get_term_by_name($name, $vocabulary = NULL) { $conditions = array('name' => trim($name)); if (isset($vocabulary)) { $vocabularies = taxonomy_vocabulary_get_names(); if (isset($vocabularies[$vocabulary])) { $conditions['vid'] = $vocabularies[$vocabulary]->vid; } else { // Return an empty array when filtering by a non-existing vocabulary. return array(); } } return taxonomy_term_load_multiple(array(), $conditions); }
/** * @param $tids * * @return array */ public static function createTermObjectsFromTids($tids, $vocabulary = NULL, $false_on_invalid = TRUE) { $terms = taxonomy_term_load_multiple($tids); $termObjects = array(); foreach ($tids as $tid) { if (empty($terms[$tid])) { if ($false_on_invalid) { $termObjects[] = FALSE; } else { $termObjects = $tid; } continue; } $vocabulary = $terms[$tid]->vocabulary_machine_name; $term_class = "RedTest\\entities\\TaxonomyTerm\\" . Utils::makeTitleCase($vocabulary); $termObjects[] = new $term_class($tid); } return $termObjects; }
<div class="om-right-block"> <h3 class="om-right-title"><?php print t("Fontions Concernees"); ?> </h3> <div class="om-right-content om-access"> <div class="field field-name-field-om-actuers field-type-taxonomy-term-reference field-label-hidden view-mode-full"><ul class="field-items"> <?php $actuers = $node->field_om_actuers['und']; for ($i = 0; $i < count($actuers); $i++) { if ($i % 2 == 0) { $class = "even"; } else { $class = "odd"; } $actuers_term = taxonomy_term_load_multiple(array($actuers[$i]['tid'])); print '<li class="field-item ' . $class . '">' . $actuers_term->name . '</li>'; } ?> </ul> </div> </div> </div> <?php } ?> <?php if (!empty($node->field_om_duration['und'][0]['value'])) { ?> <div class="om-right-block"> <h3 class="om-right-title"><?php
<?php if (isset($node->language)) { $lang = $node->language; } else { $lang = 'und'; } if (isset($node->field_isotope_tags[$lang]) && count($node->field_isotope_tags[$lang])) { $tids = array(); foreach ($node->field_isotope_tags[$lang] as $tid) { $tids[] = $tid['tid']; } try { $tags = taxonomy_term_load_multiple($tids); foreach ($tags as $tag) { $tag_name = strtolower($tag->name); $tag_name = preg_replace('/[^a-z0-9 -]+/', '', $tag_name); $tag_name = preg_replace('/\\s/', '-', $tag_name); $tag_name = 'tagged-' . $tag_name; $classes .= " {$tag_name}"; } } catch (Exception $e) { } } ?> <div id="node-<?php print $node->nid; ?> " class="<?php print $classes;
function unity_lab_it_preprocess_paragraphs_item_service_categories_section(&$vars, $hook) { $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'taxonomy_term')->propertyCondition('vid', '3')->propertyOrderBy('weight')->range(0, 12); //do not forget the semicolon at the end of the query conditions $result = $query->execute(); if (!empty($result['taxonomy_term'])) { // To load all terms. $terms = taxonomy_term_load_multiple(array_keys($result['taxonomy_term'])); // To generate an options list. foreach ($terms as $term) { $taxTerm = array(); $targetLink = field_get_items('taxonomy_term', $term, 'field_target_link'); $targetLink = empty($targetLink[0]['url']) ? '' : $targetLink[0]['url']; $taxTerm['target']['url'] = url($targetLink); $icon = field_get_items('taxonomy_term', $term, 'field_icon_font_class'); $icon = empty($icon[0]['value']) ? '' : $icon[0]['value']; $taxTerm['icon'] = $icon; $taxTerm['title'] = $term->name; $nodes = field_get_items('taxonomy_term', $term, 'field_related_nodes'); $link = array(); foreach ($nodes as $node) { $nodeItem = node_load($node['target_id']); $link['title'] = $nodeItem->title; $link['url'] = url('node/' . $nodeItem->nid); $taxTerm['links'][] = $link; } $vars['content']['items'][] = $taxTerm; // To hook into i18n and everything else, use entity_label(). } } }
function _taxonomy_field($name, $vocab_name, $caption, $subtype, $active, $require, $card) { $vocab = taxonomy_vocabulary_machine_name_load($vocab_name); $items = array(); if (!empty($vocab)) { $terms = taxonomy_term_load_multiple(_get_term_id_array_by_vid($vocab->vid)); foreach ($terms as $tid => $term) { $items[] = array('id' => $tid, 'text' => $term->name); } } $max = $card; if ($card == FIELD_CARDINALITY_UNLIMITED) { $max = 0; } $attr = ''; if (!$active) { $attr .= ' disabled'; } if ($subtype == 'category' || $subtype == 'tag') { $taxon_field = array('name' => $name, 'type' => 'enum', 'require' => $require, 'options' => array('items' => $items, 'max' => $max, 'openOnFocus' => true, 'markSearch' => true), 'html' => array('caption' => $caption, 'attr' => $attr)); if ($subtype == 'tag') { $taxon_field['options']['onNew'] = 'function(event) { event.item.style = "background-color: rgb(255, 232, 232); border: 1px solid red;";}'; } } else { // boolean $taxon_field = array('name' => $name, 'type' => 'toggle', 'require' => $require, 'html' => array('caption' => $caption)); } return $taxon_field; }
/** * Allow formatters to load information for field values being displayed. * * This should be used when a formatter needs to load additional information * from the database in order to render a field, for example a reference field * which displays properties of the referenced entities such as name or type. * * This hook is called after the field type's own hook_field_prepare_view(). * * Unlike most other field hooks, this hook operates on multiple entities. The * $entities, $instances and $items parameters are arrays keyed by entity ID. * For performance reasons, information for all available entities should be * loaded in a single query where possible. * * @param $entity_type * The type of $entity. * @param $entities * Array of entities being displayed, keyed by entity ID. * @param $field * The field structure for the operation. * @param $instances * Array of instance structures for $field for each entity, keyed by entity * ID. * @param $langcode * The language the field values are to be shown in. If no language is * provided the current language is used. * @param $items * Array of field values for the entities, keyed by entity ID. * @param $displays * Array of display settings to use for each entity, keyed by entity ID. * * @return * Changes or additions to field values are done by altering the $items * parameter by reference. */ function hook_field_formatter_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items, $displays) { $tids = array(); // Collect every possible term attached to any of the fieldable entities. foreach ($entities as $id => $entity) { foreach ($items[$id] as $delta => $item) { // Force the array key to prevent duplicates. $tids[$item['tid']] = $item['tid']; } } if ($tids) { $terms = taxonomy_term_load_multiple($tids); // Iterate through the fieldable entities again to attach the loaded term // data. foreach ($entities as $id => $entity) { $rekey = FALSE; foreach ($items[$id] as $delta => $item) { // Check whether the taxonomy term field instance value could be loaded. if (isset($terms[$item['tid']])) { // Replace the instance value with the term data. $items[$id][$delta]['taxonomy_term'] = $terms[$item['tid']]; } else { unset($items[$id][$delta]); $rekey = TRUE; } } if ($rekey) { // Rekey the items array. $items[$id] = array_values($items[$id]); } } } }
function bootstrap_theme_dashboard_contribute_create_form_submit(&$form, &$form_state) { global $user; $contribution = new stdClass(); $contribution->type = NODE_TYPE_CLAS_CONTRIBUTOR; $contribution->status = NODE_NOT_PUBLISHED; $contribution->language = LANGUAGE_NONE; $contribution->uid = $user->uid; $term = taxonomy_term_load($form_state['values']['cno_learning_object_type']); $termname = $term->name; if (!empty($form_state['values']['cno_associated_materials'])) { $file = file_load($form_state['values']['cno_associated_materials']); } else { $file = file_managed_file_save_upload($form['cno_associated_materials']); } if (!empty($form_state['values']['cnob_photo'])) { $photo = file_load($form_state['values']['cnob_photo']); } else { $photo = file_managed_file_save_upload($form['cnob_photo']); } if ($termname == 'Audio') { if (!empty($form_state['values']['cno_lobj_res_audio'])) { $audio_file = file_load($form_state['values']['cno_lobj_res_audio']); //$fname_arr = explode("://",$audio_file->uri); //file_move($audio_file, "public://".$fname_arr[1], FILE_EXISTS_RENAME); $contribution->field_cnob_learn_obj_res_audio[$contribution->language][0] = array('fid' => $audio_file->fid, 'display' => 1); } else { $audio_file = file_managed_file_save_upload($form['cno_lobj_res_audio']); } } /*if (!empty($form_state['values']['cno_lobj_res_video'])) { $video_file = file_load($form_state['values']['cno_lobj_res_video']); $contribution->field_cnob_learn_obj_res_video[$contribution->language][0] = array('fid' => $video_file->fid,'display' => 1); } else { $video_file = file_managed_file_save_upload($form['cno_lobj_res_video']); }*/ if ($termname == 'Document') { if (!empty($form_state['values']['cno_lobj_res_document'])) { $doc_file = file_load($form_state['values']['cno_lobj_res_document']); $contribution->field_cnob_learn_obj_res_doc[$contribution->language][0] = array('fid' => $doc_file->fid, 'display' => 1); } else { $doc_file = file_managed_file_save_upload($form['cno_lobj_res_document']); } } if ($termname == 'Link') { if (!empty($form_state['values']['cno_lobj_res_link'])) { $res_link = $form_state['values']['cno_lobj_res_link']; } else { $res_link = ''; } $contribution->field_cnob_learn_obj_res_link[$contribution->language][0]['value'] = $res_link; } $contribution->title = $form_state['values']['title']; $contribution->body[$contribution->language][0]['value'] = $form_state['values']['body']; $contribution->field_cnob_user_type[$contribution->language][0]['value'] = $form_state['values']['cno_type']; $contribution->field_cnob_category[$contribution->language][0]['tid'] = $form_state['values']['cno_category']; $contribution->field_cnob_learning_object_type[$contribution->language][0]['tid'] = $form_state['values']['cno_learning_object_type']; if ($termname == 'Video') { $contribution->field_cnob_learn_obj_res_video[$contribution->language][0]['video_url'] = $form_state['values']['cno_lobj_res_video']; } $contribution->field_cnob_area_of_study[$contribution->language][0]['tid'] = $form_state['values']['cno_area_of_study']; $contribution->field_cnob_grade_level[$contribution->language][0]['tid'] = $form_state['values']['cno_grade_level']; $contribution->field_cnob_expiration_date[$contribution->language][0]['value'] = date('Y-m-d', strtotime($form_state['values']['expiration_date'])); $contribution->field_cnob_collections[$contribution->language][0]['nid'] = $form_state['values']['og_group_ref']; $contribution->og_group_ref[$contribution->language][0]['target_id'] = $form_state['values']['og_group_ref']; $contribution->field_cnob_content_area[$contribution->language][0] = array('tid' => $form_state['values']['cno_content_area']); $contribution->group_content_access[$contribution->language][0]['value'] = OG_CONTENT_ACCESS_PRIVATE; $contribution->cnob_content_area[$contribution->language][0]['value'] = OG_CONTENT_ACCESS_PRIVATE; //$contribution->field_cnob_relevant_standards[$contribution->language][0]['tid'] = $form_state['values']['cno_relevant_standards']; $contribution->field_cnob_lesson_plan[$contribution->language][0]['value'] = $form_state['values']['lesson_plan']; $contribution->field_cnob_assigned_badge[$contribution->language][0]['value'] = $form_state['values']['cno_badge']; if ($file) { $contribution->field_cnob_associated_materials[$contribution->language][0] = array('fid' => $file->fid, 'display' => 1); } if ($photo) { $contribution->field_cnob_photo[$contribution->language][0] = array('fid' => $photo->fid, 'display' => 1); } $contribution->field_cnob_comments[$contribution->language][0]['value'] = $form_state['values']['comments']; //////Tags//// $tags = $form_state['values']['tags']; $typed_terms = drupal_explode_tags($tags); $tags_vocabulary = taxonomy_vocabulary_load(TAXONOMY_VOCABULARY_ID_TAGS); $value_tags = array(); foreach ($typed_terms as $typed_term) { if ($possibilities = taxonomy_term_load_multiple(array(), array('name' => trim($typed_term), 'vid' => array(TAXONOMY_VOCABULARY_ID_TAGS)))) { $term = array_pop($possibilities); } else { $vocabulary = $tags_vocabulary; $term = array('tid' => 'autocreate', 'vid' => $vocabulary->vid, 'name' => $typed_term, 'vocabulary_machine_name' => $vocabulary->machine_name); } $value_tags[] = (array) $term; } $contribution->field_cnob_tags[$contribution->language] = $value_tags; //////Tags//// //////Relevant Standards//// $relevant_standards = $form_state['values']['cno_relevant_standards']; $typed_terms = drupal_explode_tags($relevant_standards); $rs_vocabulary = taxonomy_vocabulary_load(TAXONOMY_VOCABULARY_ID_RELEVANT_STANDARDS); $value_rs = array(); foreach ($typed_terms as $typed_term) { if ($possibilities = taxonomy_term_load_multiple(array(), array('name' => trim($typed_term), 'vid' => array(TAXONOMY_VOCABULARY_ID_TAGS)))) { $term = array_pop($possibilities); } else { $vocabulary = $rs_vocabulary; $term = array('tid' => 'autocreate', 'vid' => $vocabulary->vid, 'name' => $typed_term, 'vocabulary_machine_name' => $vocabulary->machine_name); } $value_rs[] = (array) $term; } $contribution->field_cnob_relevant_standards[$contribution->language] = $value_rs; //////Relevant Standards//// $userDetails = user_load($user->uid); $userRoles = $userDetails->roles; if (in_array('administrator', $userRoles) || in_array('editor', $userRoles)) { $contribution->field_cnob_is_featured[$contribution->language][0]['value'] = $form_state['values']['featured']; } $contribution->field_cnob_contributor[$contribution->language][0]['uid'] = $form_state['values']['cno_contributor']; node_object_prepare($contribution); //node_submit($contribution); //bootstrap_theme_node_presave($contribution); node_save($contribution); drupal_set_message('Created new contribution successfully.'); }
/** * Alter the results of node_view(). */ function hwpi_basetheme_node_view_alter(&$build) { // Persons, heavily modify the output to match the HC designs if ($build['#node']->type == 'person') { if ($build['#view_mode'] == 'sidebar_teaser') { $build['pic_bio']['#prefix'] = '<div class="pic-bio clearfix people-sidebar-teaser">'; } else { $build['pic_bio']['#prefix'] = '<div class="pic-bio clearfix">'; } $build['pic_bio']['#suffix'] = '</div>'; $build['pic_bio']['#weight'] = -9; if (isset($build['body'])) { $build['body']['#label_display'] = 'hidden'; $build['pic_bio']['body'] = $build['body']; unset($build['body']); } //join titles $title_field =& $build['field_professional_title']; if ($title_field) { $keys = array_filter(array_keys($title_field), 'is_numeric'); foreach ($keys as $key) { $titles[] = $title_field[$key]['#markup']; unset($title_field[$key]); } $glue = $build['#view_mode'] == 'sidebar_teaser' ? ', ' : "<br />\n"; $title_field[0] = array('#markup' => implode($glue, $titles)); } // We dont want the other fields on teasers if (in_array($build['#view_mode'], array('teaser', 'slide_teaser', 'no_image_teaser'))) { //move title, website. body $build['pic_bio']['body']['#weight'] = 5; foreach (array(0 => 'field_professional_title', 10 => 'field_website') as $weight => $field) { if (isset($build[$field])) { $build['pic_bio'][$field] = $build[$field]; $build['pic_bio'][$field]['#weight'] = $weight; unset($build[$field]); } } //hide the rest foreach (array('field_address') as $field) { if (isset($build[$field])) { unset($build[$field]); } } if (isset($build['field_email'])) { $email_plain = $build['field_email'][0]['#markup']; $build['field_email'][0]['#markup'] = '<a href="mailto:' . $email_plain . '">' . $email_plain . '</a>'; } // Newlines after website. if (isset($build['pic_bio']['field_website'])) { foreach (array_filter(array_keys($build['pic_bio']['field_website']), 'is_numeric') as $delta) { $item = $build['pic_bio']['field_website']['#items'][$delta]; $build['pic_bio']['field_website'][$delta]['#markup'] = l($item['title'], $item['url'], $item) . '<br />'; } } unset($build['links']['node']); return; } // Professional titles if (isset($build['field_professional_title'])) { $build['field_professional_title']['#label_display'] = 'hidden'; $build['field_professional_title']['#weight'] = -10; } if (isset($build['field_person_photo'])) { $build['field_person_photo']['#label_display'] = 'hidden'; $build['pic_bio']['field_person_photo'] = $build['field_person_photo']; unset($build['field_person_photo']); } $children = element_children($build['pic_bio']); if (empty($children)) { $build['pic_bio']['#access'] = false; } // Note that Contact and Website details will print wrappers and titles regardless of any field content. // This is kind of deliberate to avoid having to handle the complexity of dealing with the layout or // setting messages etc. $block_zebra = 0; // Contact Details if ($build['#view_mode'] != 'sidebar_teaser') { $build['contact_details']['#prefix'] = '<div class="block contact-details ' . ($block_zebra++ % 2 ? 'even' : 'odd') . '"><div class="block-inner"><h2 class="block-title">Contact Information</h2>'; $build['contact_details']['#suffix'] = '</div></div>'; $build['contact_details']['#weight'] = -8; // Contact Details > address if (isset($build['field_address'])) { $build['field_address']['#label_display'] = 'hidden'; $build['contact_details']['field_address'] = $build['field_address']; $build['contact_details']['field_address'][0]['#markup'] = str_replace("\n", '<br>', $build['contact_details']['field_address'][0]['#markup']); unset($build['field_address']); } // Contact Details > email if (isset($build['field_email'])) { $build['field_email']['#label_display'] = 'inline'; $email_plain = mb_strtolower($build['field_email'][0]['#markup']); if ($email_plain) { $build['field_email'][0]['#markup'] = l($email_plain, 'mailto:' . $email_plain, array('absolute' => TRUE)); } $build['contact_details']['field_email'] = $build['field_email']; $build['contact_details']['field_email']['#weight'] = -50; unset($build['field_email']); } // Contact Details > phone if (isset($build['field_phone'])) { $build['field_phone']['#label_display'] = 'hidden'; $phone_plain = $build['field_phone'][0]['#markup']; if ($phone_plain) { $build['field_phone'][0]['#markup'] = t('p: ') . $phone_plain; } $build['contact_details']['field_phone'] = $build['field_phone']; $build['contact_details']['field_phone']['#weight'] = 50; unset($build['field_phone']); } // Websites if (isset($build['field_website'])) { $build['website_details']['#prefix'] = '<div class="block website-details ' . ($block_zebra++ % 2 ? 'even' : 'odd') . '"><div class="block-inner"><h2 class="block-title">Websites</h2>'; $build['website_details']['#suffix'] = '</div></div>'; $build['website_details']['#weight'] = -7; $build['field_website']['#label_display'] = 'hidden'; $build['website_details']['field_website'] = $build['field_website']; unset($build['field_website']); } //Don't show an empty contact details section. if (!element_children($build['contact_details'])) { unset($build['contact_details']); } } if (isset($build['og_vocabulary'])) { $terms = array(); foreach ($build['og_vocabulary']['#items'] as $i) { if (isset($i['target_id'])) { $terms[] = $i['target_id']; } else { $terms[] = $i; } } $terms = vsite_vocab_sort_weight_alpha(taxonomy_term_load_multiple($terms)); foreach ($terms as $info) { $v = taxonomy_vocabulary_load($info['vid']); if (!isset($build[$v->machine_name])) { $m = $v->machine_name; $build[$m] = array('#type' => 'container', '#weight' => $block_zebra, '#attributes' => array('class' => array('block', $m, $block_zebra++ % 2 ? 'even' : 'odd')), 'inner' => array('#type' => 'container', '#attributes' => array('class' => array('block-inner')), 'title' => array('#markup' => '<h2 class="block-title">' . $v->name . '</h2>'))); } $build[$v->machine_name]['inner'][$info['tid']] = array('#prefix' => '<div>', '#suffix' => '</div>', '#theme' => 'link', '#path' => $info['uri'], '#text' => $info['term'], '#options' => array('attributes' => array(), 'html' => false)); } unset($build['og_vocabulary']); } } }
function _bvng_get_tag_links(&$field_items, &$item_list) { $terms = taxonomy_term_load_multiple($field_items); foreach ($terms as $term) { $uri = taxonomy_term_uri($term); $tag_link = l($term->name, $uri['path']); array_push($item_list['items'], array('data' => $tag_link)); } }