当前位置: 首页>>代码示例>>PHP>>正文


PHP entity_metadata_wrapper函数代码示例

本文整理汇总了PHP中entity_metadata_wrapper函数的典型用法代码示例。如果您正苦于以下问题:PHP entity_metadata_wrapper函数的具体用法?PHP entity_metadata_wrapper怎么用?PHP entity_metadata_wrapper使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了entity_metadata_wrapper函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: joost_preprocess_node

/**
 * Override or insert variables into the node templates.
 */
function joost_preprocess_node(&$vars)
{
    switch ($vars['type']) {
        case 'ready_made_':
            foreach ($vars['node']->field_ready_made_ref[LANGUAGE_NONE] as $product_id) {
                $product_ids[] = $product_id['product_id'];
                // dsm($product_id);
                //dsm($product_ids);
            }
            $products = commerce_product_load_multiple($product_ids);
            $product_prices = array();
            foreach ($products as $product_id => $product) {
                $product_wrapper = entity_metadata_wrapper('commerce_product', $product);
                $product_prices[] = $product_wrapper->commerce_price->amount->value();
                $count_prices = count($product_prices);
                // dsm($count_prices);
            }
            sort($product_prices, SORT_NUMERIC);
            $lower = commerce_currency_format(reset($product_prices), 'GBP');
            $upper = commerce_currency_format(end($product_prices), 'GBP');
            $price_range = "{$lower} - {$upper}";
            $price_lower = "{$lower}";
            if ($count_prices == 1) {
                $vars['content']['product:commerce_price'][0]['#markup'] = $price_lower;
            } else {
                $vars['content']['product:commerce_price'][0]['#markup'] = $price_range;
            }
            break;
    }
}
开发者ID:rodvolpe,项目名称:Blinds,代码行数:33,代码来源:template.php

示例2: hook_repeating_date_update

/**
 * Used to update a date instance in a date series.
 *
 * @param object $date_entity
 *   An instance of a date entity in a series.
 * @param object $updated_entity
 *   The updated entity.
 * @param string $entity_type
 *   The type of entity.
 */
function hook_repeating_date_update($date_entity, $updated_entity, $entity_type = 'node')
{
    $date_entity_wrapper = entity_metadata_wrapper($entity_type, $date_entity);
    $updated_entity_wrapper = entity_metadata_wrapper($entity_type, $updated_entity);
    // Update date entity title from updated entity.
    $date_entity_wrapper->title = $updated_entity_wrapper->label();
}
开发者ID:Global-Shelter-Cluster,项目名称:website,代码行数:17,代码来源:date_repeat_entity.api.php

示例3: prepare

 /**
  * Map location field.
  *
  * @todo: Move to value callback.
  */
 public function prepare($entity, $row)
 {
     list($lat, $lng) = explode('|', $row->_location);
     $wrapper = entity_metadata_wrapper('node', $entity);
     $values = array('lat' => $lat, 'lng' => $lng);
     $wrapper->field_location->set($values);
 }
开发者ID:vinodpanicker,项目名称:generator-hedley,代码行数:12,代码来源:SkeletonEventsMigrate.php

示例4: groupAudiencegetDiff

 /**
  * Get the difference in group audience for a saved field.
  *
  * @return
  *   Array with all the differences, or an empty array if none found.
  */
 public function groupAudiencegetDiff($entity_type, $entity, $field, $instance, $langcode, $items)
 {
     $return = FALSE;
     $field_name = $field['field_name'];
     $wrapper = entity_metadata_wrapper($entity_type, $entity);
     $og_memberships = $wrapper->{$field_name . '__og_membership'}->value();
     $new_memberships = array();
     foreach ($items as $item) {
         $new_memberships[$item['target_id']] = TRUE;
     }
     foreach ($og_memberships as $og_membership) {
         $gid = $og_membership->gid;
         if (empty($new_memberships[$gid])) {
             // Membership was deleted.
             if ($og_membership->entity_type == 'user') {
                 // Make sure this is not the group manager, if exists.
                 $group = entity_load_single($og_membership->group_type, $og_membership->gid);
                 if (!empty($group->uid) && $group->uid == $og_membership->etid) {
                     continue;
                 }
             }
             $return['delete'][] = $og_membership->id;
             unset($new_memberships[$gid]);
         } else {
             // Existing membership.
             unset($new_memberships[$gid]);
         }
     }
     if ($new_memberships) {
         // New memberships.
         $return['insert'] = array_keys($new_memberships);
     }
     return $return;
 }
