• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP entity_load_single函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: getTokenFromEntity

 /**
  * Get the token string from the token entity.
  *
  * @param int $token_id
  *   The restful_token_auth entity.
  *
  * @return string
  *   The token string.
  */
 public static function getTokenFromEntity($token_id)
 {
     if ($token = entity_load_single('restful_token_auth', $token_id)) {
         return $token->token;
     }
     return NULL;
 }
开发者ID:jhoffman-tm,项目名称:waldorf-deployment,代码行数:16,代码来源:TokenAuthenticationBase.php


示例2: getLabel

 /**
  * Overrides EntityReferenceHandler::getLabel().
  */
 public function getLabel($entity) {
   $target_type = $this->field['settings']['target_type'];
   $field = $entity->{OG_AUDIENCE_FIELD};
   $gid = $field[LANGUAGE_NONE][0]['target_id'];
   $group = entity_load_single('node', $gid);
   return entity_label($target_type, $entity).' ('.entity_label('node', $group).')';
 }
开发者ID:humanitarianresponse,项目名称:site,代码行数:10,代码来源:OgHRBundlesSelectionHandler.class.php


示例3: authenticate

 /**
  * {@inheritdoc}
  */
 public function authenticate(RequestInterface $request)
 {
     // Access token may be on the request, or in the headers.
     if (!($token = $this->extractToken($request))) {
         return NULL;
     }
     // Check if there is a token that has not expired yet.
     $query = new \EntityFieldQuery();
     $result = $query->entityCondition('entity_type', 'restful_token_auth')->entityCondition('bundle', 'access_token')->propertyCondition('token', $token)->range(0, 1)->execute();
     if (empty($result['restful_token_auth'])) {
         // No token exists.
         return NULL;
     }
     $id = key($result['restful_token_auth']);
     $auth_token = entity_load_single('restful_token_auth', $id);
     if (!empty($auth_token->expire) && $auth_token->expire < REQUEST_TIME) {
         // Token is expired.
         if (variable_get('restful_token_auth_delete_expired_tokens', TRUE)) {
             // Token has expired, so we can delete this token.
             $auth_token->delete();
         }
         return NULL;
     }
     return user_load($auth_token->uid);
 }
开发者ID:jhoffman-tm,项目名称:waldorf-deployment,代码行数:28,代码来源:TokenAuthentication.php


示例4: refreshToken

 /**
  * Create a token for a user, and return its value.
  *
  * @param string $token
  *   The refresh token.
  *
  * @throws BadRequestException
  *
  * @return RestfulTokenAuth
  *   The new access token.
  */
 public function refreshToken($token)
 {
     // Check if there is a token that did not expire yet.
     /* @var \Drupal\restful\Plugin\resource\DataProvider\DataProviderEntityInterface $data_provider */
     $data_provider = $this->getDataProvider();
     $query = $data_provider->EFQObject();
     $results = $query->entityCondition('entity_type', $this->entityType)->entityCondition('bundle', 'refresh_token')->propertyCondition('token', $token)->range(0, 1)->execute();
     if (empty($results['restful_token_auth'])) {
         throw new BadRequestException('Invalid refresh token.');
     }
     // Remove the refresh token once used.
     $refresh_token = entity_load_single('restful_token_auth', key($results['restful_token_auth']));
     $uid = $refresh_token->uid;
     // Get the access token linked to this refresh token then do some cleanup.
     $access_token_query = new EntityFieldQuery();
     $access_token_reference = $access_token_query->entityCondition('entity_type', 'restful_token_auth')->entityCondition('bundle', 'access_token')->fieldCondition('refresh_token_reference', 'target_id', $refresh_token->id)->range(0, 1)->execute();
     if (!empty($access_token_reference['restful_token_auth'])) {
         $access_token = key($access_token_reference['restful_token_auth']);
         entity_delete('restful_token_auth', $access_token);
     }
     $refresh_token->delete();
     // Create the new access token and return it.
     /* @var \Drupal\restful_token_auth\Entity\RestfulTokenAuthController $controller */
     $controller = entity_get_controller($this->getEntityType());
     $token = $controller->generateAccessToken($uid);
     return $this->view($token->id);
 }
