當前位置: 首頁>>代碼示例>>PHP>>正文


PHP EntityInterface::getValue方法代碼示例

本文整理匯總了PHP中Drupal\Core\Entity\EntityInterface::getValue方法的典型用法代碼示例。如果您正苦於以下問題:PHP EntityInterface::getValue方法的具體用法?PHP EntityInterface::getValue怎麽用?PHP EntityInterface::getValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Drupal\Core\Entity\EntityInterface的用法示例。


在下文中一共展示了EntityInterface::getValue方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: patch

 /**
  * Responds to entity PATCH requests.
  *
  * @Thruway(name = "update", type="procedure")
  *
  * @param \Drupal\Core\Entity\EntityInterface $original_entity
  *   The original entity object.
  *
  * @return array
  *
  */
 public function patch(EntityInterface $original_entity)
 {
     $entity = entity_load($original_entity->getEntityTypeId(), $original_entity->id());
     if (!$entity) {
         throw new BadRequestHttpException(t('Invalid entity'));
     }
     $definition = $this->getPluginDefinition();
     if ($entity->getEntityTypeId() != $definition['entity_type']) {
         throw new BadRequestHttpException(t('Invalid entity type'));
     }
     if (!$entity->access('update')) {
         throw new AccessDeniedHttpException();
     }
     // Overwrite the received properties.
     foreach ($original_entity as $field_name => $field) {
         if (isset($entity->{$field_name})) {
             // It is not possible to set the language to NULL as it is automatically
             // re-initialized. As it must not be empty, skip it if it is.
             // @todo: Use the langcode entity key when available. See
             //   https://drupal.org/node/2143729.
             if ($field_name == 'langcode' && $field->isEmpty()) {
                 continue;
             }
             //                if ($field->isEmpty() && !$original_entity->get($field_name)->access('delete')) {
             //                    throw new AccessDeniedHttpException(
             //                        t('Access denied on deleting field @field.', array('@field' => $field_name))
             //                    );
             //                }
             $entity->set($field_name, $original_entity->getValue($field_name)[$field_name]);
             if (!$entity->get($field_name)->access('update')) {
                 throw new AccessDeniedHttpException(t('Access denied on updating field @field.', array('@field' => $field_name)));
             }
         }
     }
     // Validate the received data before saving.
     $this->validate($original_entity);
     try {
         $entity->save();
         //            $this->logger->notice(
         //                'Updated entity %type with ID %id.',
         //                array('%type' => $entity->getEntityTypeId(), '%id' => $entity->id())
         //            );
         // Update responses have an empty body.
         return $entity;
     } catch (EntityStorageException $e) {
         throw new HttpException(500, t('Internal Server Error'), $e);
     }
 }
開發者ID:voryx,項目名稱:ThruwayDrupal,代碼行數:59,代碼來源:EntityResource.php

示例2: createLogMessage

 /**
  * Creates a log message when an exception occured during import.
  *
  * @param \Exception $e
  *   The exception that was thrown during processing.
  * @param \Drupal\Core\Entity\EntityInterface $entity
  *   The entity object that was being processed.
  * @param arary $item
  *   The parser result for this entity.
  *
  * @return string
  *   The message to log.
  *
  * @todo This no longer works due to circular references.
  */
 protected function createLogMessage(\Exception $e, EntityInterface $entity, array $item)
 {
     include_once DRUPAL_ROOT . '/core/includes/utility.inc';
     $message = $e->getMessage();
     $message .= '<h3>Original item</h3>';
     $message .= '<pre>' . drupal_var_export($item) . '</pre>';
     $message .= '<h3>Entity</h3>';
     $message .= '<pre>' . drupal_var_export($entity->getValue()) . '</pre>';
     return $message;
 }
開發者ID:alnutile,項目名稱:drunatra,代碼行數:25,代碼來源:EntityProcessor.php


注:本文中的Drupal\Core\Entity\EntityInterface::getValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。