开发者ID:natemudd,项目名称:drupal-test-environment,代码行数:40,代码来源:OgBehaviorHandler.class.php

示例5: getBoxFolderID

 /**
  * Helper function to get the Box id number from the node. Includes
  * a check to see if the node is an organic group or not.
  */
 public static function getBoxFolderID($gid)
 {
     // Is session active
     self::isSessionActive();
     $node = node_load($gid);
     // ->soc_boxgroup_folder
     // if not group
     if (!og_is_group('node', $node)) {
         $msg = t('@node_title is not an Group', ['@node_title' => $node->title]);
         watchdog(self::BOX_OPERATIONS_NAME, $msg);
         drupal_set_message($msg, 'error');
         return FALSE;
     }
     // return URL if we can
     $ent = entity_metadata_wrapper('node', $node);
     $box_id = $ent->soc_boxgroup_folder->value();
     // if field is blank
     if (is_null($box_id)) {
         $msg = t('@node_title does not have a box folder url assigned to it', ['@node_title' => $node->title]);
         watchdog(SOC_BOXGROUP_MODULE_NAME, $msg);
         drupal_set_message($msg, 'error');
         return FALSE;
     }
     // is it not numeric
     if (!is_numeric($box_id)) {
         watchdog(SOC_BOXGROUP_MODULE_NAME, t('@node_title (@nid) does not have a numeric folder id assigned to it', ['@node_title' => $node->title, '@nid' => $node->nid]));
         return FALSE;
     }
     // Lastly, if we get this far, just return the value;
     return $ent->soc_boxgroup_folder->value();
 }
开发者ID:rgoodie,项目名称:soc_boxauth,代码行数:35,代码来源:BoxFolderOperations.class.php

示例6: prepare

 /**
  * Map field_location and field_address fields.
  */
 public function prepare($entity, $row)
 {
     $row->field_location = explode('|', $row->field_location);
     $wrapper = entity_metadata_wrapper('node', $entity);
     $wrapper->field_location->set(array('lat' => $row->field_location[0], 'lng' => $row->field_location[1]));
     $wrapper->field_address->set(array('country' => $row->country, 'locality' => $row->field_place_locality));
 }
开发者ID:Gizra,项目名称:negawatt-server,代码行数:10,代码来源:NegawattModbusMeterMigrate.php

示例7: update

 public static function update($paquete)
 {
     if ($idCaja = BbiCaja::getIdCaja($paquete->getTituloVial())) {
         if ($caja = node_load($idCaja)) {
             $ewrapperCaja = entity_metadata_wrapper('node', $caja);
             //Le metemos la fecha, si no hay ninguan todavía...
             if (!isset($caja->field_caja_fec_primer_vial_lleno['und'][0]['value'])) {
                 $ewrapperCaja->field_caja_fec_primer_vial_lleno->set($paquete->getFechaVialLleno());
             }
             //Le sumamos 1 a viales llenos si no tienen ya fecha de extracción,
             //quiere decir que ya se metió en la tienda antes.
             $vial = node_load(bbiLab_getIdNodeByTitle($paquete->getTituloVial()));
             if (!isset($vial->field_vial_fecha_de_extracci_n['und'][0]['value'])) {
                 $vialesEnCaja = (int) $ewrapperCaja->field_caja_viales_llenos->value() + 1;
                 $ewrapperCaja->field_caja_viales_llenos->set((int) $vialesEnCaja);
                 //Ahora que sabemos que este vial es la primera vez que entra, se puede mandar un email al jefe...
                 $mensaje = 'Ha entrado el vial ' . $paquete->getTituloVial() . ' proveniente del ayuntamiento de ' . $paquete->getAyuntamiento() . ' del veterinario ' . $paquete->getVeterinario();
                 simple_mail_queue('info@adnperros.es', 'dlopezbbi@gmail.com', 'ADN Perros ' . 'Nuevo vial de ' . $paquete->getAyuntamiento(), $mensaje);
                 simple_mail_queue('info@adnperros.es', 'j.ant.mateos@gmail.com', 'ADN Perros ' . 'Nuevo vial de ' . $paquete->getAyuntamiento(), $mensaje);
             }
             $ewrapperCaja->save();
             return TRUE;
         }
     }
     return FALSE;
 }
开发者ID:ignaxio,项目名称:conectorCentral,代码行数:26,代码来源:BbiCaja.php