开发者ID:jhoffman-tm,项目名称:waldorf-deployment,代码行数:38,代码来源:RefreshToken__1_0.php


示例5: getOrCreateToken

 /**
  * Create a token for a user, and return its value.
  */
 public function getOrCreateToken()
 {
     $entity_type = $this->getEntityType();
     $account = $this->getAccount();
     // Check if there is a token that did not expire yet.
     /* @var DataProviderEntityInterface $data_provider */
     $data_provider = $this->getDataProvider();
     $query = $data_provider->EFQObject();
     $result = $query->entityCondition('entity_type', $entity_type)->entityCondition('bundle', 'access_token')->propertyCondition('uid', $account->uid)->range(0, 1)->execute();
     $token_exists = FALSE;
     if (!empty($result[$entity_type])) {
         $id = key($result[$entity_type]);
         $access_token = entity_load_single($entity_type, $id);
         $token_exists = TRUE;
         if (!empty($access_token->expire) && $access_token->expire < REQUEST_TIME) {
             if (variable_get('restful_token_auth_delete_expired_tokens', TRUE)) {
                 // Token has expired, so we can delete this token.
                 $access_token->delete();
             }
             $token_exists = FALSE;
         }
     }
     if (!$token_exists) {
         /* @var \Drupal\restful_token_auth\Entity\RestfulTokenAuthController $controller */
         $controller = entity_get_controller($this->getEntityType());
         $access_token = $controller->generateAccessToken($account->uid);
         $id = $access_token->id;
     }
     $output = $this->view($id);
     return $output;
 }
开发者ID:jhoffman-tm,项目名称:waldorf-deployment,代码行数:34,代码来源:AccessToken__1_0.php


示例6: 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


示例7: getBillingCycle

 /**
  * Returns the user's billing cycle with the provided start time.
  *
  * If an existing billing cycle matches the expected start and end, it will
  * be returned. Otherwise, a new one will be created.
  *
  * @param $uid
  *   The uid of the user.
  * @param $start
  *   The unix timestamp when the billing cycle needs to start.
  * @param $save
  *   Whether to save the created billing cycle entity.
  *   Passing FALSE allows an unsaved billing cycle entity to be returned
  *   for estimation purposes.
  *
  * @return
  *   A cl_billing_cycle entity.
  */
 public function getBillingCycle($uid, $start = REQUEST_TIME, $save = TRUE)
 {
     // Make the billing cycle exactly 30 days long, so that it can be divided
     // predictably for prorating.
     // The 1 is substracted to make sure that the billing cycle ends 1s before
     // the next one starts
     $end = $start + 2592000 - 1;
     // Try to find an existing billing cycle matching our parameters.
     $query = new EntityFieldQuery();
     $query->entityCondition('entity_type', 'cl_billing_cycle')->entityCondition('bundle', $this->name)->propertyCondition('status', 1)->propertyCondition('uid', $uid);
     if ($start != REQUEST_TIME) {
         // In case of a custom start, make sure to match the exact billing cycle.
         // Ensures that new orders get the previous billing cycle created at the
         // start of testing, while getNextBillingCycle returns the expected result.
         $query->propertyCondition('start', $start);
     }
     $result = $query->execute();
     if ($result) {
         $billing_cycle_id = key($result['cl_billing_cycle']);
         $billing_cycle = entity_load_single('cl_billing_cycle', $billing_cycle_id);
     } else {
         // No existing billing cycle found. Create a new one.
         $billing_cycle = entity_create('cl_billing_cycle', array('type' => $this->name));
         $billing_cycle->uid = $uid;
         $billing_cycle->start = $start;
         $billing_cycle->end = $end;
         $billing_cycle->status = 1;
         if ($save) {
             $billing_cycle->save();
         }
     }
     return $billing_cycle;
 }
开发者ID:ivanvincent,项目名称:imsv_fe,代码行数:51,代码来源:CommerceLicenseBillingCycleTypeTest.class.php


