示例#1
0
/**
 * 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;
    }
}
/**
 * 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();
}
 /**
  * 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);
 }
 /**
  * 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;
 }
 /**
  * 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();
 }
 /**
  * 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));
 }
示例#7
0
 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('*****@*****.**', '*****@*****.**', 'ADN Perros ' . 'Nuevo vial de ' . $paquete->getAyuntamiento(), $mensaje);
                 simple_mail_queue('*****@*****.**', '*****@*****.**', 'ADN Perros ' . 'Nuevo vial de ' . $paquete->getAyuntamiento(), $mensaje);
             }
             $ewrapperCaja->save();
             return TRUE;
         }
     }
     return FALSE;
 }
 /**
  * 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());
 }
示例#9
0
/**
 * 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;
}
 /**
  * {@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;
 }
 /**
  * {@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);
 }
 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);
 }
示例#13
0
/**
 * _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();
}
示例#14
0
/**
 * 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;
    }
}
/**
 * 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;
    }
}
/**
 * Obtenir tous les produits d'une commande en drupal commerce
 * @param $order
 * @return array
 */
function commerce_get_products_by_order($order)
{
    foreach (entity_metadata_wrapper('commerce_order', $order)->commerce_line_items as $delta => $line_item_wrapper) {
        if (in_array($line_item_wrapper->type->value(), commerce_product_line_item_types())) {
            $product_ids[] = $line_item_wrapper->commerce_product->raw();
        }
    }
    return $product_ids;
}
 public function generatePaymentToken($order, $payment_method)
 {
     global $user;
     $config = array();
     $shippingAddressConfig = null;
     $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
     $billing_address = $order_wrapper->commerce_customer_billing->commerce_customer_address->value();
     $order_array = $order_wrapper->commerce_order_total->value();
     $product_line_items = $order->commerce_line_items[LANGUAGE_NONE];
     if (isset($order)) {
         $orderId = $order->order_id;
         $default_currency = commerce_default_currency();
         $amountCents = number_format(commerce_currency_convert($order->commerce_order_total['und'][0]['amount'], $order_array['currency_code'], $default_currency), 0, '', '');
         $scretKey = $payment_method['settings']['private_key'];
         $mode = $payment_method['settings']['mode'];
         $timeout = $payment_method['settings']['timeout'];
         $config['authorization'] = $scretKey;
         $config['mode'] = $mode;
         $config['timeout'] = $timeout;
         if ($payment_method['settings']['payment_action'] == 'authorize') {
             $config = array_merge($config, $this->_authorizeConfig());
         } else {
             $config = array_merge($config, $this->_captureConfig($payment_method));
         }
         $products = array();
         if (!empty($product_line_items)) {
             foreach ($product_line_items as $key => $item) {
                 $line_item[$key] = commerce_line_item_load($item['line_item_id']);
                 $product_id = $line_item[$key]->commerce_product['und'][0]['product_id'];
                 $product = commerce_product_load($product_id);
                 $price = commerce_product_calculate_sell_price($product);
                 $sell_price = number_format(commerce_currency_amount_to_decimal($price['amount'], $price['currency_code']), 2, '.', '');
                 $products[$key] = array('name' => commerce_line_item_title($line_item[$key]), 'sku' => $line_item[$key]->line_item_label, 'price' => $sell_price, 'quantity' => (int) $line_item[$key]->quantity);
             }
         }
         $billingAddressConfig = array('addressLine1' => $billing_address['thoroughfare'], 'addressLine2' => $billing_address['premise'], 'postcode' => $billing_address['postal_code'], 'country' => $billing_address['country'], 'city' => $billing_address['locality']);
         if (module_exists('commerce_shipping') && !empty($order_wrapper->commerce_customer_shipping->commerce_customer_address)) {
             $shipping_address = $order_wrapper->commerce_customer_shipping->commerce_customer_address->value();
             // Add the shipping address parameters to the request.
             $shippingAddressConfig = array('addressLine1' => $shipping_address['thoroughfare'], 'addressLine2' => $shipping_address['premise'], 'postcode' => $shipping_address['postal_code'], 'country' => $shipping_address['country'], 'city' => $shipping_address['locality']);
         }
         $config['postedParam'] = array_merge($config['postedParam'], array('email' => $order->mail, 'value' => $amountCents, 'trackId' => $orderId, 'currency' => $default_currency, 'description' => 'Order number::' . $orderId, 'shippingDetails' => $shippingAddressConfig, 'products' => $products, 'card' => array('billingDetails' => $billingAddressConfig)));
         $Api = CheckoutApi_Api::getApi(array('mode' => $mode));
         $paymentTokenCharge = $Api->getPaymentToken($config);
         $paymentTokenArray = array('message' => '', 'success' => '', 'eventId' => '', 'token' => '');
         if ($paymentTokenCharge->isValid()) {
             $paymentTokenArray['token'] = $paymentTokenCharge->getId();
             $paymentTokenArray['success'] = true;
         } else {
             $paymentTokenArray['message'] = $paymentTokenCharge->getExceptionState()->getErrorMessage();
             $paymentTokenArray['success'] = false;
             $paymentTokenArray['eventId'] = $paymentTokenCharge->getEventId();
         }
     }
     return $paymentTokenArray;
 }
 /**
  * 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));
     // Assume meter will have electricity
     // @fixme: Should move to NegawattElectricityMigrate, that will update the meter node.
     $wrapper->field_has_electricity->set(TRUE);
 }
示例#19
0
/**
 * Sends the invitation.
 *
 * Called by the Invite::sendInvite() method.
 *
 * @param Invite $invite
 *   The invitation to send.
 */