示例8: createOrUpdateWorkSession

 /**
  * Create a new session or update an open session.
  */
 public function createOrUpdateWorkSession()
 {
     $request = $this->getRequest();
     $account = $this->getAccount();
     if (!user_access('timewatch punch')) {
         throw new RestfulForbiddenException('No punch access.');
     }
     if (empty($request['pincode'])) {
         throw new \RestfulBadRequestException('Pincode is required');
     }
     $uid = timewatch_session_get_uid_by_pincode($request['pincode']);
     if (!$uid) {
         throw new \RestfulBadRequestException('Wrong pincode');
     }
     $employee_account = user_load($uid);
     // Find an existing session with no end date.
     $query = new EntityFieldQuery();
     $result = $query->entityCondition('entity_type', 'node')->entityCondition('bundle', 'work_session')->propertyCondition('status', NODE_PUBLISHED)->fieldCondition('field_employee', 'target_id', $uid)->fieldCondition('field_session_date', 'value2', NULL)->range(0, 1)->execute();
     if (empty($result['node'])) {
         // When there's no open session, create a new one.
         $values = array('type' => 'work_session', 'uid' => $account->uid, 'status' => NODE_PUBLISHED, 'title' => format_string('@date - @user', array('@date' => date('d/m/y'), '@user' => $employee_account->name)));
         $node = entity_create('node', $values);
         $wrapper = entity_metadata_wrapper('node', $node);
         $wrapper->field_employee->set($uid);
         $wrapper->field_session_date->value->set(REQUEST_TIME);
     } else {
         // Otherwise set the end date of the open session.
         $wrapper = entity_metadata_wrapper('node', key($result['node']));
         $wrapper->field_session_date->value2->set(REQUEST_TIME);
     }
     $wrapper->save();
     return $this->viewEntity($wrapper->getIdentifier());
 }
开发者ID:Gizra,项目名称:timewatch-server,代码行数:36,代码来源:TimewatchPunchResource.class.php

示例9: hook_taxonomy_menu_link_alter

/**
 * Allows modules to alter the menu link before saved.
 *
 * @param $menu_link
 *   The menu link will be saved.
 * @param $term
 *   The taxonomy term
 * @param $menu_name
 *   The machine name of the menu in which the menu link should be saved.
 */
function hook_taxonomy_menu_link_alter(&$menu_link, $term, $menu_name)
{
    // For example, change the link_title and options
    $wrapper = entity_metadata_wrapper('taxonomy_term', $term);
    $menu_link['link_title'] .= '<span class="tibetan">' . $wrapper->field_tibetan_name->value() . '</span>';
    $menu_link['options']['html'] = TRUE;
}
开发者ID:DSP-e-learn,项目名称:e-learn,代码行数:17,代码来源:taxonomy_menu.api.php

示例10: process

 /**
  * {@inheritdoc}
  */
 public function process(array $data, $create_message = TRUE)
 {
     $meter_nid = 0;
     $return = array();
     $entities_of_frequency = $data[\NegaWattNormalizerTimeManagerInterface::MONTH];
     foreach ($entities_of_frequency as $timestamp => $entities_of_timeframe) {
         // Calc sum of kwh for the time-frame (i.e., sum over rate-types).
         $sum_kwh = 0;
         foreach ($entities_of_timeframe as $entity) {
             $sum_kwh += $entity->sum_kwh;
             $meter_nid = $entity->meter_nid;
         }
         // Look for an entity from a year ago
         $year_ago = strtotime('-1 year', $timestamp);
         $data_provider = $this->getDataProviderManager()->createDataProvider($year_ago, $year_ago, \NegaWattNormalizerTimeManagerInterface::MONTH, $meter_nid);
         // The data-provider will look first in data, if none were found, it'll look
         // in the normalized-electricity db.
         $prev_year_entities = $data_provider->fetchEntities($data);
         $prev_year_sum_kwh = 0;
         foreach ($prev_year_entities as $entity) {
             $prev_year_sum_kwh += $entity->sum_kwh;
         }
         // If prev year's record was found, check that it does not differ by more than 10%
         if ($prev_year_sum_kwh) {
             $kwh_diff = $sum_kwh / $prev_year_sum_kwh;
             if ($kwh_diff < 0.9 || $kwh_diff > 1.1) {
                 // Consumed kWh difference is suspicious, put an alert
                 // Prepare message parameters.
                 $node_wrapper = entity_metadata_wrapper('node', $meter_nid);
                 $return[] = array('nid' => $meter_nid, 'message_type' => 'demand_deviate', 'meter_title' => $node_wrapper->label(), 'description' => $node_wrapper->field_place_description->value(), 'address' => $node_wrapper->field_place_address->value(), 'event_timestamp' => $timestamp, 'arguments' => array('@date' => date('Y-m', $timestamp), '@frequency' => 'month', '@cur_kwh' => $sum_kwh, '@prev_kwh' => $prev_year_sum_kwh));
             }
         }
     }
     return $return;
 }