示例8: validate

 /**
  * {@inheritdoc}
  */
 public function validate(&$value)
 {
     if (!empty($value['entity_type']) && !empty($value['entity_id'])) {
         $entity = entity_load_single($value['entity_type'], $value['entity_id']);
         if (!$entity) {
             $entity_types = $this->getEntityTypeOptions();
             return array(t('@entity_type with id @entity_id does not exist.', array('@entity_type' => $entity_types[$value['entity_type']], '@entity_id' => $value['entity_id'])));
         }
         $wrapper = entity_metadata_wrapper($value['entity_type'], $value['entity_id']);
         return parent::validate($wrapper);
     }
 }
开发者ID:CodeElegance,项目名称:finsearches,代码行数:15,代码来源:FeedsEntityProcessorPropertyEntity.php


示例9: fetchSingle

 public function fetchSingle()
 {
     $query = $this->getEntityFieldQuery();
     $result = $query->execute();
     if (empty($result[$this->entityType])) {
         return null;
     } else {
         $keys = array_keys($result[$this->entityType]);
         $id = array_shift($keys);
         return entity_load_single($this->entityType, $id);
     }
 }
开发者ID:pjcarly,项目名称:drupal7-spectrum,代码行数:12,代码来源:SpectrumQuery.php


示例10: exportContextResults

 /**
  * Sends the context messages back to Drupal's messaging system using
  * drupal_set_message.
  *
  * Please note that this is meant to be called before using drupal_goto()
  * to redirect the user to a result page.
  *
  * @param array $results The context from the batch operation.
  */
 public static function exportContextResults(array $results)
 {
     foreach ($results as $result) {
         if ($result['entity_id'] && $result['entity_type']) {
             $message = ':label [<strong>:type</strong> <code>:id</code>] !message';
             $arguments = array(':label' => entity_label($result['entity_type'], entity_load_single($result['entity_type'], $result['entity_id'])), ':type' => $result['entity_type'], ':id' => $result['entity_id'], '!message' => $result['message']);
         } else {
             $message = '!message';
             $arguments = array('!message' => $result['message']);
         }
         drupal_set_message(t($message, $arguments), $result['type']);
     }
 }
开发者ID:sammarks,项目名称:publisher,代码行数:22,代码来源:Operation.php


示例11: validate

 /**
  * Implements FeedsEntityProcessorPropertyInterface::validate().
  */
 public function validate(&$value)
 {
     $info = $this->getPropertInfo();
     $entity_type = $info['type'];
     if ($value) {
         $entity = entity_load_single($entity_type, $value);
         if (!$entity) {
             $entity_info = entity_get_info();
             $entity_type_label = $entity_info[$entity_type]['label'];
             return array(t('@entity_type with id @entity_id does not exist.', array('@entity_type' => $entity_type_label, '@entity_id' => $value)));
         }
         $wrapper = entity_metadata_wrapper($entity_type, $value);
         return parent::validate($wrapper);
     }
 }
开发者ID:CodeElegance,项目名称:finsearches,代码行数:18,代码来源:FeedsEntityProcessorPropertyEntityType.php