function hook_invite_send($invite)
{
    if (!empty($invite->type_details()->invite_sending_controller['my_module'])) {
        global $language;
        $entity = entity_metadata_wrapper('invite', $invite);
        $params = array('invite' => $invite, 'wrapper' => $entity);
        $from = $entity->inviter->mail->value();
        drupal_mail('my_module', 'invite', $entity->invitee->mail->value(), $language, $params, $from, TRUE);
    }
}
 /**
  * Gets ids of existing entities in the queue.
  *
  * @return array
  *   Entity ids that are currently referenced by the entity.
  */
 public function getCurrentlyReferencedEntityIds()
 {
     $ret = array();
     if (isset($this->entity) && isset($this->field)) {
         $entity_type = $this->entity_type;
         $field_name = $this->field['field_name'];
         $wrapper = entity_metadata_wrapper($entity_type, $this->entity);
         $ret = $wrapper->{$field_name}->raw();
     }
     return $ret;
 }
 /**
  * Edits a publication in facebook from a stored entity. Events in Facebook
  * can actually be updated, this means that there is no deletion needed.
  *
  * @param FacebookPublicationEntity $publication
  *   The fully loaded Facebook publication entity
  *
  * @throws FBAutopostException
  * @see FBAutopost::remoteEdit()
  */
 public function remoteEntityEdit(FacebookPublicationEntity $publication_entity)
 {
     // For an event we should update the Entity, instead of deleting an
     // recreating it.
     $wrapper = entity_metadata_wrapper('facebook_publication', $publication_entity);
     $remote_id = $wrapper->facebook_id->value();
     $publication = array('type' => $publication_entity->type, 'params' => fb_autopost_entity_get_properties($publication_entity));
     $this->publishParameterPrepare($publication);
     // Call api method from ancestor.
     return $this->api('/' . $remote_id, 'POST', $publication['params']);
 }
示例#22
0
/**
 * Act on the contact when the link to a drupal user account is modified
 *
 * @param string $op ( insert | update | delete )
 * @param $contact
 *  The RedhenContact object with the new user drupal user info
 * @param $old_contact
 *  The RedhenContact object with the old user info
 *
 * @return void
 */