开发者ID:Gizra,项目名称:negawatt-server,代码行数:38,代码来源:NegaWattAnalyzerCompareLastYear.php

示例11: setValue

 /**
  * {@inheritdoc}
  */
 public function setValue($value, array $mapping)
 {
     $info = $this->getPropertInfo();
     if (is_scalar($value)) {
         $wrapper = entity_metadata_wrapper($info['type'], $value);
     }
     parent::setValue($wrapper, $mapping);
 }
开发者ID:CodeElegance,项目名称:finsearches,代码行数:11,代码来源:FeedsEntityProcessorPropertyEntityType.php

示例12: buildContent

 public function buildContent($entity, $view_mode = 'full', $langcode = NULL, $content = array())
 {
     $wrapper = entity_metadata_wrapper('spotify_playlist_track', $entity);
     $content['author'] = array('#markup' => t('Created by: !author', array('!author' => $wrapper->uid->name->value(array('sanitize' => TRUE)))));
     // Make Description and Status themed like default fields.
     $content['description'] = array('#theme' => 'field', '#weight' => 0, '#title' => t('Track Description'), '#access' => TRUE, '#label_display' => 'above', '#view_mode' => 'full', '#language' => LANGUAGE_NONE, '#field_name' => 'field_fake_description', '#field_type' => 'text', '#entity_type' => 'spotify_playlist_track', '#bundle' => $entity->type, '#items' => array(array('value' => $entity->description)), '#formatter' => 'text_default', 0 => array('#markup' => check_plain($entity->description)));
     return parent::buildContent($entity, $view_mode, $langcode, $content);
 }
开发者ID:jobjol,项目名称:spotify-playlist,代码行数:8,代码来源:spotify_playlist.classes.php

示例13: _update_product

/**
 * _update_product
 */
function _update_product($param_array = NULL, $product)
{
    $wrapper = entity_metadata_wrapper('commerce_product', $product);
    $wrapper->field_product_brand->set($param_array['brand_tid']);
    $wrapper->field_product_description->set($param_array['description']);
    // $wrapper->field_chassis_configuration->set($param_array['description']);
    $wrapper->save();
}
开发者ID:temptemp5678,项目名称:onequote2,代码行数:11,代码来源:batch_save_node.php

示例14: hook_commerce_checkout_order_can_checkout

/**
 * Allows modules to confirm that an order may proceed to checkout.
 *
 * If any implementation of this hook returns TRUE, the given order can proceed
 * to checkout. However, if no implementations of this hook exist and return
 * TRUE, the checkout router will simply redirect away to the front page.
 *
 * @param $order
 *   The order being confirmed for checkout.
 *
 * @return
 *   Boolean value indicating whether or not the order can proceed to checkout.
 */
function hook_commerce_checkout_order_can_checkout($order)
{
    // Allow orders with one or more product line items to proceed to checkout.
    // If there are no line items on the order, redirect away.
    $wrapper = entity_metadata_wrapper('commerce_order', $order);
    if (commerce_line_items_quantity($wrapper->commerce_line_items, commerce_product_line_item_types()) > 0) {
        return TRUE;
    }
}
开发者ID:drupdateio,项目名称:gvj,代码行数:22,代码来源:commerce_checkout.api.php

示例15: hook_commerce_stock_reserve_set_product_stock

/**
 * Set the current stock level for a product.
 *
 * This helps sites that have their own stock storage (instead of Commerce
 * Simple Stock).
 *
 * The product should not be saved in implementations of this hook.
 *
 * @param object $product
 *   The Commerce product object.
 * @param mixed $stock
 *   The new stock level to set.
 *
 * @return mixed
 *   Return FALSE on failure. Any other return value will be ignored.
 */
function hook_commerce_stock_reserve_set_product_stock($product, $stock)
{
    if (isset($product->my_custom_stock_field)) {
        $product_wrapper = entity_metadata_wrapper('commerce_product', $product);
        $product_wrapper->my_custom_stock_field->set($stock);
    } else {
        return FALSE;
    }
}
开发者ID:TerraLudis,项目名称:shop,代码行数:25,代码来源:commerce_stock_reserve.api.php


注:本文中的entity_metadata_wrapper函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。