示例12: view

 /**
  * Displays the bean.
  */
 public function view($bean, $content, $view_mode = 'default', $langcode = NULL)
 {
     // Retrieve the terms from the loaded entity.
     $active_entity = bean_tax_active_entity_array();
     // Check for cached content on this block.
     $cache_name = 'bean_tax:listing:' . $bean->delta . ':' . $active_entity['type'] . ':' . $active_entity['ids'][0];
     if ($cache = cache_get($cache_name)) {
         $content = $cache->data;
     } else {
         // We need to make sure that the bean is configured correctly.
         if ($active_entity['type'] != 'bean' && !empty($bean->filters['vocabulary']) && (isset($active_entity['terms']) && count($active_entity['terms']))) {
             // Reformat vocabulary list from machine names to vocabulary vids.
             $vids = array();
             foreach ($bean->filters['vocabulary'] as $vm) {
                 $query = new EntityFieldQuery();
                 $result = $query->entityCondition('entity_type', 'taxonomy_vocabulary');
                 $query->propertyCondition('machine_name', $vm);
                 global $language;
                 if ($language->language != NULL && db_field_exists('taxonomy_vocabulary', 'language')) {
                     $query->propertyCondition('language', $language->language);
                 }
                 $result = $query->execute();
                 foreach ($result['taxonomy_vocabulary'] as $vocabulary) {
                     $vids[$vocabulary->vid] = $vocabulary->vid;
                 }
             }
             $i = 0;
             $content['terms'] = array();
             // Parse terms from correct vocabularies, limit list to X results.
             foreach ($active_entity['terms'] as $term) {
                 $term = entity_load_single('taxonomy_term', $term->tid);
                 if (in_array($term->vid, $vids) && $i < $bean->settings['records_shown']) {
                     $content['terms'][$term->tid] = entity_view('taxonomy_term', array($term->tid => $term), $bean->settings['term_view_mode']);
                     $i++;
                 }
             }
             cache_set($cache_name, $content, 'cache', time() + 60 * $bean->settings['cache_duration']);
         } elseif (isset($active_entity['type']) && $active_entity['type'] == 'bean' && $bean->bid === $active_entity['object']->bid) {
             $content['#markup'] = '';
         } elseif ($bean->settings['hide_empty'] || !$active_entity['object']) {
             return;
         } else {
             $content['#markup'] = t('No terms.');
         }
     }
     return $content;
 }
开发者ID:stevebresnick,项目名称:iomedia_stp_d7_core,代码行数:50,代码来源:TaxListingBean.class.php


示例13: refreshToken

  /**
   * Create a token for a user, and return its value.
   *
   * @param string $token
   *   The refresh token.
   *
   * @throws RestfulBadRequestException
   *
   * @return \RestfulTokenAuth
   *   The new access token.
   */
  public function refreshToken($token) {
    // Check if there is a token that did not expire yet.
    $query = new EntityFieldQuery();
    $results = $query
      ->entityCondition('entity_type', $this->entityType)
      ->entityCondition('bundle', 'refresh_token')
      ->propertyCondition('token', $token)
      ->range(0, 1)
      ->execute();

    if (empty($results['restful_token_auth'])) {
      throw new \RestfulBadRequestException('Invalid refresh token.');
    }

    // Remove the refresh token once used.
    $refresh_token = entity_load_single('restful_token_auth', key($results['restful_token_auth']));
    $uid = $refresh_token->uid;

    // Get the access token linked to this refresh token then do some cleanup.
    $access_token_query = new EntityFieldQuery();
    $access_token_reference = $access_token_query
      ->entityCondition('entity_type', $this->getEntityType())
      ->entityCondition('bundle', $this->getBundle())
      ->fieldCondition('refresh_token_reference', 'target_id', $refresh_token->id)
      ->range(0, 1)
      ->execute();

    if (!empty($access_token_reference['restful_token_auth'])) {
      $access_token_id = key($access_token_reference['restful_token_auth']);
      entity_delete('restful_token_auth', $access_token_id);
    }

    $refresh_token->delete();

    // Create the new access token and return it.
    $controller = entity_get_controller($this->getEntityType());
    $token = $controller->generateAccessToken($uid);
    return $this->viewEntity($token->id);
  }
开发者ID:humanitarianresponse,项目名称:site,代码行数:50,代码来源:RestfulRefreshTokenAuthentication.class.php


示例14: authenticate

  /**
   * {@inheritdoc}
   */
  public function authenticate(array $request = array(), $method = \RestfulInterface::GET) {
    $options = $this->getPluginKey('options');
    $key_name = !empty($options['param_name']) ? $options['param_name'] : 'access_token';
    $token = !empty($request['__application'][$key_name]) ? $request['__application'][$key_name] : $request[$key_name];

    // Check if there is a token that did not expire yet.

    $query = new EntityFieldQuery();
    $result = $query
      ->entityCondition('entity_type', 'restful_token_auth')
      ->entityCondition('bundle', 'access_token')
      ->propertyCondition('token', $token)
      ->range(0, 1)
      ->execute();


    if (empty($result['restful_token_auth'])) {
      // No token exists.
      return;
    }

    $id = key($result['restful_token_auth']);
    $auth_token = entity_load_single('restful_token_auth', $id);

    if (!empty($auth_token->expire) && $auth_token->expire < REQUEST_TIME) {
      // Token is expired.

      if (variable_get('restful_token_auth_delete_expired_tokens', TRUE)) {
        // Token has expired, so we can delete this token.
        $auth_token->delete();
      }

      return;
    }

    return user_load($auth_token->uid);
  }