function hook_redhen_contact_user_update($op, RedhenContact $contact, $old_contact = NULL)
{
    // Send "Welcome (no approval required)" email to new user.
    if ($op == 'insert') {
        $wrapper = entity_metadata_wrapper('redhen_contact', $contact);
        // Set _user_mail_notify specific operation.
        $op = 'register_no_approval_required';
        // Send an email.
        _user_mail_notify($op, $wrapper->user->value());
    }
}
示例#23
0
function hc_bootstrap_commerce_product_reference_default_delta_alter(&$delta, $products)
{
    foreach ($products as $key => $product) {
        $p_wrapper = entity_metadata_wrapper('commerce_product', $product);
        $stock = $p_wrapper->commerce_stock->value();
        if ($stock > 0) {
            $delta = $key;
            break;
        }
    }
}
示例#24
0
 /**
  * Create an Editorial Team.
  *
  * @param string $title
  *    Editorial team name.
  * @param string $group_content_access
  *    Define group content access public regardless of its group definition.
  *    Either OG_CONTENT_ACCESS_PUBLIC or OG_CONTENT_ACCESS_PRIVATE.
  *
  * @return int
  *    Newly created editorial team node NID.
  */
 public function createEditorialTeam($title, $group_content_access = OG_CONTENT_ACCESS_PUBLIC)
 {
     $properties = array('type' => 'editorial_team', 'uid' => 1, 'status' => 1, 'promote' => 0);
     $entity = entity_create('node', $properties);
     $wrapper = entity_metadata_wrapper('node', $entity);
     $wrapper->title->set($title);
     $wrapper->comment = COMMENT_NODE_CLOSED;
     $wrapper->{OG_ACCESS_FIELD}->set($group_content_access);
     $wrapper->{OG_DEFAULT_ACCESS_FIELD}->set(0);
     $wrapper->save(TRUE);
     return $wrapper->getIdentifier();
 }
示例#25
0
/**
 * Implements hook_process_node().
 */
function sociale_platforme_process_node(&$variables, $hook)
{
    $node = $variables['node'];
    $wrapper = entity_metadata_wrapper('node', $node);
    // Use timeago module for formatting node submission date
    // if it is enabled and also configured to be used on nodes.
    if (module_exists('timeago') && variable_get('timeago_node', 1)) {
        $variables['date'] = timeago_format_date($node->created, $variables['date']);
        $use_timeago_date_format = TRUE;
    } else {
        $use_timeago_date_format = FALSE;
    }
    // Replace the submitted text on nodes with something a bit more pertinent to
    // the content type.
    if (variable_get('node_submitted_' . $node->type, TRUE)) {
        $node_type_info = node_type_get_type($variables['node']);
        $type_attributes = array('class' => array('node-content-type', drupal_html_class('node-content-type-' . $node->type)));
        $placeholders = array('!type' => '<span' . drupal_attributes($type_attributes) . '>' . check_plain($node_type_info->name) . '</span>', '!user' => $variables['name'], '!date' => $variables['date'], '@interval' => format_interval(REQUEST_TIME - $node->created));
        // Show what group the content belongs to if applicable.
        if (!empty($node->{OG_AUDIENCE_FIELD}) && $wrapper->{OG_AUDIENCE_FIELD}->count() == 1) {
            $placeholders['!group'] = l($wrapper->{OG_AUDIENCE_FIELD}->get(0)->label(), 'node/' . $wrapper->{OG_AUDIENCE_FIELD}->get(0)->getIdentifier());
            if ($use_timeago_date_format == TRUE) {
                $variables['submitted'] = t('!type created !date in the !group group by !user', $placeholders);
            } else {
                $variables['submitted'] = t('!type created @interval ago in the !group group by !user', $placeholders);
            }
        } else {
            if ($use_timeago_date_format == TRUE) {
                $variables['submitted'] = t('!type created !date by !user', $placeholders);
            } else {
                $variables['submitted'] = t('!type created @interval ago by !user', $placeholders);
            }
        }
    }
    // Append a feature label to featured node teasers.
    if ($variables['teaser'] && $variables['promote']) {
        $variables['submitted'] .= ' <span class="featured-node-tooltip">' . t('Featured') . ' ' . $variables['type'] . '</span>';
    }
    // Provide theme suggestions for view mode node templates
    $view_mode = $variables['view_mode'];
    $content_type = $variables['type'];
    $variables['theme_hook_suggestions'][] = 'node__' . $view_mode;
    $variables['theme_hook_suggestions'][] = 'node__' . $view_mode . '_' . $content_type;
    $view_mode_preprocess = 'THEME_preprocess_node_' . $view_mode . '_' . $content_type;
    if (function_exists($view_mode_preprocess)) {
        $view_mode_preprocess($variables, $hook);
    }
    $view_mode_preprocess = 'THEME_preprocess_node_' . $view_mode;
    if (function_exists($view_mode_preprocess)) {
        $view_mode_preprocess($variables, $hook);
    }
}
 /**
  * Deletes a publication from facebook stored in an entity.
  *
  * @param FacebookPublicationEntity $publication
  *   The fully loaded Facebook publication entity.
  *
  * @return boolean
  *   TRUE if the publication was deleted successfully.
  *
  * @throws FBAutopostException
  * @see FBAutopost::remoteDelete()
  */
 public function remoteEntityDelete(FacebookPublicationEntity $publication)
 {
     // Get a wrapper for the entity and extract the remote ID.
     $wrapper = entity_metadata_wrapper('facebook_publication', $publication);
     $remote_id = $wrapper->facebook_id->value();
     // If there is a remote ID in return, then delete the associated
     // publication.
     if (!empty($remote_id)) {
         return parent::remoteDelete($remote_id);
     } else {
         throw new FBAutopostException(t('Remote ID could not be found.'), FBAutopost::missing_param, WATCHDOG_ERROR);
     }
 }
示例#27
0
/**
 * Export node to XML
 * @param $node node to serialize
 * @param $temp_folder_path folder where to copy attachments
 * @return XML as a string
 */
function hook_mica_export_to_xml($node, $temp_folder_path)
{
    $wrapper = entity_metadata_wrapper('node', $node);
    if ($node->type === 'study') {
        mica_export_copy_attachment_file($wrapper->field_files->value(), $temp_folder_path);
        $dom = new DomDocument('1.0', 'utf-8');
        $root = $dom->createElement($node->type);
        $root->setAttribute('uuid', $wrapper->uuid->value());
        $dom->appendChild($root);
        return $dom->saveXML();
    }
    return NULL;
}
示例#28
0
/**
 * Allow modules to mark group privacy change.
 *
 * @param $result
 *   Array of results of the hooks called before.
 * @param array $context
 *   Array with the following keys:
 *   'entity': the group entity.
 *   'entity_type':  The group type.
 */
function hook_og_access_invoke_node_access_acquire_grants_alter(&$result, $context)
{
    $wrapper = entity_metadata_wrapper($context['entity_type'], $context['entity']);
    if (!isset($wrapper->OG_ACCESS_FIELD)) {
        // Group doesn't have OG access field attached to it.
        return;
    }
    $original_wrapper = entity_metadata_wrapper($context['entity_type'], $context['entity']->original);
    $og_access = $wrapper->{OG_ACCESS_FIELD}->value();
    $original_og_access = $original_wrapper->{OG_ACCESS_FIELD}->value();
    if ($og_access !== $original_og_access) {
        $result['my_module'] = TRUE;
    }
}
/**
 * Alter user claims about the provided account.
 *
 * The provided claims can be included in the id_token and / or returned from
 * the /oauth2/UserInfo endpoint.
 *
 * Groups of claims are returned based on the requested scopes. No group
 * is required, and no claim is required.
 *
 * @param array &$claims
 *   Existing claims provided by OAuth2 Server or other modules.
 * @param object $account
 *   The user account for which claims should be returned.
 * @param array $requested_scopes
 *   The requested scopes.
 *
 * @see hook_oauth2_server_user_claims()
 *
 * @see http://openid.net/specs/openid-connect-core-1_0.html#ScopeClaims
 */
function hook_oauth2_server_user_claims_alter(&$claims, $account, $requested_scopes)
{
    $wrapper = entity_metadata_wrapper('user', $account);
    // Example: add the birthday from a custom field, if the 'profile' scope is
    // requested.
    if (in_array('profile', $requested_scopes) && !empty($wrapper->field_birthday)) {
        $claims['birthdate'] = date('0000-m-d', strtotime($wrapper->field_birthday->value()));
    }
    // Example: add the phone number from a custom field, if the 'phone' scope is
    // requested.
    if (in_array('phone', $requested_scopes) && !empty($wrapper->field_phone)) {
        $claims += array('phone_number' => date('0000-m-d', strtotime($wrapper->field_phone->value())), 'phone_number_verified' => FALSE);
    }
}
示例#30
0
/**
 * Implements hook_preprocess_node().
 */
function eventcollective_preprocess_node(&$variables)
{
    global $user;
    if ($variables['view_mode'] == 'teaser') {
        $variables['theme_hook_suggestions'][] = 'node__' . $variables['node']->type . '__teaser';
        $variables['theme_hook_suggestions'][] = 'node__' . $variables['node']->nid . '__teaser';
    }
    if ($variables['type'] == 'event') {
        if ($variables['view_mode'] == 'teaser') {
            // dpm_once($variables);
            $nw = entity_metadata_wrapper('node', $variables['nid']);
        }
    }
}