开发者ID:humanitarianresponse,项目名称:site,代码行数:40,代码来源:RestfulAuthenticationToken.class.php


示例15: refreshToken

  /**
   * Create a token for a user, and return its value.
   *
   * @param string $token
   *   The refresh token.
   *
   * @throws RestfulBadRequestException
   *
   * @return \RestfulTokenAuth
   *   The new access token.
   */
  public function refreshToken($token) {
    $account = $this->getAccount();
    // Check if there is a token that did not expire yet.
    $query = new EntityFieldQuery();
    $results = $query
      ->entityCondition('entity_type', $this->entityType)
      ->entityCondition('bundle', 'refresh_token')
      ->propertyCondition('token', $token)
      ->range(0, 1)
      ->execute();

    if (empty($results['restful_token_auth'])) {
      throw new \RestfulBadRequestException('Invalid refresh token.');
    }

    // Remove the refresh token once used.
    $refresh_token = entity_load_single('restful_token_auth', key($results['restful_token_auth']));
    $refresh_token->delete();

    // Create the new access token and return it.
    $controller = entity_get_controller($this->getEntityType());
    $token = $controller->generateAccessToken($account->uid);
    return $this->viewEntity($token->id);
  }
开发者ID:pcambra,项目名称:site,代码行数:35,代码来源:RestfulRefreshTokenAuthentication.class.php


示例16: entity_load_single

<?php

/**
 * @file
 * This template is used to print a single field in a view.
 *
 * It is not actually used in default Views, as this is registered as a theme
 * function which has better performance. For single overrides, the template is
 * perfectly okay.
 *
 * Variables available:
 * - $view: The view object
 * - $field: The field handler object that can process the input
 * - $row: The raw SQL result that can be used
 * - $output: The processed output that will normally be used.
 *
 * When fetching output from the $row, this construct should be used:
 * $data = $row->{$field->field_alias}
 *
 * The above will guarantee that you'll always get the correct data,
 * regardless of any changes in the aliasing that might happen if
 * the view is modified.
 */
$node = entity_load_single('node', $output);
$wrapper = entity_metadata_wrapper('node', $node);
$commerce_price_data = $wrapper->field_product_store[0]->commerce_price->value();
$commerce_price = commerce_currency_format($commerce_price_data['amount'], $commerce_price_data['currency_code']);
print $commerce_price;
开发者ID:aposidelov,项目名称:copfun1,代码行数:28,代码来源:views-view-field--product-wishlist--page--nid-1.tpl.php


示例17: saveToActiveStore

 /**
  * Implements Drupal\configuration\Config\Configuration::saveToActiveStore().
  */
 public function saveToActiveStore(ConfigIteratorSettings &$settings)
 {
     $entity = $this->getData();
     $entity_type = $this->getComponent();
     if ($original = entity_load_single($entity_type, $this->getIdentifier())) {
         $entity->id = $original->id;
         unset($entity->is_new);
     }
     $entity->save();
     $settings->addInfo('imported', $this->getUniqueId());
 }
开发者ID:gnulugtn,项目名称:portal,代码行数:14,代码来源:EntityApiConfiguration.php


示例18: entity_load_single

 * @see template_preprocess_entity()
 * @see template_process()
 */
?>
<div class="<?php 
print $classes;
?>
 clearfix"<?php 
print $attributes;
?>
>

  <?php 
$publisher_link = '#';
if ($ckan_dataset->publisher_id) {
    $publisher = entity_load_single('ckan_publisher', $ckan_dataset->publisher_id);
    $publisher_link = l($publisher->title, 'ckan_publisher/' . $ckan_dataset->publisher_id);
}
$author = user_load($ckan_dataset->uid);
print 'id: ' . $ckan_dataset->id . '<br />';
print 'ckan_id: ' . $ckan_dataset->ckan_id . '<br />';
print 'name: ' . $ckan_dataset->name . '<br />';
if ($author) {
    print 'published by: ' . l($author->name, 'user/' . $author->uid) . '<br />';
}
print 'publisher: ' . $publisher_link . '<br />';
print 'inventory: ' . $ckan_dataset->inventory . '<br />';
print 'notes: <br />' . $ckan_dataset->notes . '<br />';
?>

</div>
开发者ID:TabulaData,项目名称:donl_d7,代码行数:31,代码来源:ckan_dataset.tpl.php


示例19: normalizeMappings

 /**
  * @see LdapAuthorizationConsumerAbstract::normalizeMappings
  */
 public function normalizeMappings($mappings)
 {
     $new_mappings = array();
     if ($this->ogVersion == 2) {
         $group_entity_types = og_get_all_group_bundle();
         foreach ($mappings as $i => $mapping) {
             $from = $mapping[0];
             $to = $mapping[1];
             $to_parts = explode('(raw: ', $to);
             $user_entered = $to_parts[0];
             $new_mapping = array('from' => $from, 'user_entered' => $user_entered, 'valid' => TRUE, 'error_message' => '');
             if (count($to_parts) == 2) {
                 // has simplified and normalized part in (). update normalized part as validation
                 $to_normalized = trim($to_parts[1], ')');
                 /**
                  * users (node:35:1)
                  * node:students (node:21:1)
                  * faculty (node:33:2)
                  * node:35:1 (node:35:1)
                  * node:35 (node:35:1)
                  */
                 $to_simplified = $to_parts[0];
                 $to_simplified_parts = explode(':', trim($to_simplified));
                 $entity_type = count($to_simplified_parts) == 1 ? 'node' : $to_simplified_parts[0];
                 $role = count($to_simplified_parts) < 3 ? OG_AUTHENTICATED_ROLE : $to_simplified_parts[2];
                 $group_name = count($to_simplified_parts) == 1 ? $to_simplified_parts[0] : $to_simplified_parts[1];
                 list($group_entity, $group_entity_id) = ldap_authorization_og2_get_group_from_name($entity_type, $group_name);
                 $to_simplified = join(':', array($entity_type, $group_name));
             } else {
                 // may be simplified or normalized, but not both
                 /**
                  * users
                  * node:students
                  * faculty
                  * node:35:1
                  * node:35
                  */
                 $to_parts = explode(':', trim($to));
                 $entity_type = count($to_parts) == 1 ? 'node' : $to_parts[0];
                 $role = count($to_parts) < 3 ? OG_AUTHENTICATED_ROLE : $to_parts[2];
                 $group_name_or_entity_id = count($to_parts) == 1 ? $to_parts[0] : $to_parts[1];
                 list($group_entity, $group_entity_id) = ldap_authorization_og2_get_group_from_name($entity_type, $group_name_or_entity_id);
                 if ($group_entity) {
                     // if load by name works, $group_name_or_entity_id is group title
                     $to_simplified = join(':', array($entity_type, $group_name_or_entity_id));
                 } else {
                     $to_simplified = FALSE;
                 }
                 $simplified = (bool) $group_entity;
                 if (!$group_entity && ($group_entity = @entity_load_single($entity_type, $group_name_or_entity_id))) {
                     $group_entity_id = $group_name_or_entity_id;
                 }
             }
             if (!$group_entity) {
                 $new_mapping['normalized'] = FALSE;
                 $new_mapping['simplified'] = FALSE;
                 $new_mapping['valid'] = FALSE;
                 $new_mapping['error_message'] = t("cannot find matching group: !to", array('!to' => $to));
             } else {
                 $role_id = is_numeric($role) ? $role : ldap_authorization_og2_rid_from_role_name($entity_type, $group_entity->type, $group_entity_id, $role);
                 $roles = og_roles($entity_type, isset($group_entity->type) ? $group_entity->type : NULL, 0, FALSE, TRUE);
                 $role_name = is_numeric($role) ? $roles[$role] : $role;
                 $to_normalized = join(':', array($entity_type, $group_entity_id, $role_id));
                 $to_simplified = $to_simplified ? $to_simplified . ':' . $role_name : $to_normalized;
                 $new_mapping['normalized'] = $to_normalized;
                 $new_mapping['simplified'] = $to_simplified;
                 if ($to == $to_normalized) {
                     /**  if not using simplified notation, do not convert to simplified.
                            this would create a situation where an og group
                            can change its title and the authorizations change when the
                            admin specified the group by entity id
                          */
                     $new_mapping['user_entered'] = $to;
                 } else {
                     $new_mapping['user_entered'] = $to_simplified . ' (raw: ' . $to_normalized . ')';
                 }
             }
             $new_mappings[] = $new_mapping;
         }
     } else {
         // og 1
         foreach ($mappings as $i => $mapping) {
             $new_mapping = array('from' => $mapping[0], 'user_entered' => $mapping[1], 'normalized' => NULL, 'simplified' => NULL, 'valid' => TRUE, 'error_message' => '');
             $gid = NULL;
             $rid = NULL;
             $correct_syntax = "gid=43,rid=2 or group-name=students,role-name=member or node.title=students,role-name=member";
             $incorrect_syntax = t('Incorrect mapping syntax.  Correct examples are:') . $correct_syntax;
             $targets = explode(',', $mapping[1]);
             if (count($targets) != 2) {
                 $new_mapping['valid'] = FALSE;
                 $new_mapping['error_message'] = $incorrect_syntax;
                 continue;
             }
             $group_target_and_value = explode('=', $targets[0]);
             if (count($group_target_and_value) != 2) {
                 $new_mapping['valid'] = FALSE;
                 $new_mapping['error_message'] = $incorrect_syntax;
//.........这里部分代码省略.........
开发者ID:ehazell,项目名称:AWBA,代码行数:101,代码来源:LdapAuthorizationConsumerOG.class.php


示例20: isValidEntity

 /**
  * Determine if an entity is valid, and accessible.
  *
  * @param string $op
  *   The operation to perform on the entity (view, update, delete).
  * @param int $entity_id
  *   The entity ID.
  *
  * @return bool
  *   TRUE if entity is valid, and user can access it.
  *
  * @throws UnprocessableEntityException
  * @throws InaccessibleRecordException
  */
 protected function isValidEntity($op, $entity_id)
 {
     $entity_type = $this->entityType;
     if (!ctype_digit((string) $entity_id) || !($entity = entity_load_single($entity_type, $entity_id))) {
         // We need to check if the entity ID is numeric since if this is a uuid
         // that starts by the number 4, and there is an entity with ID 4 that
         // entity will be loaded incorrectly.
         throw new UnprocessableEntityException(sprintf('The entity ID %s does not exist.', $entity_id));
     }
     list(, , $bundle) = entity_extract_ids($entity_type, $entity);
     if (!empty($this->bundles) && !in_array($bundle, $this->bundles)) {
         return FALSE;
     }
     if ($this->checkEntityAccess($op, $entity_type, $entity) === FALSE) {
         if ($op == 'view' && !$this->getResourcePath()) {
             // Just return FALSE, without an exception, for example when a list of
             // entities is requested, and we don't want to fail all the list because
             // of a single item without access.
             // Add the inaccessible item to the metadata to fix the record count in
             // the formatter.
             $inaccessible_records = $this->getMetadata()->get('inaccessible_records');
             $inaccessible_records[] = array('resource' => $this->pluginId, 'id' => $entity_id);
             $this->getMetadata()->set('inaccessible_records', $inaccessible_records);
             return FALSE;
         }
         // Entity was explicitly requested so we need to throw an exception.
         throw new InaccessibleRecordException(sprintf('You do not have access to entity ID %s.', $entity_id));
     }
     return TRUE;
 }
开发者ID:jhoffman-tm,项目名称:waldorf-deployment,代码行数:44,代码来源:DataProviderEntity.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP entity_load_unchanged函数代码示例发布时间:2022-05-15
下一篇:
PHP entity_load_multiple_by_properties函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap